Sign in to follow this  

Camera Matrix

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quote:
I am creating my own 3D game engine and I need to know how to make a camera matrix based on a position direction and up vector.
That isn't enough information; you'll also need something else, such as a target position or a side or forward vector.

Also, how you set up the matrix will depend on your math library conventions - specifically, whether you're using row or column vectors, and (if your matrix is a 1d array which you are accessing directly) whether the matrix is row or column major.

Share this post


Link to post
Share on other sites
Ok, if you're given the position of the camera frame, and two of the basis vectors you have enough information.

For starters, just so you know, if you have a frame (consisting of 3 basis vectors - side up and front, and a position relative to another frame), to transform a point by that frame we use the matrix:


[Sx Ux Fx Px]
[Sy Uy Fy Py]
[Sz Uz Fz Pz]
[0 0 0 1]


To transform vertices into that frame - as in what we need to do for a camera transformation, the inverse of this matrix is used, which is:


[Sx Sy Sz -P.S]
[Ux Uy Uz -P.U]
[Fx Fy Fz -P.F]
[ 0 0 0 1 ]


Since you have the up and front vectors, the side vector can be calculated using the cross product.

This assumes OpenGL. For Direct3D, the transpose of these matrices would have to be used.

Share this post


Link to post
Share on other sites
Unless you have other 4x4 matrices to pipeline you will get better performance if you subtract first and use a 3x3. Oh yeah I forgot to mention you need to do cross product to get the side vector.

Share this post


Link to post
Share on other sites
Quote:
Original post by Alrecenk
Unless you have other 4x4 matrices to pipeline you will get better performance if you subtract first and use a 3x3.


Which, unless you're writing a software engine, you will have.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this