We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wrote a particleSystem using physics simulation library punktiert. here is the constructor func of ParticleSystem class:
class ParticleSystem extends VParticleGroup {
Vec emitter;
int num;
ParticleSystem(Vec loc,int num) {
super();
emitter = loc;
this.physics = new VPhysics();
for(int i=0; i<num; i++) {
SoloParticle p = new SoloParticle(emitter);
particles.add(p);
physics.addParticle(p);
}
**for(VParticle s : particles) {
s.setNeighbors(this.getNeighbors(s));
s.addBehavior(new BCollision());**
}
}
........... ....... ....
VParticleGroup is something like:
public class VParticleGroup {
public VPhysics physics;
public ArrayList<VParticle> particles;
public ArrayList<VSpring> springs;
private HashGrid hashgrid;
/**
* empty particle group
*/
public VParticleGroup() {
this.springs = new ArrayList<VSpring>();
this.particles = new ArrayList<VParticle>();
}
..........................
............. .........
and getNeighbors() is:
public Collection<VParticle> getNeighbors(VParticle particle) {
if (hashgrid == null && physics != null) {
return physics.hashgrid.check(particle);
}
return hashgrid.check(particle);
}
I dont know what's wrong with my code. but result of this? when the system being constructed, only one particle has BColllision behavior and only that particle is set to others' neighbor.
things go like this
Answers
All 200 particles do get the BCollision bahavior but 199 set the single one as a only neighbor.
With same code, if add a new particle, things go well. But the initial particles, act so odd.