Пример #1
0
    public static LFloat Angle(LQuaternion a, LQuaternion b)
    {
        LQuaternion q = b * LQuaternion.Inverse(a);

        q.Normalize();
        return(LMath.Acos(q.w));
    }
Пример #2
0
 public static LVector3 ToEulerAngles(LQuaternion rotation)
 {
     rotation.Normalize();
     return(new LVector3(
                LMath.Atan2(2 * (rotation.w * rotation.z + rotation.x * rotation.y), 1 - 2 * (rotation.z * rotation.z + rotation.x * rotation.x)),
                LMath.Asin(2 * (rotation.w * rotation.x - rotation.y * rotation.z)),
                LMath.Atan2(2 * (rotation.w * rotation.y + rotation.z * rotation.x), 1 - 2 * (rotation.x * rotation.x + rotation.y * rotation.y))
                ));
 }
Пример #3
0
    public static LQuaternion Slerp(LQuaternion from, LQuaternion to, LFloat t)
    {
        t = LMath.Clamp(t, 0, 1);
        LFloat diff   = Angle(from, to) * LMath.DegToRad;
        LFloat sind   = LMath.Sin(diff);
        LFloat sintd  = LMath.Sin(t * diff);
        LFloat sin1td = LMath.Sin((1 - t) * diff);

        return((sin1td / sind) * from + (sintd / sind) * to);
    }
Пример #4
0
    public static LQuaternion Inverse(LQuaternion rotation)
    {
        LQuaternion inv = rotation.conjugation;

        if (rotation.sqrtMagnitude != 1)
        {
            inv *= (1 / rotation.sqrtMagnitude);
        }
        return(inv);
    }
Пример #5
0
 public void Write(LQuaternion val)
 {
     Write(val.x); Write(val.y); Write(val.z); Write(val.w);
 }
Пример #6
0
 public static LQuaternion Lerp(LQuaternion from, LQuaternion to, LFloat t)
 {
     t = LMath.Clamp(t, 0, 1);
     return((1 - t) * from + t * to);
 }
Пример #7
0
    public static LQuaternion RotateTowards(LQuaternion from, LQuaternion to, LFloat maxDegreesDelta)
    {
        LFloat angle = Angle(from, to);

        return(Slerp(from, to, maxDegreesDelta / angle));
    }
Пример #8
0
 public static LFloat Dot(LQuaternion a, LQuaternion b)
 {
     return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
 }
Пример #9
0
    public static LVector3 operator *(LQuaternion rotation, LVector3 point)
    {
        LQuaternion p = rotation * new LQuaternion(point.x, point.y, point.z, 0) * rotation.conjugation;

        return(new LVector3(p.x, p.y, p.z));
    }