   [XNA] im confused by my matrix rotations!
  I was posting on the xna forums, but i cannot even get onto the site at the moment.I have made a class for my players ship, but it is not acting like i have predicted it to. This is the Load(), Rotate() and Move() functions i have at the moment, not the whole class but the ones that i think im having problems understanding.    class Ship    {   VertexPositionColorTexture[] shipVertices;   Vector3 position = new Vector3(0.0f, 0.0f, 0.0f);   Vector3 direction = new Vector3(0.0f, 1.0f, 0.0f);   Vector3 up = new Vector3(0.0f, 0.0f, 1.0f);   Vector3 right;   Matrix shipOrientation;   float rotation = 0.0f;   float velocity = 0.0f; private void Load()   {  right = Vector3.Cross(direction, up);  //shipOrientation = Matrix.CreateWorld(position, direction, up);  //shipOrientation = Matrix.CreateTranslation(new Vector3(0.0f,0.0f,-6.0f));  //shipOrientation = Matrix.Identity;  //initialize ship content and set it up ready for drawning  shipVertices = new VertexPositionColorTexture[4];  shipVertices[0] = new VertexPositionColorTexture(((position - direction) + (position - right)), Color.White, new Vector2(0.0f, 0.0f));  shipVertices[1] = new VertexPositionColorTexture(((position + direction) + (position - right)), Color.Blue, new Vector2(1.0f, 0.0f));  shipVertices[2] = new VertexPositionColorTexture(((position - direction) + (position + right)), Color.White, new Vector2(0.0f, 1.0f));  shipVertices[3] = new VertexPositionColorTexture(((position + direction) + (position + right)), Color.Blue, new Vector2(1.0f, 1.0f));shipOrientation = Matrix.CreateWorld(position, direction, up);   }   public void RotateShip(float amount)   {  Vector3 tempPosition = shipOrientation.Translation;  shipOrientation *= Matrix.CreateFromAxisAngle(shipOrientation.Up, amount);  rotation += amount;  shipOrientation.Translation = tempPosition;   }   public void MoveShip(float amount)   {  Vector3 velocity = shipOrientation.Forward * amount;  shipOrientation *= Matrix.CreateTranslation(velocity);   }}This class should be drawing a quad on the X,Y axis with the quad facing up towards the +Z axis. All of the vectors seem to be set properly and in the load function the vertices are created in the correct positions to draw my quad where i want it. But when it gets drawn it is a drawn flat on the X,Z axis, so its standing up where i want it to be laying flat!My rotate and move functions seem to work how i want them to, because i can move the quad around in whatever directino i face it in, the quad is just standing up instead of laying down. (I want to use it for a top down shooter kind game)So i think i am doing something wrong with the matrix rotations or rotating something at the wrong time but i just cannot for the life of me see where i am going wrong! its getting me very frustrated hehe i hope someone may be able to spot some obvious mistake im making, or tell me if im misusing the matrix and vectors in some way?Sorry for the long winded post, i just feel that i really need to get my head around rotating my game objects properly.Cheers for any help you can offer.   
Quote:Original post by leedude  shipOrientation = Matrix.CreateWorld(position, direction, up);On that line, you're asking XNA to create a matrix where an input of +Y is mapped to an output of +Z. XNA is Y-up by default, so it expects geometry fed to it to have +Y as semantic "up".Incidentally, I find Matrix.CreateWorld to be virtually useless, particularly if you already know what a cross product does. Just set rotation directly. A rotation around the up-vector is what you have 90% of the time, and that's not difficult to construct.   ;  sorry i dont understand what you mean by"where an input of +Y is mapped to an output of +Z"Arent i creating a matrix that describes the model/quad? and that model/quad has its own Up vector that is independent of the views Up vector?The way i have read it is i create the matrix that describes the models forward, up, right, and position vectors, and then this matrix gets passed to the effect so the model can be drawn. Am i incorrect in this thinking? Or should i just keep the vectors and use matrix operations to rotate and move these vector values and then before i draw the model i build a modelMatrix from these 4 vectors and pass it to the effect.Thanks for the reply, im slowly getting my head around it all....i think :p   ;Quote:Original post by leedudesorry i dont understand what you mean by"where an input of +Y is mapped to an output of +Z"Arent i creating a matrix that describes the model/quad? and that model/quad has its own Up vector that is independent of the views Up vector?A matrix doesn't "describe" geometry. A matrix, at base, is a mapping; you feed in points and vectors, and you get out transformed points and vectors. You use it to (among other things) move things around without changing their vertices.Try this: Render your quad without the transformation (that is, with the default transformation, which is the identity matrix). Then play around with the transformations; try rotations of pi/2 and pi/4 around different axes, and also CreateWorld matrices with different parameters. Also, stop making your vertex coordinates dependent on... well, anything; just hardcode the numbers in there.   