Loading transformation matrix directly
Hi there,
I am generating transform 4x4 matrices for different 3d models and would like to load them directly into OpenGL so as to avoid having to call the glTranslatef and glRotatef set of functions.
How can this be accomplished assuming the matrices specify the object's position from the origin (0,0,0) and rotation? Will calling glLoadMatrixf suffice, after setting glMatrixMode to GL_MODELVIEW?
Thank you.
PS: I'm asking this question, as I'm unable to test it out by myself at the moment.
glLoadMatrix will replace the current matrix completely. Assuming your matrix contains ALL of the transformations you're interested in performing, it shouldn't be a problem.
Thanks for the prompt reply, it is much appreciated!
By "all the transformations" do you mean translation from point of origin plus rotation on local axes (and no scaling in my case)? Sorry for the emphasis but I only want to be sure. :)
Quote:Original post by strtok
glLoadMatrix will replace the current matrix completely. Assuming your matrix contains ALL of the transformations you're interested in performing, it shouldn't be a problem.
By "all the transformations" do you mean translation from point of origin plus rotation on local axes (and no scaling in my case)? Sorry for the emphasis but I only want to be sure. :)
I think strtok means that your matrix will need to include all the translations from object space to world space (translations, rotations, scaling (OK, you said you don't scale)) AND the transformations to eye space.
Keep in mind that the modelview matrix contains the model transformations as well as the view transformations. So unless you don't assume that the camera is in its default position and orientation you need the camera's view transformations as well.
I therefore do the following per frame/camera:
Keep in mind that the modelview matrix contains the model transformations as well as the view transformations. So unless you don't assume that the camera is in its default position and orientation you need the camera's view transformations as well.
I therefore do the following per frame/camera:
glLoadMatrix(cameraMatrix); //load view matrixfor each object to render{ glPushMatrix(); //save view matrix glMultMatrix(objectWorldTransform); //create modelview glPopMatrix(); //restore view matrix}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement