My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
package toxi.physics;

import java.util.ArrayList;
import java.util.List;

import toxi.geom.Spline3D;
import toxi.geom.Vec3D;

/**
* This class is used as a builder to dynamically construct a
* {@link ParticleString} following a given spline path, sampled at a fixed
* frequency/step distance. This functionality is needed especially when working
* with various obstacles/mechanic constraints which the string should flow/wrap
* around.
*/
public class ParticlePath extends Spline3D {

List<VerletParticle> particles = new ArrayList<VerletParticle>();

public ParticlePath() {
super();
}

public ParticlePath(List<Vec3D> points) {
super(points);
}

public List<VerletParticle> createParticles(VerletPhysics physics,
int subDiv, float step, float mass) {
particles.clear();
computeVertices(subDiv);
int num = vertices.size();
int i = 0;
while (i < num - 1) {
Vec3D a = vertices.get(i);
Vec3D b = vertices.get(i + 1);
Vec3D dir = b.sub(a);
Vec3D stepDir = dir.getNormalizedTo(step);
Vec3D curr = a.copy();
while (curr.sub(a).dot(dir) / dir.magSquared() <= 1) {
VerletParticle currP = new VerletParticle(curr, mass);
particles.add(currP);
curr.addSelf(stepDir);
}
i++;
}
return particles;
}
}

Change log

r350 by toxmeister on Jan 17, 2010   Diff
createParticles() now also calls
computeVertices() on the parent spline
Go to: 
Project members, sign in to write a code review

Older revisions

r337 by toxmeister on Jan 4, 2010   Diff
adding 3D ParticlePath, ParticleString
and various new constraint types (box,
min, softbox, z-cylinder)
All revisions of this file

File info

Size: 1452 bytes, 49 lines
Powered by Google Project Hosting