Jump to content
  • Advertisement
Sign in to follow this  
me_here_me

OpenGL basic questions about openGL

This topic is 4328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I want to write the following algorithm using c and openGL but am facing problems due to my inexperiance with openGL. float const transX = 20; float const transY = 30; float const transZ = 90; float const transXInv = -20; float const transYInv = -30; float const transZInv = -90; //.. some openGL working goes here glTranslatef(transXInv, transYInv, transZInv); glPushMatrix(); glRotatef(angle,0,0,0); // angle is generated elsewhere in the program glTranslatef(transX, transY, transZ); glPushMartix(); for (int y=0;y<300;y++){ for (int x=0;x<300;x++){ for (int z=0;z<300;z++){ // Q1: here i want to tranform points (x,y,z) according to the above final MV // matrix produced earlier and get back result as another point // BUT i donot know the function for doing this tranformation // Q2: i want to get the "transposed Inverse" of the final MV matrix here, but // don know the method for that glPopMatrix(); } } } Q3: I have three nested loops that are doing a lot of work. I have to generate "transposed inverse" of the result in each loop iteration and then pop away the stuff. Can I work around this overhead by generating both the MV matrix and its "transopsed inverse" before the loop begins. So that I have two seperate matrices that I just use in my loop? any ideas: thanks

Share this post


Link to post
Share on other sites
Advertisement
Q1: Getting the result after one matrix from OpenGL is not easy. Easiest is probably to do it yourself. Learn some matrix math and multiply the point by the modelview matrix. You can get the modelview matrix with glGetFloatv and GL_MODELVIEW_MATRIX.

Q2: You must invert it yourself. OpenGL does not provide any way to get the inverted matrix.

Q3: I don't really understand what you want to do. In this example (although ignoring the push/pop mismatch I will explain below) you never change the matrices within the loops, so preclaculate it before all three loops. No need to get and invert the matrix each loop.

Concerning two things in your code. The call to glRotate is not well defined. You're rotating about the zero vector which is not well defined. And the pushes and pops are not matched. You must have exactly one, no more, no less, pops for each push you do. Your code makes two pushes and 27000000 pops. This is FAAAR from correct. If anything, place two pops after the three for loops, or wherever you want them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!