Jump to content
  • Advertisement
Sign in to follow this  
WilyCoder

owc

This topic is 4414 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

Advertisement
You're right _in principle_ with your 2nd approach. But

(1) there is a little typo:
WorldP2 = P1*matrix should be WorldP2 = P2*matrix, of course.

(2) Don't use OpenGL's getMatrix routine for this job but track the matrices yourself. See that OpenGL has a MODELVIEW matrix there, and that the VIEW portion of that matrix is against of what you want. You want only the MODEL matrix here. You could use getMatrix and consider the VIEW portion specially, but that doesn't makes the things fancier, and you _will_ suffer from it, believe me. The threads here on GDnet are full of problems arised from using getMatrix for such purposes.

(3) You should be aware that OpenGL uses column vectors, while your above pseudo code suggests you're using row vectors. That doesn't need to be a problem but you have to consider that especially in conjunction with point (2).


As for the dimensions of a matrix: With a 3x3 sub-portion you can have rotation and scaling (and shearing) in 3D but no translation. You should always store the full 4x4 matrix but you may deal only with the particular relevant portion on a situation by situation basis (but be aware of what that really means w.r.t. the overall transformation).

Share this post


Link to post
Share on other sites
As haegarr said in his post: refrain from using glGet. There are dozens of online libraries that perform efficient matrix math, and you should use them instead of OpenGL's (slow) getters. Also, matrix math in itself isn't difficult at all.

Two comments on the last code snippet:

1) glGet( GL_MODELVIEW_MATRIX, ... ) gives you the Model matrix concatenated with the View matrix, which isn't really "right", although in your case it yields correct results. Don't use it.

2) You perform a glLoadIdentity followed by two pairs of glPush/glPop. In this case, you could just as well remove both pairs and replace the second pair with another glLoadIdentity

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!