View Full Version : rotation
10-25-2004, 11:48 PM
hallo everybody!all of you have been very helpful to me!!i have a new question
how can i constantly rotate an object??
i've tried applying a rotation command and then i increase the angle in ever cycle after the flush() command but i doesn't work.any ideas??
10-26-2004, 06:43 AM
should be easy enough...
keep a variable that will track the current total rotation. suppose in this example we're rotating on the y-axis.
pick a 'rotation delta', let's say for example the object rotates 5 degrees each frame.
then each frame:
y_rotation += rotation_delta (5);
y_rotation = y_rotation%360 (wrap around at 360)
glPushMatrix(); //might want to save matrix
glRotatef(y_rotation,0,1,0); (perform the rotation)
glPopMatrix(); //restore matrix if you saved it before
that should more or less achieve what you want.
10-26-2004, 01:22 PM
rotate+=0.2f; // or rotate-=0.2f;
//or any amount you want
rotate = degrees you want to rotate
x = degrees on x axis
y = degrees on y axis
z = degrees on z axis
i might look completely fool but i have tried all these and all i get is a blank screen.
after a lot of tries today i found out that it needed a
command at the end of the display function.
why is that?
it needs time to load the next frame??
thanks a lot for the interest.
10-27-2004, 04:58 AM
Windowing systems are generally event driven. That means that you only get code executed for those windows when that window receives events. One of those events is the drawing event. In Windows a WM_PAINT event is generated whenever a window needs to be re-drawn. (e.g. you resize it, restore the window after minimizing, uncover the window when another window has been on top, etc...)
Glut basically will only call the display function when that WM_PAINT event has been generated. By using glutPostRedisplay(), you are essentially telling glut that you need another WM_PAINT event to be generated. You could also setup an idle function or timer and put the glutPostRedisplay() function in that.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.