How do you make sure the speed of OpenGL animation is consistent on different machines? -
How do you control animation speed? My objects animate quickly on another machine.
zero inactive (zero) {if (WantPause) {circleSpin = circleSpin + 2.0; // Spin Circle if (Circlepin> 360.0) {circleSpin = CircleSpin - 360.0; } Diamond Spin = Diamond Spin - 4.0; // spin diamonds if (diamondpin> 360.0) {diamond spin = diamond spin + 360.0; } Elps Scale = Alpes Scale + 0.1; // Scale oval if (Alpsiscell> 30) {Oval SCL = 15; } GlutPostRedisplay (); }} Zero Draw Sessine () {... glColor3f (1,0,0); GlPushMatrix (); GlRotatef (circleSpin, 0,0,1); DrawOuterCircles (); GlPopMatrix (); } Int main (int argc, char ** argv) {glutInit (and argc, argv); GlutInitWindowSize (400,400); GlutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); Glutrack Windo ("Lesson 6"); in this(); GlutDisplayFunc (drawScene); GlutKeyboardFunc (keyboard); GlutReshapeFunc (handleResize); GlutIdleFunc (inactive); GlutMainLoop (); Return 0; }
This is the solution of the poor man:
FPS = 60.0; While (game_loop) {int t = getticks (); If ((T - T_PRV)> 1000 / FPS) process_animation_tick (); T_prev = t; }
This is a better solution:
GAME_SPEED = ... while (game_loop) {int t = getticks (); Process_animation (T - T_PRV) * GAME_SPEED / 1000.0); T_prev = t; }
In the first one, the getframe transmits your object with a certain amount, but it suffers from errors when it has a framerate drops.
Later, depending on the time you passed, if the objects pass such as 20ms, you rotate an object 12 degrees, and if 10ms pass, you can rotate it by 6 degrees, in general, the animation If time function is passed.
The implementation of getticks ()
is up to you to start you glutGet (GLUT_ELAPSED_TIME)
.
You can use something like this in your case:
int old_t; Zero useless (zero) {int t = glutGet (GLUT_ELAPSED_TIME); Int passed = t - old_t; Old_t = T; Chetan (pass); GlutPostRedisplay (); } Void Chetan (int ms) {if (Want!) {CircleSpin = circleSpin + ms * 0.01; // Spin Circle if (Circlepin> 360.0) {circleSpin = CircleSpin - 360.0; } DiamondSpin = DiamondSpin - MS * 0.02; // Spin diamonds if (diamondpin> 360.0) {diamond spin = diamond spin - 360.0; } Elps Scale = Alpes Scale + MS * 0.001; // Scale oval if (Alpsiscell> 30) {Oval SCL = 15; }}}
Comments
Post a Comment