コード例 #1
0
        public static AnimQuaternion Read(EndianBinaryReader reader)
        {
            AnimQuaternion qua = new AnimQuaternion();
            float          x   = (float)reader.ReadInt16() / (float)Int16.MaxValue;
            float          y   = (float)reader.ReadInt16() / (float)Int16.MaxValue;
            float          z   = (float)reader.ReadInt16() / (float)Int16.MaxValue;
            float          w   = (float)reader.ReadInt16() / (float)Int16.MaxValue;

            qua.quaternion = new Quaternion(x, y, z, w);
            qua.ConvertRotation();
            return(qua);
        }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: cualquiercosa327/raymap
        public static Matrix ReadCompressed(Reader reader, Pointer offset)
        {
            MapLoader  l = MapLoader.Loader;
            ushort     type = reader.ReadUInt16();
            Vector4    vec = new Vector4(1f, 1f, 1f, 1f);
            Vector3?   pos = null;
            Quaternion?rot = null;
            Matrix4x4? sclM = null;
            float      x, y, z, w;

            /*the first byte & 0xF is the type
             * 1: translation
             * 2: rotation only
             * 3: translation & rotation
             * 7: translation, rotation, zoom (1 word, conv to float). zoom is basically scale for all axes
             * 11: translation, rotation, scale per axis (3 words, conv to float)
             * 15: translation, rotation, scale (6 words, conv to float)*/
            int actualType = type < 128 ? (type & 0xF) : 128;

            if (actualType == 1 || actualType == 3 || actualType == 7 || actualType == 11 || actualType == 15)
            {
                // Translation
                x   = (float)reader.ReadInt16() / (float)512;
                y   = (float)reader.ReadInt16() / (float)512;
                z   = (float)reader.ReadInt16() / (float)512;
                pos = new Vector3(x, y, z);
            }
            if (actualType == 2 || actualType == 3 || actualType == 7 || actualType == 11 || actualType == 15)
            {
                // Rotation
                w = (float)reader.ReadInt16() / (float)Int16.MaxValue;
                x = (float)reader.ReadInt16() / (float)Int16.MaxValue;
                y = (float)reader.ReadInt16() / (float)Int16.MaxValue;
                z = (float)reader.ReadInt16() / (float)Int16.MaxValue;
                //rot = new Quaternion(x, y, z, w);
                //rot = Quaternion.Euler(rot.Value.eulerAngles);
                Animation.Component.AnimQuaternion q = new Animation.Component.AnimQuaternion();
                q.quaternion = new Quaternion(x, y, z, w);
                Matrix rotM = q.ToMatrix();
                rot = rotM.GetRotation(convertAxes: false);
            }
            if (actualType == 7)
            {
                // Zoom scale
                x    = (float)reader.ReadInt16() / (float)256;
                sclM = Matrix4x4.Scale(new Vector3(x, x, x));
            }
            else if (actualType == 11)
            {
                // Axial scale
                x    = (float)reader.ReadInt16() / (float)256;
                y    = (float)reader.ReadInt16() / (float)256;
                z    = (float)reader.ReadInt16() / (float)256;
                sclM = Matrix4x4.Scale(new Vector3(x, y, z));
            }
            else if (actualType == 15)
            {
                // Matrix scale
                float m0 = (float)reader.ReadInt16() / (float)256;
                float m1 = (float)reader.ReadInt16() / (float)256;
                float m2 = (float)reader.ReadInt16() / (float)256;
                float m3 = (float)reader.ReadInt16() / (float)256;
                float m4 = (float)reader.ReadInt16() / (float)256;
                float m5 = (float)reader.ReadInt16() / (float)256;
                // Actually it should be like this, but oh well:

                /*sclM = new Matrix4x4();
                 * sclM.Value.SetColumn(0, new Vector4(m0, m1, m2, 0f));
                 * sclM.Value.SetColumn(1, new Vector4(m1, m3, m4, 0f));
                 * sclM.Value.SetColumn(2, new Vector4(m2, m4, m5, 0f));
                 * sclM.Value.SetColumn(3, new Vector4(0f, 0f, 0f, 1f));*/
                sclM = Matrix4x4.Scale(new Vector3(m0, m3, m5));
            }
            if (!pos.HasValue)
            {
                pos = Vector3.zero;
            }
            if (!rot.HasValue)
            {
                rot = Quaternion.identity;
            }
            Matrix mat = new Matrix(offset, type, Matrix4x4.TRS(pos.Value, rot.Value, Vector3.one), vec);

            if (sclM.HasValue)
            {
                mat.SetScaleMatrix(sclM.Value);
            }
            return(mat);
        }