Advertisement
RaWRCoder

vec3f

Aug 15th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. public struct Vec3f
  2.     {
  3.         public float x, y, z;
  4.  
  5.         // ...
  6.  
  7.         public unsafe static explicit operator byte[](Vec3f s)
  8.         {
  9.             var bts = new byte[12];
  10.             var ps = &s;
  11.             var btsp = (byte*) ps;
  12.             for (var i = 0; i < 12; i++)
  13.                 bts[i] = btsp[i];
  14.             return bts;
  15.         }
  16.         public unsafe static explicit operator Vec3f(byte[] bts)
  17.         {
  18.             fixed (byte* btsp = &bts[0])
  19.             {
  20.                 return *(Vec3f*)btsp;
  21.             }
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement