I want to know if there is a way to change the joint position of a revolute joint. Like as provided in one of the examples from the book "Nature of the code", the windmill example, i want to change the joint position so that the joint is made at either end of the box2 (the one that is rotating). I tried setting its MassData it moved the joint to the right place but the motor function is not functioning.
i want this: https://www.dropbox.com/s/nkakvpr4p3iyyoj/joint.png
i want this: https://www.dropbox.com/s/nkakvpr4p3iyyoj/joint.png
Code: Select all
class Windmill {
RevoluteJoint joint;
Box box1;
Box box2;
Windmill(float x, float y) {
box1 = new Box(x, y-20, 120, 10, radians(0), false); [img][/img]
box2 = new Box(x-60, y, 10, 40, 0, true);
// Define joint as between two bodies
RevoluteJointDef rjd = new RevoluteJointDef();
rjd.initialize(box1.body, box2.body, box1.body.getWorldCenter());
// Turning on a motor (optional)
rjd.motorSpeed = -PI*3;
rjd.maxMotorTorque = 1000.0;
rjd.enableMotor = true;
// Create the joint
joint = (RevoluteJoint) box2d.world.createJoint(rjd);
}
// Turn the motor on or off
void toggleMotor() {
joint.enableMotor(!joint.isMotorEnabled());
}
boolean motorOn() {
return joint.isMotorEnabled();
}
void display() {
box2.display();
box1.display();
// Draw anchor just for debug
Vec2 anchor = box2d.coordWorldToPixels(box1.body.getWorldCenter());
fill(255);
noStroke();
ellipse(anchor.x, anchor.y, 10, 10);
}
}