Example #1
0
        public Angles(zMat4 matrix)
        {
            Vec3f right = new Vec3f(matrix[0], matrix[8], matrix[4]).Normalise();
            Vec3f up    = new Vec3f(matrix[1], matrix[9], matrix[5]).Normalise();
            Vec3f at    = new Vec3f(matrix[2], matrix[10], matrix[6]).Normalise();

            Pitch = -(float)Math.Atan2(up.Z, at.Z) + PI / 2; // +PI/2 so the default value is 0 and not -90
            Pitch = ClampToPI(Pitch);

            Yaw  = (float)Math.Atan2(right.Y, right.X);
            Roll = -(float)Math.Asin(right.Z);

            /*const float oneminusepsilon = 0.99999f;
             * if (right.Z < -oneminusepsilon)
             * { // singularity
             *  Roll = PI / 2f;
             *  Yaw = 0;
             *  Pitch = (float)Math.Atan2(up.X, at.X);
             * }
             * else if (right.Z > oneminusepsilon)
             * { // singularity
             *  Roll = -PI / 2f;
             *  Yaw = 0;
             *  Pitch = (float)Math.Atan2(-up.X, -at.X);
             * }
             * else
             * {
             *  Roll = -(float)Math.Asin(right.Z);
             *  float c = (float)Math.Cos(Roll);
             *
             *  Yaw = (float)Math.Atan2(right.Y / c, right.X / c);
             *  Pitch = -(float)Math.Atan2(up.Z / c, at.Z / c) + PI/2; // +PI/2 so the default is 0 and not 90
             * }*/
        }
Example #2
0
        public void SetMatrix(zMat4 matrix)
        {
            float rollSin = (float)Math.Sin(Roll);
            float rollCos = (float)Math.Cos(Roll);

            float yawSin = (float)Math.Sin(Yaw);
            float yawCos = (float)Math.Cos(Yaw);

            float pitchSin = -(float)Math.Cos(Pitch); // (float)Math.Sin(Pitch - PI/2); // -PI/2 so the default value can be 0 and not -90
            float pitchCos = (float)Math.Sin(Pitch);  // (float)Math.Cos(Pitch - PI/2);

            matrix[0] = rollCos * yawCos;
            matrix[8] = rollCos * yawSin;
            matrix[4] = -rollSin;

            matrix[1] = -pitchSin * rollSin * yawCos + pitchCos * yawSin;
            matrix[9] = -pitchSin * rollSin * yawSin - pitchCos * yawCos;
            matrix[5] = -pitchSin * rollCos;

            matrix[2]  = pitchCos * rollSin * yawCos + pitchSin * yawSin;
            matrix[10] = pitchCos * rollSin * yawSin - pitchSin * yawCos;
            matrix[6]  = pitchCos * rollCos;
        }
Example #3
0
 public void GetTrafoNodeToModel(int nodePtr, zMat4 matrix)
 {
     Process.THISCALL <NullReturnCall>(Address, 0x57A9C0, matrix, (IntArg)nodePtr);
 }
Example #4
0
 public void Init(zCVob self, zCVob owner, zVec3 start, float angle, float force, zMat4 trafo)
 {
     Process.THISCALL <NullReturnCall>(Address, 0x69F540, self, owner, start, (FloatArg)angle, (FloatArg)force, trafo);
 }
Example #5
0
 public static Angles FromMatrix(zMat4 matrix)
 {
     return(new Angles(matrix));
 }
Example #6
0
 public void GetTrafoModelNodeToWorld(zString nodeName, zMat4 matrix)
 {
     Process.THISCALL <NullReturnCall>(Address, 0x604960, matrix, nodeName);
 }