예제 #1
0
        /// <summary>
        /// Compress a Normalized float. For bit-based settings, you must supply floats in the range of 0 to 1.
        /// Values outside of that range will produce a looping modulus behaviour.
        /// </summary>
        /// <returns>Returns the compressed value as a uint, with an out bits value for convenience with bitpacking.</returns>
        public static uint CompressNorm(this float value, int bits)
        {
            switch (bits)
            {
            case 0:
                return((uint)0);

            case 1:
                return((uint)value);

            case 2:
                return((uint)(value * NORM_COMP_ENCODE2));

            case 3:
                return((uint)(value * NORM_COMP_ENCODE3));

            case 4:
                return((uint)(value * NORM_COMP_ENCODE4));

            case 5:
                return((uint)(value * NORM_COMP_ENCODE5));

            case 6:
                return((uint)(value * NORM_COMP_ENCODE6));

            case 7:
                return((uint)(value * NORM_COMP_ENCODE7));

            case 8:
                return((uint)(value * NORM_COMP_ENCODE8));

            case 9:
                return((uint)(value * NORM_COMP_ENCODE9));

            case 10:
                return((uint)(value * NORM_COMP_ENCODE10));

            case 11:
                return((uint)(value * NORM_COMP_ENCODE11));

            case 12:
                return((uint)(value * NORM_COMP_ENCODE12));

            case 13:
                return((uint)(value * NORM_COMP_ENCODE13));

            case 14:
                return((uint)(value * NORM_COMP_ENCODE14));

            case 15:
                return((uint)(value * NORM_COMP_ENCODE15));

            case 16:
                return(HalfUtilities.Pack(value));

            default:
                return((ByteConverter)value);
            }
        }
예제 #2
0
        public void Pack(Network.ByteOutStream stream)
        {
            Vector3    p;
            Quaternion r;
            byte       angle = 0;

            if (Actor.Context.IsServer)
            {
                p = position;
                r = rotation;

                if (yawOnly)
                {
                    angle = (byte)(yaw * 0.71111f);
                }
            }
            else
            {
                p = Actor.Transform.Position;
                r = Actor.Transform.Rotation;

                if (yawOnly)
                {
                    angle = (byte)(Vector3.SignedAngle(Vector3.Forward, Actor.Transform.Forward, Vector3.Up) * 0.71111f);
                }
            }

            if (compressPosition)
            {
                stream.WriteUShort(HalfUtilities.Pack(p.X));
                stream.WriteUShort(HalfUtilities.Pack(p.Y));
                stream.WriteUShort(HalfUtilities.Pack(p.Z));
            }
            else
            {
                stream.WriteVector3(p);
            }

            if (yawOnly)
            {
                stream.WriteByte(angle);
            }
            else
            {
                p = r.Axis;
                stream.WriteUShort(HalfUtilities.Pack(p.X));
                stream.WriteUShort(HalfUtilities.Pack(p.Y));
                stream.WriteUShort(HalfUtilities.Pack(p.Z));
                stream.WriteByte((byte)(r.Angle * SlimMath.Single.Rad2Deg * 0.71111f));
            }
        }
예제 #3
0
        /// <summary>
        /// Compress and Write a Normalized float. For bit-based settings, you must supply floats in the range of 0 to 1.
        /// Values outside of that range will produce a looping modulus behaviour.
        /// </summary>
        /// <returns>Returns the compressed value as a uint.</returns>
        public static uint WriteNorm(this byte[] buffer, float value, ref int bitposition, int bits)
        {
            uint cval;

            switch (bits)
            {
            case 0:
                cval = 0;
                break;

            case 1:
                cval = (uint)value;
                break;

            case 2:
                cval = (uint)(value * NORM_COMP_ENCODE2);
                break;

            case 3:
                cval = (uint)(value * NORM_COMP_ENCODE3);
                break;

            case 4:
                cval = (uint)(value * NORM_COMP_ENCODE4);
                break;

            case 5:
                cval = (uint)(value * NORM_COMP_ENCODE5);
                break;

            case 6:
                cval = (uint)(value * NORM_COMP_ENCODE6);
                break;

            case 7:
                cval = (uint)(value * NORM_COMP_ENCODE7);
                break;

            case 8:
                cval = (uint)(value * NORM_COMP_ENCODE8);
                break;

            case 9:
                cval = (uint)(value * NORM_COMP_ENCODE9);
                break;

            case 10:
                cval = (uint)(value * NORM_COMP_ENCODE10);
                break;

            case 11:
                cval = (uint)(value * NORM_COMP_ENCODE11);
                break;

            case 12:
                cval = (uint)(value * NORM_COMP_ENCODE12);
                break;

            case 13:
                cval = (uint)(value * NORM_COMP_ENCODE13);
                break;

            case 14:
                cval = (uint)(value * NORM_COMP_ENCODE14);
                break;

            case 15:
                cval = (uint)(value * NORM_COMP_ENCODE15);
                break;

            case 16:
                cval = HalfUtilities.Pack(value);
                break;

            default:
                cval = (ByteConverter)value;
                break;
            }

            buffer.Write(cval, ref bitposition, bits);
            return(cval);
        }
예제 #4
0
 public static void AppendHalf(this byte[] buffer, float value, ref int bitposition)
 {
     buffer.Append(HalfUtilities.Pack(value), ref bitposition, 16);
 }