当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReaderEx.ReadUInt16方法代码示例

本文整理汇总了C#中BinaryReaderEx.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReaderEx.ReadUInt16方法的具体用法?C# BinaryReaderEx.ReadUInt16怎么用?C# BinaryReaderEx.ReadUInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryReaderEx的用法示例。


在下文中一共展示了BinaryReaderEx.ReadUInt16方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateQuaternionCurve

        private static Curves.QuaternionCurve CreateQuaternionCurve(BinaryReaderEx reader, short count)
        {
            var result = new Curves.QuaternionCurve();

            bool flag = (count & 0x80) != 0;
            int numLengths = count & 0xFF7F;

            var lengths = reader.ReadBytes(numLengths);

            // Lengths section is always a multiple of 4-bytes in length, so advance the stream past the unused bytes
            var unusedBytes = ((numLengths + 3) & 0x7FFFFFFC) - numLengths;

            reader.BaseStream.Position += unusedBytes;

            for (var i = 0; i < numLengths; i++)
            {
                byte len = lengths[i];
                for (var j = 0; j < len; j++)
                {
                    long data = 0;
                    data = (long)reader.ReadUInt16(Endianness.BigEndian) << 32;
                    data |= (long)reader.ReadUInt16(Endianness.BigEndian) << 16;
                    data |= (long)reader.ReadUInt16(Endianness.BigEndian);

                    int index = (int)(data >> 43) & 0x1F; // 5-bit index of this quaternion
                    int signFlags = (int)(data >> 39) & 0x0F; // 4-bit sign Flags
                    int val = (int)(data >> 17) & 0x3FFFFF; // 22-bit integer
                    int wVal = (int)(data & 0x1FFFF); // 17-bit integer

                    int globalIdx = index + 32 * i;

                    float w = (float)wVal / 131071.0f;
                    if (flag)
                    {
                        w = 1 - w * w;
                    }

                    double halfPi = Math.PI * 0.5;

                    double dVal = (double)val;
                    double sqrtVal = Math.Sqrt(dVal);
                    double sqrtValWholePart = Math.Truncate(sqrtVal);

                    double v44 = halfPi * (1 - (sqrtValWholePart / 2047));
                    double tmp = (sqrtValWholePart < 0.001) ? 0 : halfPi * (dVal - sqrtValWholePart * sqrtValWholePart) / (2 * sqrtValWholePart);

                    double tmp6 = Math.Sqrt(1 - w * w);
                    double tX = Math.Sin(-tmp);
                    double tY = Math.Sin(halfPi - tmp);
                    double tZ = Math.Sin(v44);
                    double tW = Math.Sin(v44 - halfPi);

                    float rX = (float)(tY * -tW * tmp6);
                    float rY = (float)(tZ * tmp6);
                    float rZ = (float)(-tX * -tW * tmp6);

                    SlimDX.Quaternion qValue = new SlimDX.Quaternion();
                    if ((signFlags & 0x8) != 0)
                    {
                        signFlags ^= 0xF; // Switch all the bits
                        qValue.W = -w;
                    }
                    else
                    {
                        qValue.W = w;
                    }

                    // Flag Set means Negate
                    qValue.X = ((signFlags & 0x4) != 0) ? -rX : rX;
                    qValue.Y = ((signFlags & 0x2) != 0) ? -rY : rY;
                    qValue.Z = ((signFlags & 0x1) != 0) ? -rZ : rZ;

                    qValue.Normalize();

                    var curveValue = new Curves.QuaternionCurveValue()
                    {
                        Time = (float)globalIdx,
                        Value = qValue
                    };

                    result.Values.Add(curveValue);
                }
            }

            return result;
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:86,代码来源:SpuCurveLoader.cs

示例2: CreateCompressedLinearCurve

        private static Curves.LinearCurve CreateCompressedLinearCurve(BinaryReaderEx reader, AnimatedComponent component, short count)
        {
            var result = new Curves.LinearCurve(component);

            bool flag = (count & 0x8000) != 0;
            int numValues = count & 0x7FFF;
            float offset = reader.ReadSingle(Endianness.BigEndian);
            float scale = reader.ReadSingle(Endianness.BigEndian);
            var lengths = reader.ReadBytes(numValues);
            for (var i = 0; i < numValues; i++)
            {
                var length = lengths[i];
                if (length == 0) { length = 1; }
                var indices = reader.ReadBytes(length);
                if (flag)
                {
                    for (var j = 0; j < length; j++)
                    {
                        ushort sval = reader.ReadUInt16(Endianness.BigEndian);
                        bool isNeg = (sval & 0x8000) != 0;
                        float val = (sval & 0x7FFF) / 32767.0f;
                        if (isNeg) { val = -val; }
                        val = val * scale + offset;

                        Curves.LinearCurveValue curveVal = new Curves.LinearCurveValue()
                        {
                            Time = (float)(indices[j] + 256*i),
                            Value = val
                        };
                        result.Values.Add(curveVal);
                    }
                }
                else
                {
                    for (var j = 0; j < length; j++)
                    {
                        byte sval = reader.ReadByte();
                        bool isNeg = (sval & 0x80) != 0;
                        float val = (sval & 0x7F) / 127.0f;
                        if (isNeg) { val = -val; }
                        val = val * scale + offset;
                        Curves.LinearCurveValue curveVal = new Curves.LinearCurveValue()
                        {
                            Time = (float)(indices[j] + 256 * i),
                            Value = val
                        };
                        result.Values.Add(curveVal);
                    }
                }
            }

            // Align reader position to 4-byte boundary
            reader.BaseStream.Position = (reader.BaseStream.Position + 3) & 0x7FFFFFFFFFFFFFFC;

            return result;
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:56,代码来源:SpuCurveLoader.cs

示例3: LoadSection

        public void LoadSection(BinaryReaderEx reader)
        {
            this.Header = new GtexHeader();
            this.Header.Magic = reader.ReadInt32();
            this.Header.Unknown1 = reader.ReadByte();
            this.Header.Unknown2 = reader.ReadByte();
            this.Header.Format = reader.ReadByte();
            this.Header.MipMapCount = reader.ReadByte();
            this.Header.Unknown3 = reader.ReadByte();
            this.Header.IsCubeMap = reader.ReadByte() == 0x1;
            this.Header.Width = reader.ReadUInt16(Endianness.BigEndian);
            this.Header.Height = reader.ReadUInt16(Endianness.BigEndian);
            this.Header.Depth = reader.ReadInt16(Endianness.BigEndian);
            this.Header.Unknown5 = reader.ReadInt32(Endianness.BigEndian);
            this.Header.DataOffset = reader.ReadUInt32(Endianness.BigEndian);

            if (this.Header.IsCubeMap) { this.NumLayers = 6; }
            else { this.NumLayers = this.Header.MipMapCount; }

            this.LoadMipMapData(reader);
            this.GetDataOffset();
            this.LoadTextureData(reader);
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:23,代码来源:GtexData.cs

示例4: UShortToShort

 private static ushort UShortToShort(BinaryReaderEx src)
 {
     return src.ReadUInt16(Endianness.BigEndian);
 }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:4,代码来源:StreamDecompressors.cs

示例5: UShortToFloat

 private static float UShortToFloat(BinaryReaderEx src)
 {
     ushort val = src.ReadUInt16(Endianness.BigEndian);
     return val / 65535.0f;
 }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:5,代码来源:StreamDecompressors.cs

示例6: HalfToFloat

 private static float HalfToFloat(BinaryReaderEx src)
 {
     ushort val = src.ReadUInt16(Endianness.BigEndian);
     return HalfHelper.HalfToSingle(val);
 }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:5,代码来源:StreamDecompressors.cs


注:本文中的BinaryReaderEx.ReadUInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。