PDA

View Full Version : Multiply current Matrix with the stacked Matrix



ColacX
06-22-2009, 07:22 AM
Hi there is there anyway to multiply your current matrix with the one on the stack?

I'm testing out some object oriented coding with multiple cameras
So I have created a 3D world system
every object in it have global positions but local rotations
but to rotate every object locally before i draw them i have to first load an identity matrix then rotate then move it and then

somehow apply it with the camera-matrix that was pushed on the stack. I guess i could make every object store a local rotation matrix and multiply it with the camera-matrix or i hoped that opengl was smart enought to make a built in "multiply current matrix with top stacked matrix operation", because this probly would be super efficiant rather than storing matrixes some other place.

so is there one?


glPushMatrix(); //push camera matrix on stack

glLoadIdentity(); //creation of object matrix starts here
glRotatef(rx,1.0f,0.0f,0.0f); //apply local rotations
glRotatef(ry,0.0f,1.0f,0.0f);
glRotatef(rz,0.0f,0.0f,1.0f);

//space for my hoped matrix operation //merge camera matrix with object matrix

glTranslatef(px,py,pz); //apply global position

glBegin(GL_LINES);
glColor4f(1.0f,0.0f,0.0f,alpha);
glVertex4f(+scale,0.0f,0.0f,alpha);
glVertex4f(0.0f,0.0f,0.0f,alpha);

glColor4f(0.0f,1.0f,0.0f,alpha);
glVertex4f(0.0f,+scale,0.0f,alpha);
glVertex4f(0.0f,0.0f,0.0f,alpha);

glColor4f(0.0f,0.0f,1.0f,alpha);
glVertex4f(0.0f,0.0f,+scale,alpha);
glVertex4f(0.0f,0.0f,0.0f,alpha);
glEnd();

glPopMatrix(); //pop camera matrix on the stack

V-man
06-22-2009, 08:04 AM
Yes, there is glMultMatrixf.
Personally, I suggest that you don't use these things as they are considered deprecated. Do your own matrix math or use a ready made library. Here is mine
http://www.geocities.com/vmelkon/glhlibrary.html

and some examples here
http://www.geocities.com/vmelkon/gl3_and_glh.html

ColacX
06-22-2009, 09:21 AM
Yes, there is glMultMatrixf.
Personally, I suggest that you don't use these things as they are considered deprecated. Do your own matrix math or use a ready made library. Here is mine
http://www.geocities.com/vmelkon/glhlibrary.html

and some examples here
http://www.geocities.com/vmelkon/gl3_and_glh.html
No i dont understand how do you get/use the pushed matrix without using popmatrix? glMultMatrixf( PushedMatrix? )

V-man
06-22-2009, 12:08 PM
If you want to get the matrix,
float mymatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mymatrix);

If you want to know how to use push and pop

glPushMatrix();
glMultMatrixf(....);
DrawObject();
glPopMatrix(); //for every push, there must be a pop

ColacX
06-22-2009, 02:07 PM
Alright so what you are saying is that my function that i'd like to exist doesnt exist. gotcha.