public static Quaternion Blend(float t, Quaternion a, Quaternion b) { float norm = Quaternion.Dot(a, b); bool flip = norm < 0; if (flip) norm = -norm; float inv_t; if (1 - norm < 1e-6f) inv_t = 1 - t; else { float theta = (float)Math.Acos(norm); float s = (1 / (float)Math.Sin(theta)); inv_t = (float)Math.Sin((1 - t) * theta) * s; } if (flip) t = -t; return new Quaternion( inv_t * a.x + t * b.x, inv_t * a.y + t * b.y, inv_t * a.z + t * b.z, inv_t * a.w + t * b.w); }
public static float Dot(Quaternion a, Quaternion b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; }
public Transform(Quaternion r, Vector3 t) { rotation = r; translation = t; }