Fisica and pinned wheels or bars

edited May 2015 in Library Questions

Hi, I have some trouble understanding how to correctly handle bodies that are linked by a FRevoluteJoint.

Case 1 : I link 2 FCircles (or more in the example below), one is static, the other not. If the almighty mouse grabs the wheel to move it, then sometimes the static body moves first, but not the other one, and it can take some tapping or magic so that the screen finally refreshes with the right display:

 PImage inner, outer, movimg, turnimg, pivot_img;

FCircle circle1, circle2;

FWorld world;
FRevoluteJoint joint, joint2;
FCircle pivot;

public void setup() {

    Fisica.init(this);

    inner=loadImage("inner.png");

    outer=loadImage("outer.png");
    movimg=loadImage("move.png");
    turnimg=loadImage("turn.png");
    pivot_img=loadImage("pivot.png");

    world=new FWorld();

    circle1=new FCircle(inner.width);
    circle1.setPosition(width/2, height/2);
    circle1.setName("inner");
    circle1.attachImage(inner);
    //circle1.setStatic(true);
    circle1.setSensor(true);

    circle2=new FCircle(outer.width);
    circle2.setPosition(width/2, height/2);
    circle2.attachImage(outer);
    circle2.setName("outer");
    circle2.setSensor(true);

    pivot=new FCircle(pivot_img.width);
    pivot.setPosition(width/2, height/2);
    pivot.setStatic(true);
    pivot.setSensor(true);
    pivot.attachImage(pivot_img);

    joint=new FRevoluteJoint(circle1, circle2);
    joint2=new FRevoluteJoint(circle2, pivot);

    world.add(circle2);
    world.add(circle1);
    world.add(joint);
    world.add(pivot);
    world.add(joint2);

}

public void draw() {
    background(255);
    world.step();
    circle1.draw(this);
    circle2.draw(this);
    pivot.draw(this);
}


public void mouseReleased(){
    circle1.setAngularVelocity(0);
    circle2.setAngularVelocity(0);
}

Case 2: I link a FCircle and a FPoly to make a pinball-like structure. When the mouse is Pressed, I set the angular velocity to make the pin reach its max angle. Problem #1: the pin does not stay constrained and has some kind of weird motion, out of the RevoluteJoint axis... Problem #2: when the mouse is still pressed (mouseDragged), the pin starts falling back down instead of staying steady at the max angle position..

 ....//in setup()
   bar_left = new FPoly();
    bar_left.setName("bar_left");
    bar_left.setFriction(0);
    bar_left.setFillColor(0xFF6E6E6E);
    bar_left.setBullet(true);
    bar_left.setDensity(5000 / scale);
    bar_left.setGroupIndex(-1);
    bar_left.setRestitution(0);

    screw_left = new FCircle(10 * scale2 * scale);
    screw_left.setPosition(86 * scale2 * scaleWidth, 518 * scale2 * scaleHeight);
    screw_left.setStatic(true);
    screw_left.setSensor(true);
    screw_left.setDensity(500000 / scale);
    screw_left.setGroupIndex(-1);

    for (float i = 3f * aRatio_bar; i <= 9f * aRatio_bar; i++) {
        bar_left.vertex((centerX1 + radius1 * cos(2f * i * PI / angle_steps_bar)), centerY1 + radius1 * sin(2f * i * PI / angle_steps_bar));
    }

    for (float i = 9f * aRatio_bar; i <= 15f * aRatio_bar; i++) {
        bar_left.vertex((centerX2 + radius2 * cos(2f * i * PI / angle_steps_bar)), centerY2 + radius2 * sin(2f * i * PI / angle_steps_bar));

    }

 joint_left = new FRevoluteJoint(bar_left, screw_left) {
        public void draw(PGraphics applet) {
        }
    };

      joint_left.setEnableLimit(true);
      joint_left.setLowerAngle(radians(-30));
      joint_left.setUpperAngle(radians(30));
      joint_left.setAnchor(86 * scale2 * scaleWidth, 518 * scale2 * scaleHeight);
      ....

 void mousePressed(){
  if (mouseX < width / 2) {
            bar_left.setAngularVelocity(-radians(30) * 100 * scale);

        }
 }

 void mouseDragged(){
  if (mouseX < width / 2) {
            bar_left.setAngularVelocity(-radians(30) * 100 * scale);

        }
 }

Any suggestion regarding these problems? Thanks.

Answers

Sign In or Register to comment.