How to rotate a 3D model around its center?

I am making a game with a 3D car and I have a rotation problem. I want to rotate the model around me, but when I move, it starts to move around the world!

The question arises: how to create a center for moving the model?

I tried to change the code as follows:

 effect.World = Matrix.CreateRotationZ(modelRotation) *  effect.World = Matrix.CreateTranslation(position); 

now instead of moving forward relative to the model, the orientation moves in a given direction! & Amp; this is my code:

 effect.World = Matrix.CreateTranslation(position) * Matrix.CreateRotationZ(modelRotation); 
                effect.View = camera.View; 
                effect.Projection = camera.Projection;
+5
source share
2 answers

I have some tips to help you get started:

  • The matrix order of multiplication in DirectX / Xna is different from what you learned at school.

v = A B y : v = A (B y). B .

A B, C = A B

Directx/XNA . B A, var C = B * A;

, : ( ) AtoB: WorldToView, ModelToWorld ModelToRotatedModel.

, :

  var modelToView = modelToWorld * worldToView; 

:

  var nowhereToNowhere = worldToView * modelToWorld; 

, , .

P.S. , , - .

+3

:

effect.World = Matrix.CreateTranslation(position) * Matrix.CreateRotationZ(modelRotation);

:

effect.World = Matrix.CreateRotationZ(modelRotation) * Matrix.CreateTranslation(position);

, ISROT

, Translation.

+3

All Articles