2 shiffmann chains using toxiclib verletphysics doesnt work?

edited February 2016 in Library Questions

Using the example from toxiclibs I tried to instantiate a second chain using the Chain class just to see if it works. It doesnt. One chain seems to get anchored to the bottom center position. I tried creating a second Chain class (Chain2) and then renaming the class variables to avoid any naming conflicts but that still gives the same result. Any suggestions how to solve this?

TIA.

import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import toxi.geom.*;

// Reference to physics "world" (2D)
VerletPhysics2D physics;

// Our "Chain" object
Chain chain;
Chain chain2;

// color var
float c1;


void setup() {
  size(1000,1000);
  smooth();

  // Initialize the physics world
  physics=new VerletPhysics2D();
  physics.addBehavior(new GravityBehavior(new Vec2D(0,0.1)));
  physics.setWorldBounds(new Rect(0,0,width,height));

  // Initialize the chain
  chain = new Chain(200,20,12,.9);
  chain2 = new Chain(100,20,12,.9);
}

void draw() {
  colorMode(HSB);
  //background(255);
  fill(25, 10);
  rect(0,0,width,height);
  c1+=1;
  c1%=255;
  // Update physics
  physics.update();
  // Update chain's tail according to mouse location 
  chain.updateTail(mouseX,mouseY);
  chain2.updateTail(mouseX,mouseY);
  // Display chain
  chain.display();
  chain2.display();
}

void mousePressed() {
  // Check to see if we're grabbing the chain
  chain.contains(mouseX,mouseY);
  chain2.contains(mouseX,mouseY);
}

void mouseReleased() {
  // Release the chain
  chain.release();
  chain2.release();
}
Sign In or Register to comment.