Getting Current Translation And Rotation In OpenGL

Posts: 1,066
Joined: 2004.07
Post: #1
I'm trying to create some trees procedurally, but I'm having a bit of trouble. It's probably really simple, but I can't seem to find the answer.

Basically, I have a Node class which contains an std::list of Node*s. When I go to draw the nodes, I use the glRotatef and glTranslatef functions to rotate and position the branch correctly. This works fine... for a while. I just added the second generation of branches, but they just come off of the top of my tree (because that's where OpenGL was last told (0, 0, 0) was).

How can I get the current translation and rotation so that I can add that in to my drawing routines? I have almost all of it done, but those two comments in there are what I'm trying to do. I checked with glGet but couldn't find either rotations or translations. What function should I be searching for?

        glRotatef( mYaw, 0, 1, 0 );
        glRotatef( mPitch, 0, 0, 1 );
        glBegin( GL_LINES );
        glColor3f( mR, mG, mB );
        glVertex3f( 0, 0, 0 );
        glVertex3f( 0, mLength, 0 );
        glTranslatef( 0, mLength, 0 );
        if ( !mChildren.empty() )
                        //store the current translation and rotation

            std::list< Node* >::iterator itr;
            for ( itr = mChildren.begin(); itr != mChildren.end(); ++itr )
                               //call glLoadIdentity() and restore translation and rotation

                ( *itr )->draw();
Quote this message in a reply
Posts: 1,403
Joined: 2005.07
Post: #2
using glGetFloatv but instead you want to just glPushMatrix and glPopMatrix

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Posts: 1,066
Joined: 2004.07
Post: #3
Thanks. I'm used to using DirectX and now the Ogre engine, so I'm forgetting things here and there.
Quote this message in a reply
Posts: 469
Joined: 2002.10
Post: #4
Don't forget to mind your stack depth.

15.4" MacBook Pro revA
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL. Current music position e40pud 0 3,661 Mar 9, 2010 08:46 AM
Last Post: e40pud
  OpenGL Center of rotation? 3DTOPO 7 19,679 Sep 26, 2008 01:30 PM
Last Post: haegarr
  Retrieving new object coordinates after translation/rotation chris69m 4 9,379 Apr 13, 2008 06:47 PM
Last Post: chris69m
  OpenGl rotation/translation problems? wyrmmage 2 6,797 Jan 6, 2008 01:58 PM
Last Post: wyrmmage
  2D OpenGL With SDL Rotation + Scaling Problem Greywhind 4 6,077 Jun 2, 2006 04:16 PM
Last Post: Greywhind