## Getting Current Translation And Rotation In OpenGL

Sage
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?

Code:
```        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 );                  glEnd();                  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();             }         }```
Sage
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!
Sage
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.
Member
Posts: 469
Joined: 2002.10
Post: #4
Don't forget to mind your stack depth.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB