示例#1
0
    public void QuatConjTest()
    {
        Quat       originalOurs  = Quat.FromEuler(12 * Mathf.Deg2Rad, 97 * Mathf.Deg2Rad, 215 * Mathf.Deg2Rad);
        Quaternion originalUnity = UnityUtil.FromQuat(originalOurs);
        Quat       qOurs         = originalOurs.Conjugate();
        Quaternion qUnity        = Quaternion.Inverse(originalUnity);

        TestUtils.AssertQuat(qOurs, qUnity.w, qUnity.x, qUnity.y, qUnity.z);
    }
示例#2
0
        static Vector   RotateAbout(Vector _Point, Vector _Pivot, Quat _Rotation)
        {
            Quat Q            = new Quat(0.0f, _Point - _Pivot);
            Quat RotConjugate = _Rotation;

            RotConjugate.Conjugate();
            Quat   Pr       = QuatMultiply(QuatMultiply(_Rotation, Q), RotConjugate);
            Vector Protated = Pr.qv;

            return(_Pivot + Protated);
        }
示例#3
0
文件: Vec3.cs 项目: niuniuzhu/KOW
        public Vec3 RotateAround(float angle, Vec3 axis)
        {
            // rotate into world space
            Quat quaternion = Quat.AngleAxis(0, axis);

            quaternion = quaternion.Conjugate();
            Vec3 worldSpaceVector = quaternion.Transform(this);

            // rotate back to vector space
            quaternion       = Quat.AngleAxis(angle, axis);
            worldSpaceVector = quaternion.Transform(worldSpaceVector);
            return(worldSpaceVector);
        }
示例#4
0
 public static Quat Conjugate(Quat q)
 {
     return(Quat.Conjugate(q));
 }
示例#5
0
        public void Quat4()
        {
            FQuat fq  = FQuat.Euler(( Fix64 )45, ( Fix64 )(-23), ( Fix64 )(-48.88));
            FQuat fq2 = FQuat.Euler(( Fix64 )23, ( Fix64 )(-78), ( Fix64 )(-132.43f));
            Quat  q   = Quat.Euler(45, -23, -48.88f);
            Quat  q2  = Quat.Euler(23, -78, -132.43f);
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(1, 0, 0);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(1, 0, 0);

            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            this._output.WriteLine(fq2.ToString());
            this._output.WriteLine(q2.ToString());
            Fix64 fa = FQuat.Angle(fq, fq2);
            float a  = Quat.Angle(q, q2);

            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.AngleAxis(( Fix64 )(-123.324), fv);
            q  = Quat.AngleAxis(-123.324f, v);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fa = FQuat.Dot(fq, fq2);
            a  = Quat.Dot(q, q2);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.FromToRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.FromToRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Lerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Lerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Normalize(fq);
            q.Normalize();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.Inverse();
            q = Quat.Inverse(q);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fv = FQuat.Orthogonal(fv);
            v  = Quat.Orthogonal(v);
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = FQuat.Slerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Slerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.LookRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.LookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.ToAngleAxis(out fa, out fv);
            q.ToAngleAxis(out a, out v);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = fq.Conjugate();
            q  = q.Conjugate();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.SetLookRotation(FVec3.Normalize(fv), fv2);
            q.SetLookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
        }