Sign in to follow this  
markookram

Different ways of building a FPS style camera

Recommended Posts

I'm trying to create a FPS style camera with Direct3D in C#. Have seen millions of tutorials, but they are all pretty much the same or give you only one part of the code and I can't figure it out. Most tutorials I have seen is with the Matrix.LookAtRH function which requires camera position AND camera target. Why the need for a target in a 1st person camera? Is there a way of setting up a camera without it? Something that would just have the camera movement and control the yaw/pitch/roll.

Share this post


Link to post
Share on other sites
Here you can find some code that uses a different approach (the files for part 3, chapter 12). It's part of a book's source code.

BTW, that book has a second edition, but it's implementation is different and seems more limited.

Share this post


Link to post
Share on other sites
Whenever I've done a FPS camera I've always stored the up, forward and right vectors and generated a view matrix from that (easy - you just have to shove them into a 4x4 matrix in the correct position and pad the rest out). For actual movement you can construct a 4x4 matrix and apply it to all the vectors. Eg. if you were turning left you'd make a rotation matrix around the 'up' vector for your turn amount and apply that.

Share this post


Link to post
Share on other sites
Quote:
Original post by markookram
Most tutorials I have seen is with the Matrix.LookAtRH function which requires camera position AND camera target. Why the need for a target in a 1st person camera?


Because without a target(Which could be a tiny fraction away from the actual camera position), what would the camera look at? I mean, in a 3D world, you can basically look in 360 degrees in all directions. If you don't define a target, the direction in which you look is kinda random.

Toolmaker

Share this post


Link to post
Share on other sites

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