Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Camera Position from view matrix Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Jaap Suter

May 19, 1999, 04:09 PM

Hi,

I need to get my camera position in world space from my view matrix. My view matrix is constructed with three vectors and a position. After that i just update myu view matrix only when moving the camera just by multiplying the view matrix with a transformation matrix.

Should i multiply the camera position with this matrix too so I always have the position at hand? Or can i read the position of the camera out of the view matrix in some way?

Thanks!!

 
Bryan Moodie

May 20, 1999, 06:04 PM

Hi Jaap,

>>Should i multiply the camera position with this matrix too so I always have the position
>>at hand? Or can i read the position of the camera out of the view matrix in some way?

I'm assuming this is your camera class at members.xoom.com/3dengine.

Yes, you can read it out for the view matrix.
The view matrix is a 4x4 matrix, so the position of the light is already in there.
When a 4x4 matrix is applied to a vector, the vector is moved by the last column.

[r][r][r][tx] r = rotation
[r][r][r][ty] t = translation
[r][r][r][tz]
[w][w][w][tw]

So the camera is at the position (-tx, -ty, -tz, tw).

Likewise you can change the position, making sure to take into account tw.
e.g.

tx += n*(-tw)

(moves n along the positive x axis)


-Bry


 
Jaap Suter

May 21, 1999, 05:09 AM

Thanks, but

What i have is only (and only!) a 4x4 viewpoint matrix. Can you please say what i should do exactly with this matrix to get my camera position in world space?

It's hidden somewhere in 41, 42 and 43 behind a dot product.

Jaap

 
Bryan Moodie

May 22, 1999, 01:27 PM

Hi Jaap,

>>What i have is only (and only!) a 4x4 viewpoint matrix.
>>Can you please say what i should do exactly with this matrix to get
>>my camera position in world space?

Basically, the last column in the matrix (41,42,43,44) is the
negative of the position.

So if you have the matrix:

[11] [21] [31] [41]
[12] [22] [32] [42]
[13] [23] [33] [43]
[14] [24] [34] [44]

Create a new vector with ( -41, -42 -43, 44), and that is
the position of the camera. That's it! :)

Try this: (you may have to transpose it, e.g. swap (3,0) for (0,3) etc...)

cVector cCamera::getPosition(){
return cVector( -_matrix.get(3,0), -_matrix.get(3,1), -_matrix.get(3,2), _matrix.get(3,3) );
}


-Bry

 
Jaap Suter

May 24, 1999, 08:40 AM

Thanks just what i needed.


 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.