Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 596159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:08:30+00:00 2026-05-13T16:08:30+00:00

How do you control the speed of an animation? My objects animate faster on

  • 0

How do you control the speed of an animation? My objects animate faster on another’s machine.

void idle(void){

if (!wantPause){    
    circleSpin = circleSpin + 2.0;      //spin circles
    if(circleSpin > 360.0)
{
        circleSpin = circleSpin - 360.0;
}

        diamondSpin = diamondSpin - 4.0;    //spin diamonds
    if(diamondSpin > 360.0)
{
        diamondSpin = diamondSpin + 360.0;
}
        ellipseScale = ellipseScale + 0.1;  //scale ellipse
    if(ellipseScale > 30)
{
        ellipseScale = 15;
}
glutPostRedisplay();
}
}

void drawScene()
{
 ...
glColor3f(1,0,0);
glPushMatrix();
glRotatef(circleSpin,0,0,1);
drawOuterCircles();
glPopMatrix();
}


int main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(400,400);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Lesson 6");
init();
glutDisplayFunc(drawScene);
glutKeyboardFunc(keyboard);
glutReshapeFunc(handleResize);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:08:30+00:00Added an answer on May 13, 2026 at 4:08 pm

    This is the poor man’s solution:

    FPS = 60.0;
    while (game_loop) {
        int t = getticks();
        if ((t - t_prev) > 1000/FPS)
            process_animation_tick();
        t_prev = t;
    }
    

    this is the better solution:

    GAME_SPEED = ...
    while (game_loop) {
        int t = getticks();
        process_animation((t - t_prev)*GAME_SPEED/1000.0);
        t_prev = t;
    }
    

    In the first one, getframe moves your object by a fixed amount, but that is prone to errors if framerate drops.

    In the latter, you move the objects based on the time passed. E.g. if 20ms pass, you rotate an object 12 degrees, and if 10ms pass, you rotate it 6 degrees. In general, the animation if a function of time passed.

    Implementation of getticks() is up to you. For a start you could use glutGet(GLUT_ELAPSED_TIME).


    In your case it would look something like:

    int old_t;
    
    void idle(void) {
      int t = glutGet(GLUT_ELAPSED_TIME);
      int passed = t - old_t;
      old_t = t;
      animate( passed );
      glutPostRedisplay();
    }
    
    void animate( int ms )
    {  
      if (!wantPause){    
        circleSpin = circleSpin + ms*0.01;      //spin circles
        if(circleSpin > 360.0)
        {
          circleSpin = circleSpin - 360.0;
        }
        diamondSpin = diamondSpin - ms*0.02;    //spin diamonds
        if(diamondSpin > 360.0)
        {
            diamondSpin = diamondSpin - 360.0;
        }
        ellipseScale = ellipseScale + ms*0.001;  //scale ellipse
        if(ellipseScale > 30)
        {
            ellipseScale = 15;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working with jquery for animate a div. i want to control speed
I have a machine control system in Python that currently looks roughly like this
Everytime when I run Selenium IDE the speed control is set to fast It
Lets say I am running demo(graphics) and I want to control the speed with
How can I use C++ to control CPU fan speed in Windows Vista Ultimate?
I would like to create a variable speed slider control on the iPhone. Basically
We're having speed problems still with the login control and the Ad membership provider.
Is there a way to control the speed of execution of a loop ?
http://code.google.com/p/appengine-mapreduce/ mentions that it can control the speed of execution, but I can't figure
I am tring to control the ISO and the shutter speed for the iphone,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.