public static FPQuaternion LerpUnclamped(FPQuaternion a, FPQuaternion b, FP t) { FPQuaternion result = FPQuaternion.Multiply(a, (1 - t)) + FPQuaternion.Multiply(b, t); result.Normalize(); return(result); }
public static FPQuaternion FromToRotation(FPVector fromVector, FPVector toVector) { FPVector w = FPVector.Cross(fromVector, toVector); FPQuaternion q = new FPQuaternion(w.x, w.y, w.z, FPVector.Dot(fromVector, toVector)); q.w += FP.Sqrt(fromVector.sqrMagnitude * toVector.sqrMagnitude); q.Normalize(); return(q); }
/** * @brief Rotates game object based on provided axis, angle of rotation and relative space. * * If relative space is SELF then the game object will rotate based on its forward vector. **/ public void Rotate(FPVector axis, FP angle, Space relativeTo) { FPQuaternion result = FPQuaternion.identity; if (relativeTo == Space.Self) { result = this.rotation * FPQuaternion.AngleAxis(angle, axis); } else { result = FPQuaternion.AngleAxis(angle, axis) * this.rotation; } result.Normalize(); this.rotation = result; }
/** * @brief Rotates game object based on provided axis angles and relative space. * * If relative space is SELF then the game object will rotate based on its forward vector. **/ public void Rotate(FPVector eulerAngles, Space relativeTo) { FPQuaternion result = FPQuaternion.identity; if (relativeTo == Space.Self) { result = this.rotation * FPQuaternion.Euler(eulerAngles); } else { result = FPQuaternion.Euler(eulerAngles) * this.rotation; } result.Normalize(); this.rotation = result; }
public static FPQuaternion LerpUnclamped(FPQuaternion a, FPQuaternion b, FP t) { FPQuaternion tmpQuat; // if (dot < 0), q1 and q2 are more than 360 deg apart. // The problem is that quaternions are 720deg of freedom. // so we - all components when lerping if (Dot(a, b) < 0.0F) { tmpQuat = FPQuaternion.Multiply(b, -1); } else { tmpQuat = b; } FPQuaternion result = FPQuaternion.Multiply(a, (1 - t)) + FPQuaternion.Multiply(tmpQuat, t); result.Normalize(); return(result); }