lgmcben
02-17-2010, 01:11 AM
Hi.
I'm writing a program to simulate a falling chopstick. And now I stuck at the easiest part...
I've completed:
- All the physics stuff; Torque, gravity, angular acceleration and displacement, game loop, Timestep, etc.
- I have a chopstick drawn on the screen as a quad starting at (0, 0, 0) and pointing towards the screen.
- angleX and angleY variables are solved and ready to use.
Now I got stuck at:
- using the angleX and angleY with glRotate() to simulate the falling chopstick.
The chopstick fall OK on X-axis when I use only this
gl.glRotatef(angleX, 0, 1, 0);
and on Y-axis when I use only this
gl.glRotatef(angleY, 1, 0, 0);
*** Problem is here ***
But when I use them together
gl.glRotatef(angleX, 0, 1, 0);
gl.glRotatef(angleY, 1, 0, 0);
It just doesn't fall diagonally. At both angleX and angleY at 90 degree, the chopstick lies completely on Y axis.
However, I understand the reason well. It's because using glRotate 2 times like that. At 90 degree, the second glRotate will just rotate the chopstick around itself...
Please guide me on how should I use these 2 variables to properly simulate a falling chopstick.
Thank you in advance!
I'm writing a program to simulate a falling chopstick. And now I stuck at the easiest part...
I've completed:
- All the physics stuff; Torque, gravity, angular acceleration and displacement, game loop, Timestep, etc.
- I have a chopstick drawn on the screen as a quad starting at (0, 0, 0) and pointing towards the screen.
- angleX and angleY variables are solved and ready to use.
Now I got stuck at:
- using the angleX and angleY with glRotate() to simulate the falling chopstick.
The chopstick fall OK on X-axis when I use only this
gl.glRotatef(angleX, 0, 1, 0);
and on Y-axis when I use only this
gl.glRotatef(angleY, 1, 0, 0);
*** Problem is here ***
But when I use them together
gl.glRotatef(angleX, 0, 1, 0);
gl.glRotatef(angleY, 1, 0, 0);
It just doesn't fall diagonally. At both angleX and angleY at 90 degree, the chopstick lies completely on Y axis.
However, I understand the reason well. It's because using glRotate 2 times like that. At 90 degree, the second glRotate will just rotate the chopstick around itself...
Please guide me on how should I use these 2 variables to properly simulate a falling chopstick.
Thank you in advance!