Rotating a cube using jBullet collisions
- by Kenneth Bray
How would one go about rotating/flipping a cube with the physics of jBullet?
Here is my Draw method for my cube object:
public void Draw() {
// center point posX, posY, posZ
float radius = .25f;//size / 2;
glPushMatrix();
glBegin(GL_QUADS);
//top
{
glColor3f(5.0f,1.0f,5.0f); // white
glVertex3f(posX + radius, posY + radius, posZ - radius);
glVertex3f(posX - radius, posY + radius, posZ - radius);
glVertex3f(posX - radius, posY + radius, posZ + radius);
glVertex3f(posX + radius, posY + radius, posZ + radius);
}
//bottom
{
glColor3f(1.0f,1.0f,0.0f); // ?? color
glVertex3f(posX + radius, posY - radius, posZ + radius);
glVertex3f(posX - radius, posY - radius, posZ + radius);
glVertex3f(posX - radius, posY - radius, posZ - radius);
glVertex3f(posX + radius, posY - radius, posZ - radius);
}
//right side
{
glColor3f(1.0f,0.0f,1.0f); // ?? color
glVertex3f(posX + radius, posY + radius, posZ + radius);
glVertex3f(posX + radius, posY - radius, posZ + radius);
glVertex3f(posX + radius, posY - radius, posZ - radius);
glVertex3f(posX + radius, posY + radius, posZ - radius);
}
//left side
{
glColor3f(0.0f,1.0f,1.0f); // ?? color
glVertex3f(posX - radius, posY + radius, posZ - radius);
glVertex3f(posX - radius, posY - radius, posZ - radius);
glVertex3f(posX - radius, posY - radius, posZ + radius);
glVertex3f(posX - radius, posY + radius, posZ + radius);
}
//front side
{
glColor3f(0.0f,0.0f,1.0f); // blue
glVertex3f(posX + radius, posY + radius, posZ + radius);
glVertex3f(posX - radius, posY + radius, posZ + radius);
glVertex3f(posX - radius, posY - radius, posZ + radius);
glVertex3f(posX + radius, posY - radius, posZ + radius);
}
//back side
{
glColor3f(0.0f,1.0f,0.0f); // green
glVertex3f(posX + radius, posY - radius, posZ - radius);
glVertex3f(posX - radius, posY - radius, posZ - radius);
glVertex3f(posX - radius, posY + radius, posZ - radius);
glVertex3f(posX + radius, posY + radius, posZ - radius);
}
glEnd();
glPopMatrix();
Update();
}
This is my update method for the cube position:
public void Update() {
Transform trans = new Transform();
cubeRigidBody.getMotionState().getWorldTransform(trans);
posX = trans.origin.x;
posY = trans.origin.y;
posZ = trans.origin.z;
Quat4f outRot = new Quat4f();
trans.getRotation(outRot);
rotX = outRot.x;
rotY = outRot.y;
rotZ = outRot.z;
rotW = outRot.w;
}
I am assuming I need to use glrotatef, but it does not seem to work at all when I try that..
this is how I have tried to rotate the cubes:
GL11.glRotatef(rotW, rotX, 0.0f, 0.0f);
GL11.glRotatef(rotW, 0.0f, rotY, 0.0f);
GL11.glRotatef(rotW, 0.0f, 0.0f, rotZ);