Box2D Forums

It is currently Sun Aug 30, 2015 12:52 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun May 24, 2015 1:39 pm 
Offline

Joined: Sun May 24, 2015 1:33 pm
Posts: 1
Hi,
First of all, I know this is not a real JBox2D question, as it involves Fisica, one of its wrappers for Processing, but I had no luck on the Processing forums, so I am desperately trying here.
As you will see, the code is quite readable, and since I am just initializing bodies, it shouldn't be hard to understand my problem (I hope...)
Just to be clear, setup() is the initialization method while draw() is the "display thread", called everytime the screen is refreshed. Other methods are event listeners.

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:
Code:
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..

Code:
....//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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group