Jump to content
  • Advertisement
Sign in to follow this  
SuperNerd

Camera Matrix

This topic is 4697 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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
First you subtract the camera position then you can use
this function
to create a rotation matrix. Just put the main camera direction as the new z axis and the up vector as the new y axis.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!