Exemplo n.º 1
0
    public static Quaternion ConvertDegreeToQuaternion(
        ConvertRotation.RotationOrder order,
        float x,
        float y,
        float z)
    {
        Quaternion quaternion1 = Quaternion.AngleAxis(x, Vector3.get_right());
        Quaternion quaternion2 = Quaternion.AngleAxis(y, Vector3.get_up());
        Quaternion quaternion3 = Quaternion.AngleAxis(z, Vector3.get_forward());

        switch (order)
        {
        case ConvertRotation.RotationOrder.xyz:
            return(Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion1, quaternion2), quaternion3));

        case ConvertRotation.RotationOrder.xzy:
            return(Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion1, quaternion3), quaternion2));

        case ConvertRotation.RotationOrder.yxz:
            return(Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion2, quaternion1), quaternion3));

        case ConvertRotation.RotationOrder.yzx:
            return(Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion2, quaternion3), quaternion1));

        case ConvertRotation.RotationOrder.zxy:
            return(Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion3, quaternion1), quaternion2));

        case ConvertRotation.RotationOrder.zyx:
            return(Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion3, quaternion2), quaternion1));

        default:
            return(Quaternion.get_identity());
        }
    }
Exemplo n.º 2
0
    public static Vector3 ConvertRadianFromQuaternionEx(
        ConvertRotation.RotationOrder order,
        Quaternion q)
    {
        switch (order)
        {
        case ConvertRotation.RotationOrder.xyz:
            float[] numArray1 = ConvertRotation.threeaxisrot((float)(-2.0 * (q.y * q.z - q.w * q.x)), (float)(q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z), (float)(2.0 * (q.x * q.z + q.w * q.y)), (float)(-2.0 * (q.x * q.y - q.w * q.z)), (float)(q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
            return(new Vector3(numArray1[2], numArray1[1], numArray1[0]));

        case ConvertRotation.RotationOrder.xzy:
            float[] numArray2 = ConvertRotation.threeaxisrot((float)(2.0 * (q.y * q.z + q.w * q.x)), (float)(q.w * q.w - q.x * q.x + q.y * q.y - q.z * q.z), (float)(-2.0 * (q.x * q.y - q.w * q.z)), (float)(2.0 * (q.x * q.z + q.w * q.y)), (float)(q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
            return(new Vector3(numArray2[2], numArray2[0], numArray2[1]));

        case ConvertRotation.RotationOrder.yxz:
            float[] numArray3 = ConvertRotation.threeaxisrot((float)(2.0 * (q.x * q.z + q.w * q.y)), (float)(q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z), (float)(-2.0 * (q.y * q.z - q.w * q.x)), (float)(2.0 * (q.x * q.y + q.w * q.z)), (float)(q.w * q.w - q.x * q.x + q.y * q.y - q.z * q.z));
            return(new Vector3(numArray3[1], numArray3[2], numArray3[0]));

        case ConvertRotation.RotationOrder.yzx:
            float[] numArray4 = ConvertRotation.threeaxisrot((float)(-2.0 * (q.x * q.z - q.w * q.y)), (float)(q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z), (float)(2.0 * (q.x * q.y + q.w * q.z)), (float)(-2.0 * (q.y * q.z - q.w * q.x)), (float)(q.w * q.w - q.x * q.x + q.y * q.y - q.z * q.z));
            return(new Vector3(numArray4[0], numArray4[2], numArray4[1]));

        case ConvertRotation.RotationOrder.zxy:
            float[] numArray5 = ConvertRotation.threeaxisrot((float)(-2.0 * (q.x * q.y - q.w * q.z)), (float)(q.w * q.w - q.x * q.x + q.y * q.y - q.z * q.z), (float)(2.0 * (q.y * q.z + q.w * q.x)), (float)(-2.0 * (q.x * q.z - q.w * q.y)), (float)(q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
            return(new Vector3(numArray5[1], numArray5[0], numArray5[2]));

        case ConvertRotation.RotationOrder.zyx:
            float[] numArray6 = ConvertRotation.threeaxisrot((float)(2.0 * (q.x * q.y + q.w * q.z)), (float)(q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z), (float)(-2.0 * (q.x * q.z - q.w * q.y)), (float)(2.0 * (q.y * q.z + q.w * q.x)), (float)(q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
            return(new Vector3(numArray6[0], numArray6[1], numArray6[2]));

        default:
            return(Vector3.get_zero());
        }
    }
Exemplo n.º 3
0
    public static Vector3 ConvertRadianFromQuaternion(
        ConvertRotation.RotationOrder order,
        Quaternion q)
    {
        Matrix4x4 m = Matrix4x4.TRS(Vector3.get_zero(), q, Vector3.get_one());

        return(ConvertRotation.ConvertRadianFromMatrix(order, m));
    }
Exemplo n.º 4
0
    public static Vector3 ConvertDegreeFromQuaternion(
        ConvertRotation.RotationOrder order,
        Quaternion q)
    {
        Vector3 vector3 = ConvertRotation.ConvertRadianFromQuaternion(order, q);

        return(new Vector3((float)(vector3.x * 57.2957801818848), (float)(vector3.y * 57.2957801818848), (float)(vector3.z * 57.2957801818848)));
    }
Exemplo n.º 5
0
 public static Quaternion ConvertRadianToQuaternion(
     ConvertRotation.RotationOrder order,
     float x,
     float y,
     float z)
 {
     return(ConvertRotation.ConvertDegreeToQuaternion(order, x * 57.29578f, y * 57.29578f, z * 57.29578f));
 }
Exemplo n.º 6
0
    public static Vector3 ConvertDegreeFromMatrix(
        ConvertRotation.RotationOrder order,
        Matrix4x4 m)
    {
        Vector3 vector3 = ConvertRotation.ConvertRadianFromMatrix(order, m);

        return(new Vector3((float)(vector3.x * 57.2957801818848), (float)(vector3.y * 57.2957801818848), (float)(vector3.z * 57.2957801818848)));
    }
    public void ManualCalc()
    {
        if (Object.op_Equality((Object)null, (Object)this.trfTarget) || Object.op_Equality((Object)null, (Object)this.trfLookAt))
        {
            return;
        }
        Vector3 upVector  = this.GetUpVector();
        Vector3 vector3_1 = Vector3.Normalize(Vector3.op_Subtraction(this.trfTarget.get_position(), this.trfLookAt.get_position()));
        Vector3 vector3_2 = Vector3.Normalize(Vector3.Cross(upVector, vector3_1));
        Vector3 vector3_3 = Vector3.Cross(vector3_1, vector3_2);

        if (this.targetAxisType == H_LookAtDan_Info.AxisType.RevX || this.targetAxisType == H_LookAtDan_Info.AxisType.RevY || this.targetAxisType == H_LookAtDan_Info.AxisType.RevZ)
        {
            vector3_1 = Vector3.op_UnaryNegation(vector3_1);
            vector3_2 = Vector3.op_UnaryNegation(vector3_2);
        }
        Vector3 xvec = Vector3.get_zero();
        Vector3 yvec = Vector3.get_zero();
        Vector3 zvec = Vector3.get_zero();

        switch (this.targetAxisType)
        {
        case H_LookAtDan_Info.AxisType.X:
        case H_LookAtDan_Info.AxisType.RevX:
            xvec = vector3_1;
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.Y)
            {
                yvec = vector3_3;
                zvec = Vector3.op_UnaryNegation(vector3_2);
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.RevY)
            {
                yvec = Vector3.op_UnaryNegation(vector3_3);
                zvec = vector3_2;
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.Z)
            {
                yvec = vector3_2;
                zvec = vector3_3;
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.RevZ)
            {
                yvec = Vector3.op_UnaryNegation(vector3_2);
                zvec = Vector3.op_UnaryNegation(vector3_3);
                break;
            }
            break;

        case H_LookAtDan_Info.AxisType.Y:
        case H_LookAtDan_Info.AxisType.RevY:
            yvec = vector3_1;
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.X)
            {
                xvec = vector3_3;
                zvec = vector3_2;
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.RevX)
            {
                xvec = Vector3.op_UnaryNegation(vector3_3);
                zvec = Vector3.op_UnaryNegation(vector3_2);
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.Z)
            {
                xvec = Vector3.op_UnaryNegation(vector3_2);
                zvec = vector3_3;
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.RevZ)
            {
                xvec = vector3_2;
                zvec = Vector3.op_UnaryNegation(vector3_3);
                break;
            }
            break;

        case H_LookAtDan_Info.AxisType.Z:
        case H_LookAtDan_Info.AxisType.RevZ:
            zvec = vector3_1;
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.X)
            {
                xvec = vector3_3;
                yvec = Vector3.op_UnaryNegation(vector3_2);
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.RevX)
            {
                xvec = Vector3.op_UnaryNegation(vector3_3);
                yvec = vector3_2;
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.Y)
            {
                xvec = vector3_2;
                yvec = vector3_3;
                break;
            }
            if (this.sourceAxisType == H_LookAtDan_Info.AxisType.RevY)
            {
                xvec = Vector3.op_UnaryNegation(vector3_2);
                yvec = Vector3.op_UnaryNegation(vector3_3);
                break;
            }
            break;
        }
        if (this.limitAxisType == H_LookAtDan_Info.AxisType.None)
        {
            Quaternion q = (Quaternion)null;
            if (this.LookAtQuat(xvec, yvec, zvec, ref q))
            {
                this.trfLookAt.set_rotation(q);
            }
            else
            {
                this.trfLookAt.set_rotation(this.oldRotation);
            }
            this.oldRotation = this.trfLookAt.get_rotation();
        }
        else
        {
            Quaternion q1 = (Quaternion)null;
            if (this.LookAtQuat(xvec, yvec, zvec, ref q1))
            {
                this.trfLookAt.set_rotation(q1);
            }
            else
            {
                this.trfLookAt.set_rotation(this.oldRotation);
            }
            ConvertRotation.RotationOrder rotOrder = (ConvertRotation.RotationOrder) this.rotOrder;
            Quaternion localRotation = this.trfLookAt.get_localRotation();
            Vector3    vector3_4     = ConvertRotation.ConvertDegreeFromQuaternion(rotOrder, localRotation);
            Quaternion q2            = Quaternion.Slerp(localRotation, Quaternion.get_identity(), 0.5f);
            Vector3    vector3_5     = ConvertRotation.ConvertDegreeFromQuaternion(rotOrder, q2);
            if (this.limitAxisType == H_LookAtDan_Info.AxisType.X)
            {
                if (vector3_4.x < 0.0 && vector3_5.x > 0.0 || vector3_4.x > 0.0 && vector3_5.x < 0.0)
                {
                    ref Vector3 local = ref vector3_4;
                    local.x = (__Null)(local.x * -1.0);
                }
                vector3_4.x = (__Null)(double)Mathf.Clamp((float)vector3_4.x, this.limitMin, this.limitMax);
            }
Exemplo n.º 8
0
    public static Vector3 ConvertRadianFromMatrix(
        ConvertRotation.RotationOrder order,
        Matrix4x4 m)
    {
        switch (order)
        {
        case ConvertRotation.RotationOrder.xyz:
            float m02  = (float)m.m02;
            float num1 = Mathf.Asin(Mathf.Clamp(m02, -1f, 1f));
            float val1;
            float val2;
            if ((double)m02 > 0.999899983406067)
            {
                val1 = 0.0f;
                val2 = Mathf.Atan2((float)m.m21, (float)m.m11);
                ConvertRotation.CheckNaN(ref val2, 0.0f);
            }
            else
            {
                val2 = Mathf.Atan2((float)-m.m12, (float)m.m22);
                ConvertRotation.CheckNaN(ref val2, 0.0f);
                val1 = Mathf.Atan2((float)-m.m01, (float)m.m00);
                ConvertRotation.CheckNaN(ref val1, 0.0f);
            }
            return(new Vector3(val2, num1, val1));

        case ConvertRotation.RotationOrder.xzy:
            float num2 = (float)-m.m01;
            float num3 = Mathf.Asin(Mathf.Clamp(num2, -1f, 1f));
            float val3;
            float val4;
            if ((double)num2 > 0.999899983406067)
            {
                val3 = 0.0f;
                val4 = Mathf.Atan2((float)-m.m12, (float)m.m22);
                ConvertRotation.CheckNaN(ref val4, 0.0f);
            }
            else
            {
                val4 = Mathf.Atan2((float)m.m21, (float)m.m11);
                ConvertRotation.CheckNaN(ref val4, 0.0f);
                val3 = Mathf.Atan2((float)m.m02, (float)m.m00);
                ConvertRotation.CheckNaN(ref val3, 0.0f);
            }
            return(new Vector3(val4, val3, num3));

        case ConvertRotation.RotationOrder.yxz:
            float num4 = (float)-m.m12;
            float num5 = Mathf.Asin(Mathf.Clamp(num4, -1f, 1f));
            float val5;
            float val6;
            if ((double)num4 > 0.999899983406067)
            {
                val5 = 0.0f;
                val6 = Mathf.Atan2((float)-m.m20, (float)m.m00);
                ConvertRotation.CheckNaN(ref val6, 0.0f);
            }
            else
            {
                val6 = Mathf.Atan2((float)m.m02, (float)m.m22);
                ConvertRotation.CheckNaN(ref val6, 0.0f);
                val5 = Mathf.Atan2((float)m.m10, (float)m.m11);
                ConvertRotation.CheckNaN(ref val5, 0.0f);
            }
            return(new Vector3(num5, val6, val5));

        case ConvertRotation.RotationOrder.yzx:
            float m10  = (float)m.m10;
            float num6 = Mathf.Asin(Mathf.Clamp(m10, -1f, 1f));
            float val7;
            float val8;
            if ((double)m10 > 0.999899983406067)
            {
                val7 = 0.0f;
                val8 = Mathf.Atan2((float)m.m02, (float)m.m22);
                ConvertRotation.CheckNaN(ref val8, 0.0f);
            }
            else
            {
                val7 = Mathf.Atan2((float)-m.m12, (float)m.m11);
                ConvertRotation.CheckNaN(ref val7, 0.0f);
                val8 = Mathf.Atan2((float)-m.m20, (float)m.m00);
                ConvertRotation.CheckNaN(ref val8, 0.0f);
            }
            return(new Vector3(val7, val8, num6));

        case ConvertRotation.RotationOrder.zxy:
            float m21  = (float)m.m21;
            float num7 = Mathf.Asin(Mathf.Clamp(m21, -1f, 1f));
            float val9;
            float val10;
            if ((double)m21 > 0.999899983406067)
            {
                val9  = 0.0f;
                val10 = Mathf.Atan2((float)m.m10, (float)m.m00);
                ConvertRotation.CheckNaN(ref val10, 0.0f);
            }
            else
            {
                val9 = Mathf.Atan2((float)-m.m20, (float)m.m22);
                ConvertRotation.CheckNaN(ref val9, 0.0f);
                val10 = Mathf.Atan2((float)-m.m01, (float)m.m11);
                ConvertRotation.CheckNaN(ref val10, 0.0f);
            }
            return(new Vector3(num7, val9, val10));

        case ConvertRotation.RotationOrder.zyx:
            float num8 = (float)-m.m20;
            float num9 = Mathf.Asin(Mathf.Clamp(num8, -1f, 1f));
            float val11;
            float val12;
            if ((double)num8 > 0.999899983406067)
            {
                val11 = 0.0f;
                val12 = Mathf.Atan2((float)-m.m01, (float)m.m11);
                ConvertRotation.CheckNaN(ref val12, 0.0f);
            }
            else
            {
                val11 = Mathf.Atan2((float)m.m21, (float)m.m22);
                ConvertRotation.CheckNaN(ref val11, 0.0f);
                val12 = Mathf.Atan2((float)m.m10, (float)m.m00);
                ConvertRotation.CheckNaN(ref val12, 0.0f);
            }
            return(new Vector3(val11, num9, val12));

        default:
            return(Vector3.get_zero());
        }
    }