View Full Version : Ability to tell where the transformed modelview origin point is
It would be nice to be able to get the modelview origin for a ModelView matrix that is used to transform glVertex3f.
At the moment I'm trying to calculate it and I'm having absolutely no sucess. I've looked all over google.com, asked on several message boards (with no useful answers, or none at all), and tried just about every combination of reversing signs, rotating transformations, not reversing or not rotating transformations, of the numbers I extract from the modelView matrix. And none of it works! They all failed to give a coord that could be used consistantly for correct depth sorting. (Blended objects are best done with depth sorting)
In general, you should always use separate variables that holds the values of where your viewpoint is, aswell as for your objects. Doing so, you don't need to know where the matrix's origin is located. And for depthsorting, just calculate the distance from the viewpoint and the objects to be sorted.
In my oppinion, you should never need to do things like this. If you once placed the origin somewhere, pointing it in a certain direction, you must have used some kind of variable/static to get there, and why not use these variables/statics for this purpuse.
01-20-2001, 03:59 PM
Maybe I'm crazy, but for depth testing on opengl it is not only faster to use the hess'sche normal-form of a plane to calculate the distance (no square root for every vertex, 3 floating point subtracts, 2 floating point additions and 3 floating point multiplications) than to use the distance from the viewpoint (3 floating point multiplications, 2 floating point additions one square root ). It's also more exact.
You don't need to do a squareroot to get the distance. OK, to get the exact distance you need it, but for depthsorting, the exact distance is not needed, only the relative distance. Use the squared distance instead. If a > b, then a^2 > b^2. Because a distance is always positive, the above forulma is always correct, for any positive value of a and b.
So I dunno it's slower (3 fp multiplications, 2 fp adds), but as you say, it's less correct.
01-21-2001, 11:29 AM
Well, I'm not only using it for depth testing so I always needed it to be exact. Didn't think about only depth testing, ooops. Well, thanks anyway! http://www.opengl.org/discussion_boards/ubb/smile.gif
That I didn't see that. ****.
Well, anyway, the depth is the distance from the near culling plane, so only planar distance will be exact for many big and near-to-each other billboards.
Hmm, if you're not guilty of projection matrix abuse (see http://web2.airmail.net/sjbaker1/projection_abuse.html ) the last row of the modelview matrix negated should give you the viewer position. What do you get?
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.