Getting Current Translation And Rotation In OpenGL
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?
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();
}
}
using glGetFloatv but instead you want to just glPushMatrix and glPopMatrix
Sir, e^iπ + 1 = 0, hence God exists; reply!
Thanks. I'm used to using DirectX and now the Ogre engine, so I'm forgetting things here and there.
Don't forget to mind your stack depth.
---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
SDL. Current music position | e40pud | 0 | 3,612 |
Mar 9, 2010 08:46 AM Last Post: e40pud |
|
OpenGL Center of rotation? | 3DTOPO | 7 | 19,343 |
Sep 26, 2008 01:30 PM Last Post: haegarr |
|
Retrieving new object coordinates after translation/rotation | chris69m | 4 | 9,273 |
Apr 13, 2008 06:47 PM Last Post: chris69m |
|
OpenGl rotation/translation problems? | wyrmmage | 2 | 6,721 |
Jan 6, 2008 01:58 PM Last Post: wyrmmage |
|
2D OpenGL With SDL Rotation + Scaling Problem | Greywhind | 4 | 5,964 |
Jun 2, 2006 04:16 PM Last Post: Greywhind |