namespace FPS.GameComponents
{
public class Camera : Microsoft.Xna.Framework.GameComponent
{
Game1 game;
public Matrix view;
public Matrix projection;
Vector3 to;
Vector3 position;
int choice = 0;
public Camera(Game game)
: base(game)
{
this.game = game as Game1;
position = new Vector3(0, 0, 0);
to = new Vector3(0, 10, 0);
view = Matrix.CreateLookAt(position, to, new Vector3(0, 0, 1));
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, game.GraphicsDevice.Viewport.AspectRatio, 0.2f, 500);
}
public override void Update(GameTime gameTime)
{
if (Input.State.IsKeyDown(Keys.W))
{
to = Vector3.Transform(to, Matrix.CreateRotationX(MathHelper.ToRadians(1)));
}
if (Input.State.IsKeyDown(Keys.S))
{
to = Vector3.Transform(to, Matrix.CreateRotationX(MathHelper.ToRadians(-1)));
}
if (Input.State.IsKeyDown(Keys.A))
{
to = Vector3.Transform(to, Matrix.CreateRotationZ(MathHelper.ToRadians(1)));
}
if (Input.State.IsKeyDown(Keys.D))
{
to = Vector3.Transform(to, Matrix.CreateRotationZ(MathHelper.ToRadians(-1)));
}
view = Matrix.CreateLookAt(position, to, new Vector3(0, 0, 1));
base.Update(gameTime);
}
}
}
I discovered by experiment that by creating a Z rotation I could rotate my view left or right. I also discovered that applying a Y rotation to my cube rotated it up or down. However, trying to apply the Y rotation to my look vector fails miserably. It does nothing at all until I rotate my view left and right, and once I do it seems to be rotating the view in a circle.I semi-fixed the problem by changing it to X rotation. This works to move the view up and down, but once I move it left or right it still has the problem where the camera's to vector just rotates in a circle on the screen:
This post has been edited by PlasticineGuy: 16 September 2011 - 02:04 AM

New Topic/Question
Reply



MultiQuote




|