📄 simpleparticleinfluencefactory.java
字号:
public static class BasicVortex extends ParticleInfluence {
public static final int VT_CYLINDER = 0;
public static final int VT_TORUS = 1;
private int type = VT_CYLINDER;
private float strength, divergence, height, radius;
private Line axis;
private boolean random, transformWithScene;
private Vector3f v1 = new Vector3f(), v2 = new Vector3f(),
v3 = new Vector3f();
private Quaternion rot = new Quaternion();
private Line line = new Line();
public BasicVortex() {
}
public BasicVortex(float strength, float divergence, Line axis,
boolean random, boolean transformWithScene) {
this.strength = strength;
this.divergence = divergence;
this.axis = axis;
this.height = 0f;
this.radius = 1f;
this.random = random;
this.transformWithScene = transformWithScene;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public float getStrength() {
return strength;
}
public void setStrength(float strength) {
this.strength = strength;
}
public float getDivergence() {
return divergence;
}
public void setDivergence(float divergence) {
this.divergence = divergence;
}
public Line getAxis() {
return axis;
}
public void setAxis(Line axis) {
this.axis = axis;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getRadius() {
return radius;
}
public void setRadius(float radius) {
this.radius = radius;
}
public boolean isRandom() {
return random;
}
public void setRandom(boolean random) {
this.random = random;
}
public boolean isTransformWithScene() {
return transformWithScene;
}
public void setTransformWithScene(boolean transformWithScene) {
this.transformWithScene = transformWithScene;
}
public void prepare(ParticleSystem system) {
line.getOrigin().set(axis.getOrigin());
line.getDirection().set(axis.getDirection());
if (transformWithScene) {
system.getEmitterTransform().multPoint(line.getOrigin());
system.getEmitterTransform().multNormal(line.getDirection());
}
if (type == VT_CYLINDER) {
rot.fromAngleAxis(-divergence, line.getDirection());
}
}
public void apply(float dt, Particle p, int index) {
float dtStr = dt * strength *
(random ? FastMath.nextRandomFloat() : 1f);
p.getPosition().subtract(line.getOrigin(), v1);
line.getDirection().cross(v1, v2);
if (v2.length() == 0) { // particle is on the axis
return;
}
v2.normalizeLocal();
if (type == VT_CYLINDER) {
rot.multLocal(v2);
p.getVelocity().scaleAdd(dtStr, v2, p.getVelocity());
return;
}
v2.cross(line.getDirection(), v1);
v1.multLocal(radius);
v1.scaleAdd(height, line.getDirection(), v1);
v1.addLocal(line.getOrigin());
v1.subtractLocal(p.getPosition());
if (v1.length() == 0) { // particle is on the ring
return;
}
v1.normalizeLocal();
v1.cross(v2, v3);
rot.fromAngleAxis(-divergence, v2);
rot.multLocal(v3);
p.getVelocity().scaleAdd(dtStr, v3, p.getVelocity());
}
public void write(JMEExporter e) throws IOException {
super.write(e);
OutputCapsule capsule = e.getCapsule(this);
capsule.write(type, "type", VT_CYLINDER);
capsule.write(strength, "strength", 1f);
capsule.write(divergence, "divergence", 0f);
capsule.write(axis, "axis", new Line(new Vector3f(),
new Vector3f(Vector3f.UNIT_Y)));
capsule.write(height, "height", 0f);
capsule.write(radius, "radius", 1f);
capsule.write(random, "random", false);
capsule.write(transformWithScene, "transformWithScene", true);
}
public void read(JMEImporter e) throws IOException {
super.read(e);
InputCapsule capsule = e.getCapsule(this);
type = capsule.readInt("type", VT_CYLINDER);
strength = capsule.readFloat("strength", 1f);
divergence = capsule.readFloat("divergence", 0f);
axis = (Line)capsule.readSavable("axis", new Line(new Vector3f(),
Vector3f.UNIT_Y.clone()));
height = capsule.readFloat("height", 0f);
radius = capsule.readFloat("radius", 1f);
random = capsule.readBoolean("random", false);
transformWithScene = capsule.readBoolean("transformWithScene", true);
}
public Class getClassTag() {
return this.getClass();
}
}
/**
* Not used.
*/
private SimpleParticleInfluenceFactory() {
}
/**
* Creates a basic wind that always blows in a single direction.
*
* @param windStr
* Max strength of wind.
* @param windDir
* Direction wind should blow.
* @param addRandom
* randomly alter the strength of the wind by 0-100%
* @param rotateWithScene
* rotate the wind direction with the particle system
* @return ParticleInfluence
*/
public static ParticleInfluence createBasicWind(float windStr,
Vector3f windDir, boolean addRandom, boolean rotateWithScene) {
return new BasicWind(windStr, windDir, addRandom, rotateWithScene);
}
/**
* Create a basic gravitational force.
*
* @param rotateWithScene
* rotate the gravity vector with the particle system
* @return ParticleInfluence
*/
public static ParticleInfluence createBasicGravity(Vector3f gravForce,
boolean rotateWithScene) {
return new BasicGravity(gravForce, rotateWithScene);
}
/**
* Create a basic drag force that will use the given drag coefficient. Drag
* is determined by figuring the current velocity and reversing it, then
* multiplying by the drag coefficient and dividing by the particle mass.
*
* @param dragCoef
* Should be positive. Larger values mean more drag but possibly
* more instability.
* @return ParticleInfluence
*/
public static ParticleInfluence createBasicDrag(float dragCoef) {
return new BasicDrag(dragCoef);
}
/**
* Creates a basic vortex.
*
* @param strength
* Max strength of vortex.
* @param divergence
* The divergence in radians from the tangent vector
* @param axis
* The center of the vortex.
* @param random
* randomly alter the strength of the vortex by 0-100%
* @param transformWithScene
* transform the axis with the particle system
* @return ParticleInfluence
*/
public static ParticleInfluence createBasicVortex(float strength,
float divergence, Line axis, boolean random,
boolean transformWithScene) {
return new BasicVortex(strength, divergence, axis, random,
transformWithScene);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -