455
社区成员
发帖
与我相关
我的任务
分享
public static Quaternion CreateFromAxisAngle(Vector3 rotatorAxis, float radian)
{
// Here we calculate the sin( theta / 2) once for optimization
float factor = (float)Math.Sin(radian / 2.0);
// Calculate the x, y and z of the quaternion
float x = rotatorAxis.x * factor;
float y = rotatorAxis.y * factor;
float z = rotatorAxis.z * factor;
// Calcualte the w value by cos( theta / 2 )
float w = (float)Math.Cos(radian / 2.0);
Vector3 newV = new Vector3(x, y, z);
return new Quaternion(newV, w).Normalized;
}
// rotV为起始旋转向量,axis是旋转轴,angle是旋转角度
public static Vector3 RotatorFromAxisAngle(Vector3 rotV, Vector3 axis, float angle)
{
Quaternion rotator = CreateFromAxisAngle(axis, angle);
Vector3 res = new Vector3(rotator * rotV);
return res;
}