Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

XNA Camera Problem

Started by DumpAlien Jul 4, 2008 at 2:11 AM 0 replies 550+ views
Original Post
DumpAlien
DumpAlien
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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.