Example #1
0
        public static mat4x4 operator *(mat4x4 lhs, mat4x4 rhs)
        {
            mat4x4 res = identity;

            res.m00 = lhs.m00 * rhs.m00 + lhs.m01 * rhs.m10 + lhs.m02 * rhs.m20 + lhs.m03 * rhs.m30;
            res.m01 = lhs.m00 * rhs.m01 + lhs.m01 * rhs.m11 + lhs.m02 * rhs.m21 + lhs.m03 * rhs.m31;
            res.m02 = lhs.m00 * rhs.m02 + lhs.m01 * rhs.m12 + lhs.m02 * rhs.m22 + lhs.m03 * rhs.m32;
            res.m03 = lhs.m00 * rhs.m03 + lhs.m01 * rhs.m13 + lhs.m02 * rhs.m23 + lhs.m03 * rhs.m33;

            res.m10 = lhs.m10 * rhs.m00 + lhs.m11 * rhs.m10 + lhs.m12 * rhs.m20 + lhs.m13 * rhs.m30;
            res.m11 = lhs.m10 * rhs.m01 + lhs.m11 * rhs.m11 + lhs.m12 * rhs.m21 + lhs.m13 * rhs.m31;
            res.m12 = lhs.m10 * rhs.m02 + lhs.m11 * rhs.m12 + lhs.m12 * rhs.m22 + lhs.m13 * rhs.m32;
            res.m13 = lhs.m10 * rhs.m03 + lhs.m11 * rhs.m13 + lhs.m12 * rhs.m23 + lhs.m13 * rhs.m33;

            res.m20 = lhs.m20 * rhs.m00 + lhs.m21 * rhs.m10 + lhs.m22 * rhs.m20 + lhs.m23 * rhs.m30;
            res.m21 = lhs.m20 * rhs.m01 + lhs.m21 * rhs.m11 + lhs.m22 * rhs.m21 + lhs.m23 * rhs.m31;
            res.m22 = lhs.m20 * rhs.m02 + lhs.m21 * rhs.m12 + lhs.m22 * rhs.m22 + lhs.m23 * rhs.m32;
            res.m23 = lhs.m20 * rhs.m03 + lhs.m21 * rhs.m13 + lhs.m22 * rhs.m23 + lhs.m23 * rhs.m33;

            res.m30 = lhs.m30 * rhs.m00 + lhs.m31 * rhs.m10 + lhs.m32 * rhs.m20 + lhs.m33 * rhs.m30;
            res.m31 = lhs.m30 * rhs.m01 + lhs.m31 * rhs.m11 + lhs.m32 * rhs.m21 + lhs.m33 * rhs.m31;
            res.m32 = lhs.m30 * rhs.m02 + lhs.m31 * rhs.m12 + lhs.m32 * rhs.m22 + lhs.m33 * rhs.m32;
            res.m33 = lhs.m30 * rhs.m03 + lhs.m31 * rhs.m13 + lhs.m32 * rhs.m23 + lhs.m33 * rhs.m33;

            return(res);
        }
Example #2
0
        public static mat4x4 SetTranslatePart(Vector3 pos)
        {
            mat4x4 mat = identity;

            mat[0]  = 1; mat[1] = 0; mat[2] = 0; mat[3] = pos.x;
            mat[4]  = 0; mat[5] = 1; mat[6] = 0; mat[7] = pos.y;
            mat[8]  = 0; mat[9] = 0; mat[10] = 1; mat[11] = pos.z;
            mat[12] = 0; mat[13] = 0; mat[14] = 0; mat[15] = 1;

            Debug.Log("Position: " + mat.ToString());

            return(mat);
        }
Example #3
0
        public static mat4x4 SetScalePart(Vector3 scale)
        {
            mat4x4 mat = identity;

            mat[0]  = scale.x; mat[1] = 0; mat[2] = 0; mat[3] = 0;
            mat[4]  = 0; mat[5] = scale.y; mat[6] = 0; mat[7] = 0;
            mat[8]  = 0; mat[9] = 0; mat[10] = scale.z; mat[11] = 0;
            mat[12] = 0; mat[13] = 0; mat[14] = 0; mat[15] = 1;

            Debug.Log("Scale: " + mat.ToString());


            return(mat);
        }
Example #4
0
        public static mat4x4 SetRotatePart(Quaternion rot)
        {
            mat4x4 mat = identity;

            float x = rot.x;
            float y = rot.y;
            float z = rot.z;
            float w = rot.w;

            mat[0]  = 1 - 2 * (y * y + z * z); mat[1] = 2 * (x * y - z * w); mat[2] = 2 * (x * z + y * w); mat[3] = 0;
            mat[4]  = 2 * (x * y + z * w); mat[5] = 1 - 2 * (x * x + z * z); mat[6] = 2 * (y * z - x * w); mat[7] = 0;
            mat[8]  = 2 * (x * z - y * w); mat[9] = 2 * (y * z + x * w); mat[10] = 1 - 2 * (x * x + y * y); mat[11] = 0;
            mat[12] = 0; mat[13] = 0; mat[14] = 0; mat[15] = 1;

            Debug.Log("Rotation: " + mat.ToString());

            return(mat);
        }