#### Archived

This topic is now archived and is closed to further replies.

# push/popmatrix()

## Recommended Posts

Hi... I''ve got 2 questions: 1) where from does pushmatrix() know, what matrix it''s supposed to push onto the stack? the following to lines? so would this push glRotatef() and glTranslatef() onto the stack right?
  glpushmatrix(); glRotatef(*whatever*); //<-------\ glTranslatef(*whatever*);//<-----| glpopmatrix(); // takes of these-/ ? 
2) is it able to put glRotatef() and glTranslatef() between glBegin() and glEnd() ? thx. cya, Phil

##### Share on other sites
1 - glPushMatrix pushes the matrix you are currently operating on onto a stack, I assume in this case the modelview matrix. glPopMatrix destroys the current matrix by loading the last matrix pushed onto the stack. You would have to place a polygon for the rotate and translate to operate on in between the push and pop. In you pseudocode nothing would happen.
2 - No.

I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!

##### Share on other sites
ok, thx,

i knew, that it wouldn''t do anything without a polygon in between them, i just wanted to see if that would use the gltranslatef() and glrotatef() as matrix data...ok, it does...
thx.

2) hmmm. then, if i only draw 1 vertice between glBegin(GL_TRIANGLE) and glEnd(), then apply my rotations and transformations, the glBegin(GL_TRIANGLE) draw 1 vertices glEnd(), apply transformations and rotations again, and then draw the next vertex... would this draw my triangle or would i just draw nothing, because it looses the data from the first glBegin(GL_TRIANGLE) ?

i need this, because i''m trying to animate a model with bone animations and i want to save the joints, which cannot be saved to display lists (since they change every frame), saved in an own display list for each frame...

then i can draw the model for each frame, by drawing the display list for the joints for that frame and applying the meshes in the display lists by first rotating and translating to the right position...

sounds kinda complicated, but if it works it would save memory and calculation time...

cya,

Phil

##### Share on other sites
What you should do is create some type of heirarchal structure to store your model in. Each node would hold a display list build from the segment (such as fore arm, upper arm, shin, thigh, etc) and the rotation and position of the joint (relative to the parent joint). So you still get to gain speed by using display lists, but also can rotate joins and stuff. When you draw, just start with the top node (probably the head if you are doing a humanoid), then apply a glRotatef() for the rotation of the neck joint, then draw the torso, then do a glRotatef() before drawing the upper arm, etc. Am I explaining this well enough? If you need more explanation, I could write up some psuedo code.

Morgan

##### Share on other sites
This is a list of valid commands that can appear between glBegin and glEnd in opengl 1.2
glVertex
glColor
glIndex
glNormal
glTexCoord
glMultiTexCoord
glEdgeFlag
glMaterial
glArrayElement
glEvalCoord
glEvalPoint
glCallList
glCallLists

I think opengl wants you to define a shape in totallity before you begin transforming it. I get all sorts of errors if I screw up a glbegin/end pair. I usually forget the end part. I think you have to multiply the transformation matrix by the location of the points of your joints and then use the transformed coordinates to draw your triangles or quads. I have never done this so don''t quote me.

##### Share on other sites
ok, first thx for your replies again...

Morgan> I''ve got an heirarchal structure. (i get it from the milkshape3d modeler. i wrote a plugin for my own file format)
The problem with that is, that not all face''s vertices have to belong to the same bone. (the connection faces between the meshes). so what i was planning to do, is to make display lists from the faces that belong to one bone and rotate those and the with the rest, i''d build display list for each frame...
but, since i can''t rotate between the glBegin() and glEnd() (thx to GKW for the info) i can''t draw the faces correct... so what i''m thinking of now, is just to rotate and transform all of the vertices that are left, to the right position without glRotate()
(Yes, by "hand" ;-) and glTranslate() and then save the results in display lists...
actually, does it really pay of to use displaylist for such small parts? and friend (and the lead programmer of my programming group says it doesn''t)... i kinda in between.. what''s your opinion?

thx,

Phil

##### Share on other sites
I doubt that you would get a huge speed increase with small display lists but if it is used alot who knows. I don''t think you should be using display lists for what you are doing. Making a new display list every frame sounds like a problem in the making. I bet the best way to go is the vertex array. You will be able to alter a vertex when needed and the you can draw every frame via glArrayElement. In the red book it suggests using display lists for objects that do not change shape and need to be displayed in different places. Like wheels on a car. Make the wheel once then call the display list for each rotation and transfomation for each wheel. If you are using c using the arrayelement is a good way to go. I am using java so the lack of pointers is a problem in this case but once I get my vrml parser working I will get to find out for myself as using the array is the method I plan to use. Like I said though this is my first time doing bone animation so if someone else out there knows a better way I would also like to hear about it.

I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!

##### Share on other sites

2 votes for the non-displaylist version... ;-)

also wanted to say, by "frame" i meant each frame of the animation, sorry bout that....

cya around,

Phil

##### Share on other sites
Correct me if I''m wrong, but somewhere I heard that Q3 creates a display list for eah frame in its characters animations, I would prefer a skeleton system, but maybe this would be something you would consider, it might solve your problem.

Morgan

##### Share on other sites
If you are going to use a display list for each frame of animation the displaylist are the way to go. I thought you were going for a dynamic model, which is what I will be diong soon. You might just end up fiddling with the locations for your vertex when you initialize the model. You should be able to figure out a system for moving the vertex and then compiling a display list for each frame of animation. Sorry about the confusion. For what you are doing I would use displaylists, so change my vote. If you know the location of each vertex in relation to the joint it is attached to then you should be able to easily figure out the location of each vertex after you rotate and translate the joints of your skeleton.

I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!

##### Share on other sites
ok...

resume: i''ll make for each frame of the animation 1 displaylist.
right? this means, that i takes more RAM, but i wouldn''t have to rotate and transform and loadidentity() that much at runtime....

ok,
thx a lot for all of your help...

cya around,

Phil

##### Share on other sites
All you will have to do is orient the model in your world with translate''s and rotate''s and then call the display list of the proper frame of animation. Good luck.

I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!

##### Share on other sites
One thing to note, once you have built the display list, you can get rid of your vertex info (saves RAM that way).

Morgan

• ### Forum Statistics

• Total Topics
628378
• Total Posts
2982334

• 10
• 9
• 15
• 24
• 11