XNA如何旋转汽车轮胎?

时间:2014-02-22 23:39:30

标签: c# matrix xna rotation quaternions

我有存储轮胎旋转和平移的矩阵

tireMatrix = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);

This happens

当我向前移动时,滚轮旋转正常,但当我转动它时,如图所示。任何人都可以帮忙。

2 个答案:

答案 0 :(得分:1)

我只是猜测你如何设置其余代码(例如轮胎是汽车的一部分还是自己的模型等)。这是许多方法中的一种,可以执行您要执行的操作。汽车轮胎只需沿两个轴旋转:汽车的轴和汽车的法线轴。所以要做正向旋转,你必须做这样的事情。 (这假设你的轮胎是汽车网格的一部分并且有自己的骨头)

tireMatrix *= Matrix.CreateRotationX(roll); //or whichever axis your axle is on

然后沿正常轴旋转轮胎:

tireMatrix *= Matrix.CreateRotationY(turnangle);

如果轮胎是自己的型号(这是您的图像的样子),请尝试:

//rotate the tire along the right axis to make it spin
tireMatrix *= Matrix.CreateFromAxisAngle(tireMatrix.Right, theta); 
//rotate the tire along its normal axis
tireMatrix *= Matrix.CreateFromAxisAngle(tireMatrix.Up, turntheta); 

另请参阅here以获取有关动画的更多帮助

答案 1 :(得分:0)

在我看来,您可以按顺序应用多个旋转,而不考虑每次变换中发生的轴的变化。

在你的第一次改造中,你转向右转并相应地转动你的轮胎。但随后它稍微转向右侧,然后之前的滚动动作将创造这种“翻滚”运动。