Hey all,
I'm using toxic libs, after a brief introduction and then a hiatus from the library, to set up a really simple verlet physics system. right now I just want particles that fall down and bounce around if the hit each other or if they. I will be adding more later. I'm working in eclipse and am pretty sure I got all the libraries in as there are no errors with those.
The problem I am having though is that nothing moves. I have a class that extends VerletParticle2D, which is a super class to 3 other subclasses that will all essentially draw different shapes/images at their x and y positions. Whenever I instantiate an instance of my super class it draws the proper shape at the initial position but doesnt move. the physics.particles collection shows it as stagnant almost as if nothing is affecting it. I'm not sure whats going on here any help would be appreciated. Heres some sample code of what i have so far:
Kobby
I'm using toxic libs, after a brief introduction and then a hiatus from the library, to set up a really simple verlet physics system. right now I just want particles that fall down and bounce around if the hit each other or if they. I will be adding more later. I'm working in eclipse and am pretty sure I got all the libraries in as there are no errors with those.
The problem I am having though is that nothing moves. I have a class that extends VerletParticle2D, which is a super class to 3 other subclasses that will all essentially draw different shapes/images at their x and y positions. Whenever I instantiate an instance of my super class it draws the proper shape at the initial position but doesnt move. the physics.particles collection shows it as stagnant almost as if nothing is affecting it. I'm not sure whats going on here any help would be appreciated. Heres some sample code of what i have so far:
- package bicyclecounter;
- import java.io.File;
- import java.util.ArrayList;
- import processing.core.*;
- import toxi.geom.*;
- import toxi.physics2d.*;
- import toxi.physics2d.behaviors.*;
- import visuals.*;
- import text.*;
- import out.*;
- public class BicycleCounter extends PApplet {
- public static final long serialVersionUID = 294872387429L;
- public static final int[] screenRes = {800, 600};
- ArrayList<DataObject> dataObjs = new ArrayList<DataObject>();
- VerletPhysics2D physics;
- public void setup() {
- size(screenRes[0], screenRes[1]);
- background(0);
- frameRate(30);
- smooth();
- //create a new physics object to govern our world of motion
- setUpPhysicsWorld();
- }
- public void setUpPhysicsWorld(){
- physics = new VerletPhysics2D();
- physics.setDrag(.05f);
- physics.setWorldBounds(new Rect(0,0, screenRes[0], screenRes[1]));//pass in a toxic libs geom rectangle for the world bounds
- physics.addBehavior(new GravityBehavior(new Vec2D(0, 0.15f)));
- println("physics setup");
- }
- public void draw() {
- // draw whatever data is in the data objs arraylist
- background(0);
- physics.update();
- for(VerletParticle2D p : physics.particles){
- println(p);//prints out the right initial position but never changes
- }
- for(int i = 0; i < dataObjs.size(); i++){
- dataObjs.get(i).update();
- dataObjs.get(i).display();
- }
- }
- public void keyPressed(){
- DataObject d;//super class that extends VerletParticle2D
- switch(key){
- case 'o' : d = new OilBarrel(this); break;
- case 'c' : d = new Cyclist(this); break;
- default: d = new OilBarrel(this); break;
- }
- dataObjs.add(d);
- physics.addParticle(d);
- physics.addBehavior(new AttractionBehavior(d, 20, -1.2f, 0.01f));
- }
- }
Kobby
1