Jump to content
  • Advertisement
Sign in to follow this  
technic

Simple FPS Yaw-Pitch Camera

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

Hello everyone, I'm trying to code a very simple camera to implement a free-fly first person style camera in my first 3D engine. I'm using Managed DirectX as my API of choice but that isn't particularly important, I'm curious as to what is wrong with this matrix setup. To get an idea of the simple test case: I have a box rendering at the origin. The camera is translated back down the Z-axis and is pointing at the origin (i.e. no rotations) so that the box is in view. Basically, the problem is when I try to yaw or pitch the camera I'm getting an orbit around the box instead of an "in place" FPS style yaw or pitch. So obviously something is wrong about how I'm applying the translation. I want the camera to stay in the same place world space wise and just have it's heading change when I yaw and pitch. Here is the pseudocode for what I'm doing: camMatrix = identity; camMatrix.RotateYawPitchRoll(yaw,pitch,0); camMatrix.position = previousCamPos; (i.e. set the matrix translation directly) Then I set camMatrix to the View matrix in the fixed function pipeline to be applied when rendering. Where am I going wrong?

Share this post


Link to post
Share on other sites
Advertisement
I don't know enough about D3D to tell you for sure what the problem is. But I will tell you that the view matrix should be the inverse camera matrix, and it looks like you're constructing an object matrix for the camera.

This isn't the most efficient way to do it, but try calling D3DXMatrixInverse() on your matrix before using it to set the view matrix.

Again, due to my limited knowledge of DirectX, this is only a guess.

Share this post


Link to post
Share on other sites
Just in case anyone else comes across this, as was posted above the issue was not inverting the camera matrix for the input to the view matrix. Thanks again.

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!