Esempio n. 1
0
 public Gesture(GestureGenerator.State state, GestureGenerator.EventType eventType, DateTime startTime, IDeque<SensorData> dataSinceGestureStart)
 {
     DataSinceGestureStart = dataSinceGestureStart;
     StartTime = startTime;
     State = state;
     EventType = eventType;
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Program game = new Program();
            game.editMode = new ModeSwitcher.EditModeWrapper();
            game.deform.editMode = game.editMode;
            // web code
            GestureGenerator gestureGenerator = new GestureGenerator();
            Thread generateGesturesThread = new Thread(() =>
            {
                //WebClient webClient = new WebClient();
                //webClient.Proxy = null;
                //string IPaddress = webClient.DownloadString("http://transgame.csail.mit.edu:9537/?varname=jedeyeserver");
                string IPaddress = "127.0.0.1";
                TcpClient client = new TcpClient(IPaddress, 1101);
                TextReader reader = new StreamReader(client.GetStream());
                while (true)
                {
                    string data = reader.ReadLine();
                    SensorData sensor = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorData>(data);
                    if (sensor == null)
                        continue;
                    gestureGenerator.HandleSensorData(sensor);
                }
            });
            generateGesturesThread.Start();

            //PaintWindow paintWindow = new PaintWindow();
            //paintWindow.Show();
            Thread consumeGesturesThread = new Thread(() =>
            {
            #if false
                while (true)
                {
                    Gesture gesture;
                    if (!gestureGenerator.gestures.TryDequeue(out gesture))
                        continue;
                    paintWindow.Dispatcher.BeginInvoke(new ThreadStart(() =>
                    {
                        paintWindow.ConsumeGesture(gesture);
                    }));
                }
            #endif
                while (true)
                {
                    Gesture gesture;
                    if (!gestureGenerator.gestures.TryDequeue(out gesture))
                        continue;

                    game.deform.ConsumeGesture(gesture);
                    /*
                     * Code below illustrates how you can get all the sensor data since the start of the gesture,
                     * both forward in time chronologically, and backward in time.
                     *
                    foreach (SensorData x in gesture.DataSinceGestureStart.ForwardIterate())
                    {
                        Console.WriteLine(x);
                    }
                    foreach (SensorData x in gesture.DataSinceGestureStart.ReverseIterate())
                    {
                        Console.WriteLine(x);
                    }
                    */
                }
                });
            consumeGesturesThread.Start();
            Thread guiThread = new Thread(() =>
            {
                ModeSwitcher modeSwitcher = new ModeSwitcher();
                modeSwitcher.currentMode = game.editMode;
                game.editMode.modeSwitcher = modeSwitcher;
                modeSwitcher.meshTypeChanged = (MeshTypes newMeshType) =>
                {
                    Console.WriteLine(newMeshType.ToString());
                };
                modeSwitcher.Show();
                Application app = new Application();
                app.Run();
            });
            guiThread.SetApartmentState(ApartmentState.STA);
            guiThread.Start();

            Thread mouseThread = new Thread(() =>
            {
                float zoomFactor = 1.0f;
                float prevWheel = 0.0f;
                float prevX = 0.0f;
                float prevY = 0.0f;
                while (true)
                {
                    // x,y pans
                    POINT mouseP;
                    if (MouseUtils.GetCursorPos(out mouseP))
                    {
                        float x = mouseP.X;
                        float y = mouseP.Y;
                        float diffx = x - prevX;
                        prevX = x;
                        float diffy = -(y - prevY);
                        prevY = y;
                        game.test.activeAreaStart += new Vector2(diffx*0.003f, diffy*0.003f);
                    }

                    // wheel zooms
                    float wheel = game.Mouse.WheelPrecise;
                    float diff = wheel - prevWheel;
                    zoomFactor += -diff * 0.01f;
                    if (zoomFactor > 2.0f) zoomFactor = 2.0f;
                    if (zoomFactor < 0.01f) zoomFactor = 0.01f;
                    game.test.activeAreaSize = new Vector2(zoomFactor, zoomFactor);
                    //game.test.activeAreaSize *= (wheel - prevWheel);
                    //Console.WriteLine(zoomFactor);
                    prevWheel = wheel;
                    Thread.Sleep(10);
                }
            });
            bool[] undoButtonPressed = new bool[] { false };
            mouseThread.Start();
            Thread mouseUndoThread = new Thread(() =>
            {
                int numUndoesSoFar = 0;
                while (true)
                {
                    if (undoButtonPressed[0])
                    {
                        game.test.Undo();
                        for (int i = 0; i < numUndoesSoFar / 5; ++i)
                        {
                            game.test.Undo();
                        }
                        ++numUndoesSoFar;
                    }
                    else
                    {
                        numUndoesSoFar = 0;
                    }
                    Thread.Sleep(100);
                }
            });
            mouseUndoThread.Start();
            game.Mouse.ButtonDown += (object o, MouseButtonEventArgs e) =>
            {
                if (e.Button == MouseButton.Left)
                {
                    game.deform.editMode.mode = ModeSwitcher.EditMode.Subtract;
                }
                //if (e.Button == MouseButton.Right)
                //{
                //    game.deform.editMode.mode = ModeSwitcher.EditMode.Subtract;
                //}
                if (e.Button == MouseButton.Right)
                {
                    undoButtonPressed[0] = true;
                    game.test.Undo();
                }
            };
            game.Mouse.ButtonUp += (object o, MouseButtonEventArgs e) =>
            {
                if (e.Button == MouseButton.Left)
                {
                    game.deform.editMode.mode = ModeSwitcher.EditMode.Add;
                }
                if (e.Button == MouseButton.Right)
                {
                    undoButtonPressed[0] = false;
                }
            };
            game.Run();
            /*
            Application app = new Application();
            app.MainWindow = paintWindow;
            app.Run();
            */
        }