MineViewer.SMPInterface.SwapByteOrder C# (CSharp) Method

SwapByteOrder() public static method

public static SwapByteOrder ( double val ) : double
val double
return double
        public static double SwapByteOrder(double val)
        {
            byte[] old = BitConverter.GetBytes(val);
            byte[] v = new byte[8]
            {
                old[7],
                old[6],
                old[5],
                old[4],
                old[3],
                old[2],
                old[1],
                old[0],
            };
            return BitConverter.ToDouble(v, 0);
        }

Same methods

SMPInterface::SwapByteOrder ( int val ) : int
SMPInterface::SwapByteOrder ( short val ) : short

Usage Example

Esempio n. 1
0
        private void tmrSpin_Tick(object sender, EventArgs e)
        {
            float movement = 11;

            rotation = (rotation + movement) % 360f;

            if (rotation % 2 == 0)
            {
                PacketHandler h = SMPInterface.Handler;
                h.SetOperationCode(SMPInterface.PacketTypes.PlayerPosition);

                double x = SMPInterface.PlayerX;
                double y = 126.0;
                double z = SMPInterface.PlayerZ;

                x += Math.Cos((rotation / 1.0) * Math.PI * 2.0) * 10.0;
                z += Math.Sin((rotation / 1.0) * Math.PI * 2.0) * 10.0;

                h.Write(SMPInterface.SwapByteOrder(x));
                h.Write(SMPInterface.SwapByteOrder(y));
                h.Write(SMPInterface.SwapByteOrder(y + 0.5));
                h.Write(SMPInterface.SwapByteOrder(z));
                h.Write(false);
                h.Flush();
            }
            else
            {
                float         x = rotation;
                float         y = 0f; // horizontal?
                PacketHandler h = SMPInterface.Handler;
                h.SetOperationCode(SMPInterface.PacketTypes.PlayerLook);
                h.Write(SMPInterface.SwapByteOrder(x));
                h.Write(SMPInterface.SwapByteOrder(y));
                h.Write(false);
                h.Flush();
            }
        }