Results 1 to 10 of 10

Thread: Rotating Camera in GLUT

  1. #1
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Rotating Camera in GLUT

    Does anyone have an idea of how to rotate a Camera without glutPostRedisplay() or at least correctly using GLUT?

    So far I am rotating the camera using glutPostRedisplay() in my Display function, but it's making my computer go really slow, because it's trying to update every second.

    [This message has been edited by VC6-OGL (edited 11-14-2002).]

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Rotating Camera in GLUT

    It is correct that you must redraw the scene whenever something has changed in the scene, camera, objects, etc.

    There is no problem calling redisplay if the scene has changed.

    How about posting some of your code, can advise as to what you can do to maybe inprove your drawing speed.


    Originally posted by VC6-OGL:
    Does anyone have an idea of how to rotate a Camera without glutPostRedisplay() or at least correctly using GLUT?

    So far I am rotating the camera using glutPostRedisplay() in my Display function, but it's making my computer go really slow, because it's trying to update every second.

    [This message has been edited by VC6-OGL (edited 11-14-2002).]

  3. #3
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Rotating Camera in GLUT

    Define floats:
    float g_RotateX = 0.0f;
    float g_RotationSpeed = 0.1f;

    Look At function:
    gluLookAt ( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ); {
    glRotatef( g_RotateX, 0, 1.0f, 0 );
    g_RotateX += g_RotationSpeed;
    glutPostRedisplay();
    }

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Rotating Camera in GLUT

    First a little more code would be nice...
    But glrotation is 0 to 360 in degrees, you use 0.1 degree movement, that is for a full rotation 3600 movements..... change to 1.0 degree movement that will increase speed and not really make the movement jurky.


    Also if you are going to use glRotate to change your view, just do away with the gluLookAt. and use glTranslate and glRotate together to move the camera view.

    Are you using doubble buffers?

    I put normally put the lookat or view changes in the display...


    void display(void)
    {
    bla
    bla
    bla

    glLookAt or glRotate/translate

    draw world.

    Originally posted by VC6-OGL:
    Define floats:
    float g_RotateX = 0.0f;
    float g_RotationSpeed = 0.1f;

    Look At function:
    gluLookAt ( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ); {
    glRotatef( g_RotateX, 0, 1.0f, 0 );
    g_RotateX += g_RotationSpeed;
    glutPostRedisplay();
    }

  5. #5
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Rotating Camera in GLUT

    I will E-mail you my code so you can look at it.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Rotating Camera in GLUT

    Note with out a floor or other object really hard to tell if the object or camera is moveing.

    Here is some edits:

    void display( void ) {
    glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // glClear - COLOR/DEPTH
    glColor3f ( 1.0, 1.0, 1.0 ); // Cube Color - White
    glLoadIdentity(); // Load gl Identity
    glTranslatef ( 0.0, 0.0, -5.0 ); // Camera Position - Straight
    glRotatef(g_RotateX, 0, 1.0f, 0); // Camera Rotation
    g_RotateX += g_RotationSpeed; // Setup g_RotateX
    glutPostRedisplay(); // Remove should no be called here to draw cube. // Update Screen
    glScalef ( 1.0, 1.0, 1.0 ); // Cube sizeScale
    glutWireCube ( 2.0 ); // Cube Size on screen
    glFlush(); glutPostRedisplay(); // place here. not the best way to update screen but fix's problem, best to use glutIdleFunc(); // Flush gl Memory
    }

    void specialkeys ( int key, int x, int y ) {
    switch ( key ) {
    case GLUT_KEY_LEFT: // On Left-Key
    ycam = ( ycam - 2 ) % 360; // Move camera one notch to the left
    break;
    case GLUT_KEY_RIGHT: // On Right-Key
    ycam = ( ycam + 2 ) % 360; // Move camera one notch to the right
    break;
    case GLUT_KEY_UP: // On Key-Up
    xcam = ( xcam - 2 ) % 360; // Move camera one notch to the up
    break;
    case GLUT_KEY_DOWN: // On Key-Down
    xcam = ( xcam + 2 ) % 360; // Move camera one notch to the down
    break;
    case GLUT_KEY_PAGE_UP: // On Page-Up
    zcam = ( zcam - 2 ) % 360; // Move camera right on z-axis
    break;
    case GLUT_KEY_PAGE_DOWN: // On Page-Down
    zcam = ( zcam + 2 ) % 360; // Move camera left on z-axis
    break;
    default:
    break;
    }
    glutPostRedisplay(); // just update here....
    }

    Originally posted by VC6-OGL:
    I will E-mail you my code so you can look at it.


    [This message has been edited by nexusone (edited 11-14-2002).]

  7. #7
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Rotating Camera in GLUT

    glutIdleFunc() does not take 0 paramaters. What am I supposed to do?

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Rotating Camera in GLUT

    another change would be to add glutIdleFunc() place before glutMainLoop();

    glutIdleFunc(My_idle_func);


    void My_idle_func(void)
    {
    glutPostRedisplay(); // Place here instead of the end of the display routine.
    }

  9. #9
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Rotating Camera in GLUT

    Ok, I added the glutIdleFunc(), but whenever i minimize, maximize or close the program it sort of hangs on my screen. Do you have any idea why?

    [This message has been edited by VC6-OGL (edited 11-14-2002).]

  10. #10
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Rotating Camera in GLUT

    Are there any other ways to refresh the screen besides glutPostRedisplay(). Or is there any other way to move a camera without using Rotatef().

    [This message has been edited by VC6-OGL (edited 11-14-2002).]

Similar Threads

  1. Rotating the camera
    By Ehsan Nekooee in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-05-2009, 02:10 PM
  2. Rotating camera in 4pi.
    By brambilla in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-25-2009, 07:05 AM
  3. Rotating Camera Using GlLookAt()
    By Winegums in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-07-2006, 09:27 AM
  4. Camera rotating
    By Vlasko in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-13-2004, 10:48 AM
  5. Moving and rotating a "camera"
    By skippyj777 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-23-2000, 09:36 AM

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