-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleManager.java
More file actions
54 lines (44 loc) · 2 KB
/
ParticleManager.java
File metadata and controls
54 lines (44 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class ParticleManager {
private Node guiNode;
private Spatial standardParticle, glowParticle;
private Node particleNode;
private Random rand;
public ParticleManager(Node guiNode, Spatial standardParticle, Spatial glowParticle) {
this.guiNode = guiNode;
this.standardParticle = standardParticle;
this.glowParticle = glowParticle;
particleNode = new Node("particles");
guiNode.attachChild(particleNode);
rand = new Random();
}
public void Gravity(Vector3f gravity, float distance) {
Vector3f additionalVelocity = gravity.mult(1000f / (distance*distance + 10000f));
velocity.addLocal(additionalVelocity);
if (distance < 400) {
additionalVelocity = new Vector3f(gravity.y, -gravity.x, 0).mult(3f / (distance + 100));
velocity.addLocal(additionalVelocity);
}
}
public void sprayParticle(Vector3f position, Vector3f sprayVel) {
Spatial particle = standardParticle.clone();
particle.setLocalTranslation(position);
ColorRGBA color = new ColorRGBA(0.8f,0.4f,0.8f,1f);
particle.addControl(new ParticleControl(sprayVel, 3500, color, screenWidth, screenHeight));
particle.setUserData("affectedByGravity", true);
((Node) guiNode.getChild("particles")).attachChild(particle);
}
public ColorRGBA hsvToColor(float h, float s, float v) {
if (h == 0 && s == 0) {
return new ColorRGBA(v, v, v,1);
}
float c = s * v;
float x = c * (1 - Math.abs(h % 2 - 1));
float m = v - c;
if (h < 1) {return new ColorRGBA(c + m, x + m, m, 1);
} else if (h < 2) {return new ColorRGBA(x + m, c + m, m, 1);
} else if (h < 3) {return new ColorRGBA(m, c + m, x + m, 1);
} else if (h < 4) {return new ColorRGBA(m, x + m, c + m, 1);
} else if (h < 5) {return new ColorRGBA(x + m, m, c + m, 1);
} else {return new ColorRGBA(c + m, m, x + m, 1);}
}
}