Istiaq Ahmed - 9 months ago 54

C# Question

I'm new to XNA.

I just got stuck into something - I have to tilt/flip a character in my game that means rotate around X axis and the Z axis (not simultaneously!)

I can do the turn - that means rotate around Y axis.

I have the rotation matrix, and character's current position vector (also the facing/direction vector that can be obtained from rotation matrix)

I implemented the turn i.e. rotation around Y axis by rotating the facing vector around Y axis by R radians.

If i were to do the rotaion now around X axis, for example, what would be the approach? For example, change from standing position to a "Superman Flying" position would need the character to tilt...

The y rotation didn't involve changing the position of the character, just changed the facing. But i suppose for X and z, i have to manipulate position as well? Please show me some guidance.

Answer Source

Figured it out! Just had to rotate the model around right/forward vectors that are available through the rotation matrix. Found the following blog post very helpful: https://stevehazen.wordpress.com/2010/02/15/matrix-basics-how-to-step-away-from-storing-an-orientation-as-3-angles/#comment-376

As for code, here is a sample:```
Vector3 rightVector = target.CurrentModelMatrix.Right;
var rotMatrix = Matrix.CreateFromAxisAngle(rightVector , (float)GetRadianAngle(10));// Will tilt the character forward around the right vector
target.CurrentModelMatrix *= rotMatrix;
```