owc

Started by
3 comments, last by WilyCoder 17 years, 5 months ago
... [Edited by - WilyCoder on November 5, 2007 1:56:34 PM]
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).
...

[Edited by - WilyCoder on November 5, 2007 1:39:50 PM]
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
...

[Edited by - WilyCoder on November 5, 2007 1:33:04 PM]

This topic is closed to new replies.

Advertisement