#### Archived

This topic is now archived and is closed to further replies.

# estimating camera position...

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

## Recommended Posts

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

##### Share on other sites
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]

##### Share on other sites

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.

##### Share on other sites
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.

##### Share on other sites
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 ,-)

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013434
×