C0BRA

FreeTrack

Oct 10th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2. using System.IO.MemoryMappedFiles;
  3. using System.Runtime.InteropServices;
  4. using System.Threading;
  5.  
  6. namespace FakeFreeTrack
  7. {
  8.    [StructLayout(LayoutKind.Sequential)]
  9.    public struct TFreeTrackData
  10.    {
  11.        public int DataID;
  12.        public int CamWidth;
  13.        public int CamHeight;
  14.        // virtual pose
  15.        public float Yaw;   // positive yaw to the left
  16.        public float Pitch; // positive pitch up
  17.        public float Roll;  // positive roll to the left
  18.        public float X;
  19.        public float Y;
  20.        public float Z;
  21.        // raw pose with no smoothing, sensitivity, response curve etc.
  22.        public float RawYaw;
  23.        public float RawPitch;
  24.        public float RawRoll;
  25.        public float RawX;
  26.        public float RawY;
  27.        public float RawZ;
  28.        // raw points, sorted by Y, origin top left corner
  29.        public float X1;
  30.        public float Y1;
  31.        public float X2;
  32.        public float Y2;
  33.        public float X3;
  34.        public float Y3;
  35.        public float X4;
  36.        public float Y4;
  37.    };
  38.  
  39.    class Program
  40.    {
  41.        static void Main(string[] args)
  42.        {
  43.            var random = new Random();
  44.            var count = 0;
  45.                using (var memoryMappedFile = MemoryMappedFile.CreateOrOpen("FT_SharedMem", Marshal.SizeOf(typeof(TFreeTrackData))))
  46.                {
  47.                    using (var accessor = memoryMappedFile.CreateViewAccessor())
  48.                    {
  49.                        while (true)
  50.                        {
  51.                            count++;
  52.                            TFreeTrackData model =  new TFreeTrackData();
  53.                            model.DataID = count;
  54.                            model.CamWidth = 320;
  55.                            model.CamHeight = 240;
  56.                            model.Yaw = random.Next(0, 120) / (float)(180.0 / Math.PI);
  57.  
  58.                            accessor.Write(0, ref model);
  59.                            Thread.Sleep(5);
  60.                        }
  61.                    }
  62.                }
  63.        }
  64.    }
  65. }
Add Comment
Please, Sign In to add comment