Results 1 to 2 of 2

Thread: Continuous Rotation

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    1

    Continuous Rotation

    Hello all,
    I have a program that correctly draws an object on the screen. Now, I want to rotate the scene continuously when the user presses the enter.


    Code :
    else if(key==13){
    		while(1){
    			GLfloat yAxis=cam.getPos()[1];
    			cam.setAlpha(fmod(cam.getAlpha()+10.0,360));
                            cam.setPos(xComp*cos(cam.getAlpha()*DEGREE_
            TO_RADIAN),yAxis,xComp*sin(cam.getAlpha()*DEGREE_TO_RADIAN));
    			glutPostRedisplay();
    		}
    	}

    where cam is an instance of Camera class and the calculations inside are made to move the position of the camera on a circle in x-z plane.

    When I replace while(1) line to for(i=0;i<5;i++), this code calculates the camera positions for 5 times and displays only the last position of the screen.
    I added a Sleep function but it did not solve the problem.

    How can I make it draw not only the last but also other positions of the screen.

    Thanks in advance.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Location
    Poland
    Posts
    111

    Re: Continuous Rotation

    Add a variable holding state of enter key (eg. 1 - pressed, 0 - not pressed), and update position of Your camera per frame (when key is pressed). Your program must catch key press, and key release events, and update variable.

    in your draw function:
    Code :
    if(key_is_pressed)
            update_camera_pos();

Similar Threads

  1. Continuous rendering of animations
    By linkingabo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-04-2011, 02:43 PM
  2. Continuous playback supported in OpenMAX AL ?
    By rborchers in forum OpenMAX
    Replies: 1
    Last Post: 09-22-2008, 09:58 PM
  3. Continuous rotation of scene
    By Fraktalius in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-27-2008, 02:31 AM
  4. Mapping surface to non-continuous vertices
    By dumbjock123 in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 01-28-2004, 10:49 AM
  5. Continuous rotation?
    By tdavie in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-21-2000, 01:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean