Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

get projection matrix

Started by lamtab May 30, 2009 at 9:16 AM 7 replies 5.2k views
Original Post
lamtab
lamtab
Hello all!!!! I'd like some help getting the projection matrix. I use the following code but it doesnt seem to work properly. What id does is get the same matrix no matter what transformations I apply. glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80,1.0,1.0,5000.0); glTranslatef(100.0,-10.0,-5.0f); //Here I render the geometry. no transformations are taking place. glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix); projectionMatrix is an array float[16] No matter any changes to the translatef parameters the projectionMatrix is always the same. Thanks in advance...
Pooya65
Pooya65
switch to modelview matrix then use glTranslatef

glMatrixMode (GL_MODELVIEW);
glLoadIdenity();
glTranslatef(x,y,z);
// render jeomtry


calling projection matrix at first of program is enought and you dont need to recalculate and load it in every frame.
lamtab
lamtab
I've tried that and the projection matrix is still the same.
What i'm actually trying to do is get the projection matrix before and after the translate command.
Pooya65
Pooya65
are u check it in every frame?

i think becase you are using glLoadIdentity , its values is same in every frame.
lamtab
lamtab
yeap in every frame i print the matrices.
u mean i shouldnt use loadidentity?

can u give me a small example of how u think this should be done?
(i mean with code)
something like

glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrixA);
gluPerspective(80,1.0,1.0,5000.0);
glTranslatef(100.0,-10.0,-5.0f);
//geomtry
glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrixB);
RabidDog
RabidDog
Curious as to why you want to translate the projection matrix. The view matrix is ideally for the camera, the world matrix for your objects.
lamtab
lamtab
i need the projection matrices to apply motion blur :)
Pooya65
Pooya65
void init_func()
{
// load projection matrix
}

void render_func()
{
glMatrixMode(GL_PROJECTION);
glTranslatef (x,y,z);
// render some thing
glMatrixMode(GL_MODELVIEW);
glLoadIdentity()
// render object
...

}
lamtab
lamtab
thx pooya65.
i had in mind something like this myself. i was just missing something.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.