• Advertisement
Sign in to follow this  

Different ways of building a FPS style camera

This topic is 3701 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'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
Advertisement
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
The code that I linked to implements exactly what OrangyTang described.

Share this post


Link to post
Share on other sites
The C# port of that code can be found here. It says that you need a password, but you don't (I just checked).

Share this post


Link to post
Share on other sites
It says wrong DirectX version if I try to run that project. The whole thing is cursed maybe I should go back to Pascal...

Share this post


Link to post
Share on other sites
Probably the easiest way to fix that is to create a new project and link the appropriate libraries.

Share this post


Link to post
Share on other sites
Just did that, removed the DirectX references and added them again. It runs in full screen, but nothing happens, just a blank light orange colored screen.

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

  • Advertisement