Please, I dont know whats wrong with my code. (ParticleSystem)

edited October 2013 in Questions about Code

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) {
    emitter = loc;
    this.physics = new VPhysics();
    for(int i=0; i<num; i++) {
      SoloParticle p = new SoloParticle(emitter);
    **for(VParticle s : particles) {
    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




  • 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.

Sign In or Register to comment.