旋转轴执行旋转 [英] Rotation axis to perform rotation

查看:52
本文介绍了旋转轴执行旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个第一人称相机看方向 d.

Having a first-person camera looking at direction d.

为了让相机指向目标 t(具有相关的方向 d2),我必须围绕某个轴旋转 d,对吗?这个轴应该穿过相机,并且应该垂直于 d 和 d2 形成的平面,对吗?

In order to let the camera point to a target t (with associated direction d2) I would have to rotate d around some axis, right ? This axis should go through the camera and should be perpendicular to the plane formed by d and d2, right ?

假设我每帧将向量 d 旋转一定程度,旋转轴不应该改变,因为尽管 d 慢慢接近 d2,但它们对应的平面并没有改变,对吧?

Suppose I am rotating the vector d by some degree per frame the rotation axis shouldn't change because though d is slowly approaching d2 their corresponding plane doesn't change, right ?

好吧,如果这一切都是真的,那么我想知道为什么下面示例中的旋转轴在每次调用时都会发生变化.旋转工作准确,但从旋转开始到结束速度下降.

Well, if that's all true then I am wondering why my rotation axis in the below example is changing on every call. The rotation works accurate but the speed decreases from start of the rotation to its end.

这篇文章来自此处的当前问题,您还可以在其中查看源代码.

This post is from the context of a current question here where you can also see the source code.

推荐答案

_rotationAxis 指向的方向不会改变,因此旋转方向在您状态下是恒定且正确的.但是 _rotationAxis 的大小正在发生变化,因此您会得到不同的 x、y、z 分量值和不同的旋转量.

The direction _rotationAxis points in is not changing thus direction of rotation as you state is constant and correct. But The magnitude of _rotationAxis is changing thus you get different values for the x, y, z components and a different rotation amount.

当您执行交叉以获得旋转轴时,结果向量的长度是交叉的两个向量长度的函数AND这将它们分开.结果向量的方向总是与两个输入向量成 90 度.

When you perform a cross to get a rotational axis, the length of the resulting vector is a function of the lengths of the two vectors that were crossed AND the angle that separates them. The direction of the resulting vector is always 90 degrees to both of the two inputted vectors.

很可能,您使用的 2 个向量的长度是一致且最相似的单位长度,但由于它们之间的角度每帧都较小,因此每帧 _rotationAxis 的长度不同.

Most likely, the lengths of the 2 vectors you are using is consistent and most likey unit length but since the angle between them less each frame, it results in a different length for _rotationAxis each frame.

在 Xna 中,由 CreateFromAxisAngle 产生的旋转量不仅取决于您插入的角度作为参数,还取决于轴向量的长度(在文档中不明显)但确实如此).因此,您在每帧使用越来越短的旋转轴,这会导致每帧的旋转量越来越小.如果旋转轴向量的长度为 1.0(单位长度向量),它只会导致您插入的旋转角度.

In Xna, the resulting amount of rotation produced from CreateFromAxisAngle is determined by not only the angle you plug into is as a parameter, but also the length of the axis vector (not obvious in the documentation but true none the less). So you are using a shorter and shorter rotational axis each frame which causes a smaller and smaller amount of rotation each frame. It will only result in the rotational angle you plugged in if the rotation axis vector's length is 1.0 (a unit length vector).

CreateFromAxisAngle 中使用之前,您必须规范化 _rotationAxis 以使其成为单位长度.

You must normalize the _rotationAxis to make it unit length before using it in CreateFromAxisAngle .

_rotationAxis = Vector3.Cross(Direction, _flyTargetDirection);
_rotationAxis.Normalize();
_rotation = Matrix.CreateFromAxisAngle(_rotationAxis, MathHelper.ToRadians(_flyViewingSpeed - Math.ToRadians(rotationSpeed)));

这篇关于旋转轴执行旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆