Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StructLayout(LayoutKind.Sequential)]
- public struct DefaultMaterialProperties
- {
- public Vector3 AmbientColor;
- public Vector3 DiffuseColor;
- public Vector3 SpecularColor;
- public unsafe static implicit operator byte[] (DefaultMaterialProperties data)
- {
- var myBuffer = new byte[3 * 4 * sizeof(float)];
- fixed (byte* ptr = myBuffer)
- {
- // Ambient color
- *((byte*)(ptr + 0)) = (byte)((UInt32)data.AmbientColor.X & 0xff000000 >> 24);
- *((byte*)(ptr + 1)) = (byte)((UInt32)data.AmbientColor.X & 0x00ff0000 >> 16);
- *((byte*)(ptr + 2)) = (byte)((UInt32)data.AmbientColor.X & 0x0000ff00 >> 8);
- *((byte*)(ptr + 3)) = (byte)((UInt32)data.AmbientColor.X & 0x000000ff >> 0);
- *((byte*)(ptr + 4)) = (byte)((UInt32)data.AmbientColor.Y & 0xff000000 >> 24);
- *((byte*)(ptr + 5)) = (byte)((UInt32)data.AmbientColor.Y & 0x00ff0000 >> 16);
- *((byte*)(ptr + 6)) = (byte)((UInt32)data.AmbientColor.Y & 0x0000ff00 >> 8);
- *((byte*)(ptr + 7)) = (byte)((UInt32)data.AmbientColor.Y & 0x000000ff >> 0);
- *((byte*)(ptr + 8)) = (byte)((UInt32)data.AmbientColor.Z & 0xff000000 >> 24);
- *((byte*)(ptr + 9)) = (byte)((UInt32)data.AmbientColor.Z & 0x00ff0000 >> 16);
- *((byte*)(ptr + 10)) = (byte)((UInt32)data.AmbientColor.Z & 0x0000ff00 >> 8);
- *((byte*)(ptr + 11)) = (byte)((UInt32)data.AmbientColor.Z & 0x000000ff >> 0);
- // Diffuse color
- *((byte*)(ptr + 16)) = (byte)((UInt32)data.DiffuseColor.X & 0xff000000 >> 24);
- *((byte*)(ptr + 17)) = (byte)((UInt32)data.DiffuseColor.X & 0x00ff0000 >> 16);
- *((byte*)(ptr + 18)) = (byte)((UInt32)data.DiffuseColor.X & 0x0000ff00 >> 8);
- *((byte*)(ptr + 19)) = (byte)((UInt32)data.DiffuseColor.X & 0x000000ff >> 0);
- *((byte*)(ptr + 20)) = (byte)((UInt32)data.DiffuseColor.Y & 0xff000000 >> 24);
- *((byte*)(ptr + 21)) = (byte)((UInt32)data.DiffuseColor.Y & 0x00ff0000 >> 16);
- *((byte*)(ptr + 22)) = (byte)((UInt32)data.DiffuseColor.Y & 0x0000ff00 >> 8);
- *((byte*)(ptr + 23)) = (byte)((UInt32)data.DiffuseColor.Y & 0x000000ff >> 0);
- *((byte*)(ptr + 24)) = (byte)((UInt32)data.DiffuseColor.Z & 0xff000000 >> 24);
- *((byte*)(ptr + 25)) = (byte)((UInt32)data.DiffuseColor.Z & 0x00ff0000 >> 16);
- *((byte*)(ptr + 26)) = (byte)((UInt32)data.DiffuseColor.Z & 0x0000ff00 >> 8);
- *((byte*)(ptr + 27)) = (byte)((UInt32)data.DiffuseColor.Z & 0x000000ff >> 0);
- // Specular color
- *((byte*)(ptr + 32)) = (byte)((UInt32)data.SpecularColor.X & 0xff000000 >> 24);
- *((byte*)(ptr + 33)) = (byte)((UInt32)data.SpecularColor.X & 0x00ff0000 >> 16);
- *((byte*)(ptr + 34)) = (byte)((UInt32)data.SpecularColor.X & 0x0000ff00 >> 8);
- *((byte*)(ptr + 35)) = (byte)((UInt32)data.SpecularColor.X & 0x000000ff >> 0);
- *((byte*)(ptr + 36)) = (byte)((UInt32)data.SpecularColor.Y & 0xff000000 >> 24);
- *((byte*)(ptr + 37)) = (byte)((UInt32)data.SpecularColor.Y & 0x00ff0000 >> 16);
- *((byte*)(ptr + 38)) = (byte)((UInt32)data.SpecularColor.Y & 0x0000ff00 >> 8);
- *((byte*)(ptr + 39)) = (byte)((UInt32)data.SpecularColor.Y & 0x000000ff >> 0);
- *((byte*)(ptr + 40)) = (byte)((UInt32)data.SpecularColor.Z & 0xff000000 >> 24);
- *((byte*)(ptr + 41)) = (byte)((UInt32)data.SpecularColor.Z & 0x00ff0000 >> 16);
- *((byte*)(ptr + 42)) = (byte)((UInt32)data.SpecularColor.Z & 0x0000ff00 >> 8);
- *((byte*)(ptr + 43)) = (byte)((UInt32)data.SpecularColor.Z & 0x000000ff >> 0);
- }
- return myBuffer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment