Body.SetOrientation with Matrix.CreateFromAxisAngle

WILEz 28 Mar 2010 23:05

Hi, sorry for my bad english.

I would turn the camera on arbitrary axes (for a space game) with free look using mouse.

I need to use "Matrix.CreateFromAxisAngle" to freely move the view regardless of orientation …

I used this syntax, the view is moved by mouse.

```
private void ShipMouseMovment(float amountOfMovement)
{
//widthOver2 is screen width/2
if (currentMouseState.X != widthOver2)
{
angles.Y -= amountOfMovement / ammMoviment * (currentMouseState.X - widthOver2);
}
//heightOver2 is screen height/2
if (currentMouseState.Y != heightOver2)
{
angles.X -= amountOfMovement / ammMoviment * (currentMouseState.Y - heightOver2);
}
/* Commentated for now, i do not know what it's for
if (angles.Y > Math.PI) angles.Y -= 2 * (float)Math.PI;
if (angles.Y < -Math.PI) angles.Y += 2 * (float)Math.PI;
if (angles.X > Math.PI) angles.X -= 2 * (float)Math.PI;
if (angles.X < -Math.PI) angles.X += 2 * (float)Math.PI;
*/
// Resets the pointer to the center of the screen
Mouse.SetPosition(widthOver2, heightOver2);
//Normal moviment, works but not if the camera looks down because it does not rotate on the axis of view
// ShipObjectBody.SetOrientation(Matrix.CreateRotationZ(angles.X) * Matrix.CreateRotationY(angles.Y)) ;
//My problem: When the angle increases the visual mad
ShipObjectBody.SetOrientation((Matrix.CreateFromAxisAngle(ShipObjectBody.Orientation.Backward,angles.X)*
Matrix.CreateFromAxisAngle(ShipObjectBody.Orientation.Up,angles.Y)));
CamPosition = (ShipObjectBody.Position + ShipObjectBody.Orientation.Left * 1.5f);
view = Matrix.CreateLookAt(
CamPosition,
ShipObjectBody.Position,
ShipObjectBody.Orientation.Up) ;
}
```

Where is the problem? If use CreateFromAxisAngle, when the angle increases the visual mad!