Processing Forum




Click on Join Now to Sign Up
Hello,
I'm using Toxiclibs VerletPhysics in order to create a particle system. I'd like to store additional information about each particle using my custom particle class, where one instance would exist for each particle. The problem is integrating my class with the Toxiclibs VerletParticle class. My solution has been to pass the index of the VerletParticle to my custom particle, so that it can get the VerletParticle from the particles ArrayList every time it updates, and access its current position, velocity, and so on. The problem is that the index of the VerletParticle may change as the user adds and removes particles from the ArrayList.
Passing the index of each VerletParticle to each Particle in initWorld():
for (int i = 0; i < NUM_PARTICLES; i++) {
VerletParticle p = new VerletParticle(Vec3D.randomVector().scale(3).addSelf(width/2, 0, 0));
physics.addParticle(p);
particle[i] = new Particle(i);
}
Is there a way for my custom class to extend VerletParticle, allowing me to add my own fields and methods? I don't know how to do this, as the physics object only takes the VerletParticle type in addParticle(). This is just what came to mind; I'm sure there is a more elegant solution. I'm somewhat of a novice programmer, so forgive me if the question seems obvious.
Please let me know if I can clarify. Thanks,
// ====================================================================================// class Button and RectButton class Button { int x, y; int sizeX; int sizeY; color basecolor, highlightcolor; color currentcolor; boolean over = false; boolean pressed = false; boolean Exists = false; String Text = ""; String ToolTipText = ""; String Tag = ""; int Tag2 = 0; int TagMark = 0; color ButtonStrokeColor = color (255, 255, 255); void update() { if (over()) { // Mouse over currentcolor = highlightcolor; } else { // not Mouse over currentcolor = basecolor; } } // update void toolTip() { if (over()) { if (!ToolTipText.equals("")) { if (millis() - timeSinceLastMouseMoved > 800) { fill (242, 245, 75); noStroke(); textSize (12); float tw = textWidth(ToolTipText); float xLeft = x-(tw/2); float xRight = x-(tw/2) + tw; float xLeftText = x; if (xRight>=width) { xLeft= width-tw-2; xLeftText= xLeft + tw/2; } if (xLeft< 2) { xLeft=2; xLeftText= 2 + tw / 2; } rect (xLeft, y+32, tw, 20); textAlign(CENTER); fill(0); text(ToolTipText, xLeftText, y+sizeY+19); } // if } // if } // if } // func boolean pressed() { if ( over()) { locked = true; return true; } else { locked = false; return false; } } // pressed; boolean over() { return true; } // over boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } // overRect} // class class RectButton extends Button { public RectButton(int ix, int iy, int isizeX, int isizeY, color icolor, color ihighlight, boolean iExist) { x = ix; y = iy; sizeX = isizeX; sizeY = isizeY; basecolor = icolor; highlightcolor = ihighlight; currentcolor = basecolor; Exists = iExist; Text = ""; } boolean over() { if ( overRect(x, y, sizeX, sizeY) ) { over = true; return true; } else { over = false; return false; } } void display() { if (Exists) { if (Tag.equals("Spielfeld")) { // Spielfeld // AusgabeEinFeld(Text); } else { // kein Spielfeld, sondern Befehlsbutton stroke (ButtonStrokeColor); strokeWeight(0); fill(currentcolor); rect(x, y, sizeX, sizeY); if (Text != "") { fill(0, 102, 153); textAlign(CENTER); textSize(16) ; text(Text, (x + (sizeX / 2.0)), (y + (sizeY / 2.0))+5); } // if (Text != "") } // else } // if exists } // method display} // class