コード例 #1
0
ファイル: MBN.cs プロジェクト: testingwalker/Ohana3DS-Rebirth
        /// <summary>
        ///     Reads a quantized Vector4 from the Vertex Stream.
        ///     It is usually used to store Vertex Color.
        /// </summary>
        /// <param name="buffer">The Vertex Stream buffer</param>
        /// <param name="pos">Position to read from the buffer</param>
        /// <param name="q">Quantization of the data</param>
        /// <param name="scale">Scale of the vector</param>
        /// <returns></returns>
        private static RenderBase.OVector4 getVector4(byte[] buffer, int pos, vtxAttributeQuantization q, float scale)
        {
            switch (q)
            {
            case vtxAttributeQuantization.single:
                return(new RenderBase.OVector4(
                           BitConverter.ToSingle(buffer, pos) * scale,
                           BitConverter.ToSingle(buffer, pos + 4) * scale,
                           BitConverter.ToSingle(buffer, pos + 8) * scale,
                           BitConverter.ToSingle(buffer, pos + 12) * scale));

            case vtxAttributeQuantization.unsignedByte:
                return(new RenderBase.OVector4(
                           buffer[pos] * scale,
                           buffer[pos + 1] * scale,
                           buffer[pos + 2] * scale,
                           buffer[pos + 3] * scale));

            case vtxAttributeQuantization.signedByte:
                return(new RenderBase.OVector4(
                           (sbyte)buffer[pos] * scale,
                           (sbyte)buffer[pos + 1] * scale,
                           (sbyte)buffer[pos + 2] * scale,
                           (sbyte)buffer[pos + 3] * scale));

            case vtxAttributeQuantization.signedShort:
                return(new RenderBase.OVector4(
                           BitConverter.ToInt16(buffer, pos) * scale,
                           BitConverter.ToInt16(buffer, pos + 2) * scale,
                           BitConverter.ToInt16(buffer, pos + 4) * scale,
                           BitConverter.ToInt16(buffer, pos + 6) * scale));
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        ///     Reads a quantized Vector4 from the Vertex Stream.
        ///     It is usually used to store Vertex Color.
        /// </summary>
        /// <param name="buffer">The Vertex Stream buffer</param>
        /// <param name="pos">Position to read from the buffer</param>
        /// <param name="q">Quantization of the data</param>
        /// <param name="scale">Scale of the vector</param>
        /// <returns></returns>
        private static RenderBase.OVector4 getVector4(byte[] buffer, int pos, vtxAttributeQuantization q, float scale)
        {
            switch (q)
            {
                case vtxAttributeQuantization.single:
                    return new RenderBase.OVector4(
                        BitConverter.ToSingle(buffer, pos) * scale,
                        BitConverter.ToSingle(buffer, pos + 4) * scale,
                        BitConverter.ToSingle(buffer, pos + 8) * scale,
                        BitConverter.ToSingle(buffer, pos + 12) * scale);
                case vtxAttributeQuantization.unsignedByte:
                    return new RenderBase.OVector4(
                        buffer[pos] * scale,
                        buffer[pos + 1] * scale,
                        buffer[pos + 2] * scale,
                        buffer[pos + 3] * scale);
                case vtxAttributeQuantization.signedByte:
                    return new RenderBase.OVector4(
                        (sbyte)buffer[pos] * scale,
                        (sbyte)buffer[pos + 1] * scale,
                        (sbyte)buffer[pos + 2] * scale,
                        (sbyte)buffer[pos + 3] * scale);
                case vtxAttributeQuantization.signedShort:
                    return new RenderBase.OVector4(
                        BitConverter.ToInt16(buffer, pos) * scale,
                        BitConverter.ToInt16(buffer, pos + 2) * scale,
                        BitConverter.ToInt16(buffer, pos + 4) * scale,
                        BitConverter.ToInt16(buffer, pos + 6) * scale);
            }

            return null;
        }