Results 1 to 4 of 4

Thread: Setting actors in a world

  1. #1
    Member Contributor
    Join Date
    Nov 2002
    Posts
    96

    Setting actors in a world

    I'm new to OpenGL (first came in contact a few days ago) and I've been experimenting quite a bit the past few days.
    I'm so far that I can make spinning cubes and set my camera with GLUlookat to view the cube (inc lighting) at any point.

    However, I tried to make two cubes spinning independantly just a few minutes ago, and I found out that the function "glRotatef" rotates the entire axis system.
    So what I did next was setting the axis-system back in it's original position, and then translated it over the X-axis to draw the next cube to keep it from spinning all over the place.

    Actually, this works quite properly. But I just read a thread here about optimisation of applications and read that rotating the axis-system consumes some processor-power...
    Is there a way to do this more efficiently? For example that only rotates a certain set of polygons, instead of the entire system while drawing?

    I'm not asking this to optimise my application (as I'm far from being experienced enough to worry about optimisation) but I want to learn this the proper way instead of creating that much overhead.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    London, England
    Posts
    160

    Re: Setting actors in a world

    You can use glPushMatrix and glPopMatrix.
    OpenGL has a matrix stack. PushMatrix saves the current matrix by pushing it onto the stack, and PopMatrix will restore the previous matrix. So, in your case you could do:

    Code :
    glTranslatef(0.0f, 0.0f, -10.0f); //translate into screen
    glPushMatrix(); //save current matrix *
    glRotate() //rotate cube 1
    //draw cube 1
    glPopMatrix(); //restore matrix from *
    glRotate(); rotate cube 2
    //draw cube 2
    Similarly, for three cubes, sandwich the first two with push/pop Matrix.

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

    Re: Setting actors in a world

    Here is my example:

    glRotatef(....); // Effects everything forward

    glPushMatrix(); //Save matrix
    glTranslatef(.......) // Note order, opengl operates last function first
    glRotatef(.......) // Rotate around axis
    draw_cube1();
    glPopMatrix(); //Restore matrix to state before Push, rotate/translate inside here does not effect next operations.

    glPushMatrix(); //Save matrix
    glTranslatef(.......)
    glRotatef(.......)
    draw_cube2();
    glPopMatrix(); //Restore matrix to state before Push



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

  4. #4
    Member Contributor
    Join Date
    Nov 2002
    Posts
    96

    Re: Setting actors in a world

    YOU LOT ROCK!!!

    Thanks

    [This message has been edited by Structural (edited 11-15-2002).]

Similar Threads

  1. COVERSION: world coord -> screen coord -> world coord
    By Albert85 in forum OpenGL: GLSL
    Replies: 8
    Last Post: 01-12-2015, 06:41 PM
  2. Continuous World / World Wrapping
    By MicahBrening in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 02-24-2007, 06:46 PM
  3. setting FPS
    By t3jem in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-04-2005, 02:48 PM
  4. Setting up 2D
    By smiley in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-28-2002, 02:49 PM
  5. Setting up Dev Env.
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-04-2000, 08:34 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