Hi im making a simulator for PopUpBooks. But im having problems with multiple joints. It is acting weird…
Here is whats happening:
Here the code for the joints:
front is the lefthand bottom plane
back is the righthand bottom plane
front2 is the lefthand plane thats standing up
back2 is the righthand plane thats standing up
Vector3f [] verticesF1 = new Vector3f[4];
verticesF1[3] = new Vector3f(0,0,-4);
verticesF1[2] = new Vector3f(-5,0,-4);
verticesF1[1] = new Vector3f(-5,0,4);
verticesF1[0] = new Vector3f(0,0,4);
Mesh f = makeMesh(verticesF1);
Geometry front = new Geometry("Front", f);
Vector3f [] verticesB1 = new Vector3f[4];
verticesB1[0] = new Vector3f(0,0,-4);
verticesB1[1] = new Vector3f(5,0,-4);
verticesB1[2] = new Vector3f(5,0,4);
verticesB1[3] = new Vector3f(0,0,4);
Mesh b = makeMesh(verticesB1);
Geometry back = new Geometry("Back", b);
Vector3f [] verticesF2 = new Vector3f[4];
verticesF2[0] = new Vector3f(0,0,0);
verticesF2[1] = new Vector3f(0,5,0);
verticesF2[2] = new Vector3f(-3,5,3);
verticesF2[3] = new Vector3f(-3,0,3);
Mesh f2 = makeMesh(verticesF2);
Geometry front2 = new Geometry("Front2", f2);
Vector3f [] verticesB2 = new Vector3f[4];
verticesB2[0] = new Vector3f(0,0,0);
verticesB2[1] = new Vector3f(0,5,0);
verticesB2[2] = new Vector3f(3,5,3);
verticesB2[3] = new Vector3f(3,0,3);
Mesh b2 = makeMesh(verticesB2);
Geometry back2 = new Geometry("Back2", b2);
front.setMaterial(paper);
back.setMaterial(paper);
front2.setMaterial(paper);
back2.setMaterial(paper);
Node frontPage = new Node("PhysicsNode");
frontPage.addControl(new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape(front),1));
frontPage.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0f,0f));
Node backPage = new Node("PhysicsNode");
backPage.addControl(new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape(back),0));
backPage.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0f,0f));
Node backPage2 = new Node("PhysicsNode");
backPage2.addControl(new RigidBodyControl(new HullCollisionShape(b2),0.1f));
backPage2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0f,0f));
Node frontPage2 = new Node("PhysicsNode");
frontPage2.addControl(new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape(front2),0.1f));
frontPage2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0f,0f));
frontPage2.getControl(RigidBodyControl.class).setKinematic(false);
frontPage.attachChild(front);
backPage.attachChild(back);
frontPage2.attachChild(front2);
backPage2.attachChild(back2);
planes.attachChild(frontPage);
planes.attachChild(backPage);
planes.attachChild(frontPage2);
planes.attachChild(backPage2);
getPhysicsSpace().add(frontPage);
getPhysicsSpace().add(backPage);
getPhysicsSpace().add(frontPage2);
getPhysicsSpace().add(backPage2);
//this is the joint i enable the motor on.
joint = new HingeJoint(frontPage.getControl(RigidBodyControl.class), backPage.getControl(RigidBodyControl.class), Vector3f.ZERO, Vector3f.ZERO,new Vector3f(0f,0f,-1f), new Vector3f(0f,0f,-1f));
getPhysicsSpace().add(joint);
joint.setLimit(0, 3.14f);
HingeJoint joint2 = new HingeJoint(backPage.getControl(RigidBodyControl.class), backPage2.getControl(RigidBodyControl.class),new Vector3f(0f,0f,0f) , new Vector3f(0f,0f,0f),new Vector3f(1f,0f,1f) , new Vector3f(1f,0f,1f));
getPhysicsSpace().add(joint2);
HingeJoint joint3 = new HingeJoint(frontPage.getControl(RigidBodyControl.class), frontPage2.getControl(RigidBodyControl.class),new Vector3f(0f,0f,0f) , new Vector3f(0f,0f,0f),new Vector3f(1f,0f,-1f) , new Vector3f(1f,0f,-1f));
getPhysicsSpace().add(joint3);
HingeJoint joint4 = new HingeJoint(frontPage2.getControl(RigidBodyControl.class), backPage2.getControl(RigidBodyControl.class),new Vector3f(0f,0f,0f) , new Vector3f(0f,0f,0f),new Vector3f(0f,1f,0f) , new Vector3f(0f,1f,0f));
getPhysicsSpace().add(joint4);
Code for the listener:
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(E_FOLD)) {
app.joint.getBodyA().activate();
if(keyPressed){
app.joint.enableMotor(true, 1.5f, 100f);
}else{
app.joint.enableMotor(true, -1.5f, 100f);
}
}
}
The desire effect is that when i enable the motor for “joint”(limited from 0 to 3.14), it would drive “joint2”," joint3", and “joint4” to move, openning “front2” and “bage2” page like a popupbook would.
But it seems that when “joint” hits the limit of 3.14 or 0, the “joint” stopped moving, but somehow “joint2”,“joint3” and “joint4” which is driven by “joint” kept going…(the only joint i enabled is “joint”)
And somehow the joint connecting front2 and back2 is sometimes torn appart.
Please help!
Thanks you in advance