繁体   English   中英

XNA-绕X和Z轴旋转3D

[英]XNA - Rotate around X and Z axis 3D

我是XNA的新手。 我只是陷入某种困境-我必须在游戏中倾斜/翻转角色,这意味着绕X轴和Z轴旋转(不能同时进行!)我可以转弯-意味着绕Y轴旋转。 我有旋转矩阵,还有角色的当前位置矢量(也可以从旋转矩阵获得的朝向/方向矢量),我实现了旋转,即通过将相对矢量绕Y轴旋转R弧度来绕Y轴旋转。 例如,如果我现在要绕X轴旋转,那该怎么办? 例如,从站立位置更改为“超人飞行”位置将需要角色倾斜... y旋转并不涉及更改角色的位置,而只是更改了面板。 但是我想对于X和Z,我也必须操纵位置吗? 请给我一些指导。

弄清楚了! 只需将模型围绕可通过旋转矩阵获得的右/前向矢量旋转即可。 发现以下博客文章非常有帮助: https : //stevehazen.wordpress.com/2010/02/15/matrix-basics-how-to-step-away-from-storing-an-orientation-as-3-angles/ #comment-376

至于代码,这是一个示例: 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; 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM