When I want to roll a cube from the world coordinate along the X_axis (on oxy plane) three times by edge contact then rolling aside (parallel with Y_axis ) two times and stop.
When I try to do simulation using glutDisplayFunc(Display), I do not know how to stop the 1st rolling then do the 2nd rolling.
Pick up any intro to 3D graphics book, and it’ll point out what you need to do here.
When called, don’t think of your Display() method as a “Display the scene for all possible times and then return” function, but rather a “Display the scene as it appears right now and then return” function. That’s how you should use it.
So what you want is something more like:
time = getCurrentTime()
computeSceneState( time, &angle )
drawScene( angle )
You can then arrange for the Display() function to be called repeatedly by calling glutPostRedisplay() at the end of your Display() function. Alternatively, you can arrange to call glutPostRedisplay() at some other rate by calling it based on a system timer.
I don’t understand your question. Why don’t you do exactly what you said? Instead of just calling glRotatef(), add a translate before and a translate after.
It sounds like you’re struggling with “how do I transform objects within a coordinate space”. Pick up any decent Intro to 3D Graphics book and it’ll cover this. Here’s one that discusses this w.r.t. the old version of OpenGL you’re using: Chapter 3: Viewing.
Thanks so much for your tips.
Actually, the object transformation is in apart of the rolling issue. With my code below, I have just rolled the cube along the edge 90 degrees only one time when I pressed “r”.
If I want to roll 3 times then change the direction along with Y_axis with 2 rolling times, I do not where can I put the loop. I tried to put the for then while loop in the display() but receiving wrong results.
Would you please help me to change this code.