• Advertisement
Sign in to follow this  

XNA Camera Problem

This topic is 3584 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 there! :) I am trying to implement a Camera for an XNA 2.0 Project.. The problem is that the camera behaves a little strange... When I move forward the camera moves backwards and the opposite. The same happens in the Yaw rotation too. I have used this camera (a C++ version) in a D3D10 Engine and it was running smoothly. I calculate the projection matrix using the XNA CreatePerspectiveFieldOfView() function. Here is the "Update()" function that calculates the View matrix:
public override void update()
        {
            mUpVector    = new Vector3(0.0f,1.0f,0.0f);
            mLookVector  = new Vector3(0.0f,0.0f,1.0f);
            mRightVector = new Vector3(1.0f,0.0f,0.0f);

            Matrix yawMatrix = Matrix.CreateFromAxisAngle(mUpVector, mYaw);
            mLookVector  = Vector3.Transform(mLookVector, yawMatrix);
            mRightVector = Vector3.Transform(mRightVector, yawMatrix);

            Matrix pitchMatrix = Matrix.CreateFromAxisAngle(mRightVector, mPitch);
            mLookVector  = Vector3.Transform(mLookVector, pitchMatrix);
            mUpVector    = Vector3.Transform(mUpVector, pitchMatrix);
            
            Matrix rollMatrix = Matrix.CreateFromAxisAngle(mLookVector, mRoll);
            mRightVector = Vector3.Transform(mRightVector, rollMatrix);
            mUpVector = Vector3.Transform(mUpVector, rollMatrix);

            mViewMatrix = Matrix.Identity;
            mViewMatrix.M11 = mRightVector.X; mViewMatrix.M12 = mUpVector.X; mViewMatrix.M13 = mLookVector.X;
            mViewMatrix.M21 = mRightVector.Y; mViewMatrix.M22 = mUpVector.Y; mViewMatrix.M23 = mLookVector.Y;
            mViewMatrix.M31 = mRightVector.Z; mViewMatrix.M32 = mUpVector.Z; mViewMatrix.M33 = mLookVector.Z;

            mViewMatrix.M41 = -Vector3.Dot(mPosition, mRightVector);
            mViewMatrix.M42 = -Vector3.Dot(mPosition, mUpVector);
            mViewMatrix.M43 = -Vector3.Dot(mPosition, mLookVector);

            mViewMatrix.M14 = 0.0f; mViewMatrix.M24 = 0.0f; mViewMatrix.M34 = 0.0f; mViewMatrix.M44 = 1.0f;
        }
mYaw, mPitch, mRoll is the ammount of rotation. Can you see anything wrong in this code? You have a better idea on how to create an XNA Camera? Thanks for your time!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement