Пример #1
0
 /// <summary>
 /// Returns a 16-byte set representation of this color.
 /// Inverts <see cref="FromBytes(byte[], int)"/>.
 /// </summary>
 /// <param name="outputBytes">The output byte array.</param>
 /// <param name="offset">The starting offset in the output array.</param>
 public void ToBytes(byte[] outputBytes, int offset)
 {
     PrimitiveConversionHelper.Float32ToBytes(R, outputBytes, offset);
     PrimitiveConversionHelper.Float32ToBytes(G, outputBytes, offset + 4);
     PrimitiveConversionHelper.Float32ToBytes(B, outputBytes, offset + (4 + 4));
     PrimitiveConversionHelper.Float32ToBytes(A, outputBytes, offset + (4 + 4 + 4));
 }
Пример #2
0
 /// <summary>
 /// Converts a 12-byte set to a color.
 /// Inverts <see cref="ToBytes(byte[], int)"/>.
 /// </summary>
 /// <param name="b">The byte input.</param>
 /// <param name="offset">The offset in the byte array.</param>
 /// <returns>The color.</returns>
 public static Color3F FromBytes(byte[] b, int offset = 0)
 {
     return(new Color3F(
                PrimitiveConversionHelper.BytesToFloat32(b, offset),
                PrimitiveConversionHelper.BytesToFloat32(b, offset + 4),
                PrimitiveConversionHelper.BytesToFloat32(b, offset + (4 + 4))
                ));
 }
 public static void TestBits()
 {
     if (!BitConverter.IsLittleEndian)
     {
         Assert.Fail("BitConverter identifies this system as big endian, which is not currently supported by the engine!");
     }
     else
     {
         byte[] bI = PrimitiveConversionHelper.Int32ToBytes(1 + 512);
         Assert.That(bI.Length == 4, "Bit length (int->bytes)");
         Assert.That(bI[0] == 1, "Bit contents (int->bytes)[0]");
         Assert.That(bI[1] == 2, "Bit contents (int->bytes)[1]");
         Assert.That(bI[2] == 0, "Bit contents (int->bytes)[2]");
         Assert.That(bI[3] == 0, "Bit contents (int->bytes)[3]");
         byte[] bF = PrimitiveConversionHelper.Float32ToBytes(127.125f);
         Assert.That(bF.Length == 4, "Bit length (float->bytes)");
         Assert.That(bF[0] == 0, "Bit contents (float->bytes)[0]");
         Assert.That(bF[1] == 64, "Bit contents (float->bytes)[1]");
         Assert.That(bF[2] == 254, "Bit contents (float->bytes)[2]");
         Assert.That(bF[3] == 66, "Bit contents (float->bytes)[3]");
         Assert.That(PrimitiveConversionHelper.BytesToDouble64(PrimitiveConversionHelper.Double64ToBytes(1.73e5)) == 1.73e5, "Double parseback validity");
     }
 }
Пример #4
0
 /// <summary>
 /// Write an unsigned long integer (8 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteULong(ulong x)
 {
     PrimitiveConversionHelper.ULong64ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 8);
 }
Пример #5
0
 /// <summary>
 /// Write a double (8 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteDouble(double x)
 {
     PrimitiveConversionHelper.Double64ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 8);
 }
Пример #6
0
 /// <summary>
 /// Write a float (4 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteFloat(float x)
 {
     PrimitiveConversionHelper.Float32ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 4);
 }
Пример #7
0
 /// <summary>
 /// Write an unsigned integer (4 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteUInt(uint x)
 {
     PrimitiveConversionHelper.UInt32ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 4);
 }
Пример #8
0
 /// <summary>
 /// Write an unsigned short integer (2 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteUShort(ushort x)
 {
     PrimitiveConversionHelper.UShort16ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 2);
 }
Пример #9
0
 /// <summary>
 /// Read a double (8 bytes).
 /// </summary>
 public double ReadDouble()
 {
     ReadBytes(HelperBytes, 0, 8);
     return(PrimitiveConversionHelper.BytesToDouble64(HelperBytes));
 }
Пример #10
0
 /// <summary>
 /// Read a float (4 bytes).
 /// </summary>
 public float ReadFloat()
 {
     ReadBytes(HelperBytes, 0, 4);
     return(PrimitiveConversionHelper.BytesToFloat32(HelperBytes));
 }
Пример #11
0
 /// <summary>
 /// Read an unsigned long integer (8 bytes).
 /// </summary>
 public ulong ReadULong()
 {
     ReadBytes(HelperBytes, 0, 8);
     return(PrimitiveConversionHelper.BytesToULong64(HelperBytes));
 }
Пример #12
0
 /// <summary>
 /// Read an unsigned integer (4 bytes).
 /// </summary>
 public uint ReadUInt()
 {
     ReadBytes(HelperBytes, 0, 4);
     return(PrimitiveConversionHelper.BytesToUInt32(HelperBytes));
 }
Пример #13
0
 /// <summary>
 /// Read an unsigned short integer (2 bytes).
 /// </summary>
 public ushort ReadUShort()
 {
     ReadBytes(HelperBytes, 0, 2);
     return(PrimitiveConversionHelper.BytesToUShort16(HelperBytes));
 }
Пример #14
0
 /// <summary>
 /// Read a character (2 bytes).
 /// </summary>
 /// <returns></returns>
 public char ReadChar()
 {
     ReadBytes(HelperBytes, 0, 2);
     return((char)PrimitiveConversionHelper.BytesToUShort16(HelperBytes));
 }