我试图基于沿着指定四元数旋转的同一轴的四元数旋转分量,围绕一个轴(任意单位矢量,不一定是x,y或z)旋转对象。
public void Rotate(Quaternion rotation, Vector3 axis, Vector3 pointToRotateAround)
{
float angle = ?
gameObject.transform.RotateAround(pointToRotateAround, axis, angle);
}
我不知道如何获得仅沿指定轴的四元数旋转角度。我可以在轴为y时执行此操作,例如:
public void Rotate(Quaternion rotation, Vector3 pointToRotateAround)
{
gameObject.transform.RotateAround(pointToRotateAround, Vector3.up, rotation.eulerAngles.y);
}
我想复制上面的结果,但对于任何给定的轴。
我已经挖了谷歌试图找到答案,但我还没有找到解决方案。任何帮助表示赞赏。
这是我想要的代码:
public void Rotate(Quaternion rotation, Vector3 axis, Vector3 pointToRotateAround)
{
float angle;
Vector3 rotAxis;
rotation.ToAngleAxis(out angle, out rotAxis);
float angleAroundAxis = Vector3.Dot(rotAxis, axis);
gameObject.transform.RotateAround(pointToRotateAround, axis, angleAroundAxis);
}