How to extend a class
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,