📄 boom.java
字号:
/*
* Boom.java
*
* Created on 23. Dezember 2006, 21:52
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package kanjitori.util;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Geometry;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleGeometry;
import com.jmex.effects.particles.ParticleMesh;
import com.sun.org.apache.xerces.internal.dom.ParentNode;
/**
*
* @author Pirx
*/
public class Boom {
static private AlphaState as1;
static private ZBufferState zstate;
static private TextureState ts;
static {
as1 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
as1.setBlendEnabled(true);
as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as1.setDstFunction(AlphaState.DB_ONE);
as1.setTestEnabled(true);
as1.setTestFunction(AlphaState.TF_GREATER);
as1.setEnabled(true);
ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
ts.setTexture(
TextureManager.loadTexture("data/flaresmall.jpg",
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR));
ts.setEnabled(true);
zstate = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zstate.setEnabled(false);
zstate.setFunction(ZBufferState.CF_ALWAYS);
}
/** Static class */
private Boom() {
}
public static void setExplosion(Node parentNode, ColorRGBA startColor, ColorRGBA endColor,
float startSize, float endSize, float radius, int particles) {
ParticleMesh pMesh = ParticleFactory.buildParticles("particles", particles);
pMesh.setEmissionDirection(new Vector3f(0, 1, 0));
pMesh.setInitialVelocity(.6f);
pMesh.setStartSize(startSize);
pMesh.setEndSize(endSize);
pMesh.setMinimumLifeTime(500f);
pMesh.setMaximumLifeTime(1000f);
pMesh.setStartColor(startColor);
pMesh.setEndColor(endColor);
pMesh.setMinimumAngle(0f);
pMesh.setMaximumAngle(FastMath.PI);
pMesh.getParticleController().setControlFlow(false);
pMesh.getParticleController().setRepeatType(Controller.RT_CLAMP);
pMesh.getParticleController().setSpeed(1f);
pMesh.warmUp(1000);
pMesh.setCameraFacing(true);
pMesh.setRenderState(zstate);
Sphere sphere = new Sphere("sphere", 10, 10, radius);
sphere.setCullMode(Sphere.CULL_ALWAYS);
Node node = new Node("explosion");
node.setRenderState(ts);
node.setRenderState(as1);
node.attachChild(pMesh);
node.attachChild(sphere);
pMesh.setOriginOffset(parentNode.getLocalTranslation());
sphere.setModelBound(new BoundingSphere());
sphere.updateModelBound();
pMesh.setGeomBatch(sphere.getBatch(0));
pMesh.setModelBound(new BoundingSphere());
pMesh.updateModelBound();
parentNode.attachChild(node);
parentNode.updateRenderState();
parentNode.updateWorldBound();
parentNode.updateWorldVectors();
}
public static void explode(Node parentNode) {
((ParticleGeometry) ((Node)parentNode.getChild("explosion")).getChild(0)).forceRespawn();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -