So I've been toying around with creating a game in the XNA framework. A great place to start is simply being able to move and walk around.
I kinda have looking around...
I start off with the camera position/direction as follows:
cameraDirection = Matrix.CreateLookAt(new Vector3(0, 0, 1.5f), new Vector3(0, 1, -1), Vector3.Up);
I also have a small cube rendered in a static location, on which I plan to walk around. I'm manipulating the cameraDirection from a controller as follows:
GamePadState one = GamePad.GetState(PlayerIndex.One);
if (one.Buttons.Back == ButtonState.Pressed)
this.Exit();
if (one.ThumbSticks.Right.Length() > .1f) {//Deadzone, must push stick at least 10%
cameraDirection *= Matrix.CreateRotationY((float)(gameTime.ElapsedGameTime.TotalMilliseconds * (.002 * one.ThumbSticks.Right.X)));
cameraDirection *= Matrix.CreateRotationX((float)(gameTime.ElapsedGameTime.TotalMilliseconds * (-.002 * one.ThumbSticks.Right.Y)));
}
And at first this appeared to work. Then I realized that the X and Y axes are relative to the camera's current orientation. If I turn left and right while looking straight forward, that appears to work. If I look straight down and then turn left and right, I'm rotating along a different axis. I want to look around in relation to the world's axes instead of the camera's... How can I do this?