estimating camera position...

Started by
3 comments, last by jake_NGC 20 years, 7 months ago
Hello, I''m working on an Opengl library and I need to find the camera position to do geomipmapping LOD. Because I''m working on a library I have no outside control of it''s position so I cannot simply keep track of it. I know I could find it my finding the inverse of the modelview matrix and multiplying [ 0 0 0 1] by it, but finding an inverse is too expensive. I was wondering if there was another, faster way of finding the exact position, or an estimated position? Any help is apreciated, Jake
Advertisement
finding the inverse of the modelview is extremely simple, because its a special case.

you just transpose the rotation part and negate the dotproducts for the position:

position would be:
x=-(mat[0]*mat[12] + mat[1]*mat[13] + mat[2]*mat[14])
y=-(mat[4]*mat[12] + mat[5]*mat[13] + mat[6]*mat[14])
z=mat[8]*mat[12] + mat[9]*mat[13] + mat[10]*mat[14]
f@dzhttp://festini.device-zero.de


Will that hold true for all cases? Even if there is translation, rotation, and scaling?

I thought I had read somewhere that it will only work if there is no scaling.

Let me know if anyone has any info on this.
mat[0],mat[1],mat[2] is the x-vector so you could normalize it. Dont forget that model transformations can also be on the modelview matrix.

Reading the matrix can also hurt performance a lot.
scaling sucks *g* you''ll have to normalize the three vectors first. and you should make it clear, that everybody writing code that will not push/pop the matrix to make sure you only get the "view" transformation will be shot ,-)

reading the matrix is a little expensive, true. but youre going to do it just once a frame i hope ,-)

the alternative would of course be to just pass the camera position to your class or you just the camera position as a pointer or reference in your class and set it in the constructor. not such a good idea if using more than one camera, though you would then most likely have a pointer to the active camera and could store a pointer to this pointer in your class. that way, if everybody uses this activecam pointer and its not valid it will screw up everything and nobody can blame you for being too dependent ,-)
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement