Example #1
0
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            Console.WriteLine(e.Key.ToString());

            if (e.Key.ToString() == "R" || e.Key.ToString() == "F")
            {
                drawController.ClearScreen();
            }
            else if (e.Key.ToString() == "B" || e.Key.ToString() == "G")
            {
                soundController.TriggerBackgroundEffect();
                drawController.CycleBackgrounds();
            }
            else if (e.Key.ToString() == "Q" || e.Key.ToString() == "Space")
            {
                Application.Current.Shutdown();
            }
            else if (e.Key.ToString() == "U")
            {
                if (this.sensor.ColorStream.CameraSettings.Contrast < 2.0)
                {
                    this.sensor.ColorStream.CameraSettings.Contrast += 0.1;
                }
            }
            else if (e.Key.ToString() == "D")
            {
                if (this.sensor.ColorStream.CameraSettings.Contrast > 0.6)
                {
                    this.sensor.ColorStream.CameraSettings.Contrast -= 0.1;
                }
            }

            else if ((e.Key >= Key.D0 && e.Key <= Key.D3) || e.Key == Key.W || e.Key == Key.A || e.Key == Key.S)
            {
                if (e.Key == Key.W)
                {
                    HandleColorChange(0);
                }
                else if (e.Key == Key.A)
                {
                    HandleColorChange(1);
                }
                else if (e.Key == Key.S)
                {
                    HandleColorChange(2);
                }
                else
                {
                    HandleColorChange(e.Key - Key.D0);
                }
            }
        }
        public void listenToSerial()
        {
            Console.WriteLine("start thread");
            while (_continue)
            {
                try
                {
                    string message = port.ReadLine();
                    Console.WriteLine("MESSAGE IS: " + message[0]);
                    // Change color:
                    if (message[0] == '0' || message[0] == '1' || message[0] == '2' || message[0] == '3')
                    {
                        char currColor = message[0];
                        //Console.WriteLine("msg: " + currColor);
                        if (currColor != prevColor)
                        {
                            prevColor = currColor;
                            int colorNum = currColor - '0';
                            drawController.ColorChangeFlag(colorNum);
                            soundController.TriggerColorEffect(colorNum);
                        }
                        //Console.WriteLine(message);
                    }
                    // Change background:
                    else if (message[0] == '5')
                    {
                        TimeSpan timeDiff = DateTime.Now - lastTime;

                        if (timeDiff.TotalMilliseconds > 1000)
                        {
                            drawController.CycleBackgrounds();
                            soundController.TriggerBackgroundEffect();
                            lastTime = DateTime.Now;
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
        }
        private void DrawPoint(DepthImageFrame depthFrame, int depthIndex, int minDepth)
        {
            double x_kinect = (depthIndex % depthFrame.Width);
            double y_kinect = (depthIndex / depthFrame.Width);

            double x = x_kinect * calibration_coefficients[0] + y_kinect * calibration_coefficients[1] + calibration_coefficients[2] + 3;
            double y = x_kinect * calibration_coefficients[3] + y_kinect * calibration_coefficients[4] + calibration_coefficients[5] + 10;

            foreach (Ellipse ellipse in buttons)
            {
                double top  = Canvas.GetTop(ellipse);
                double left = Canvas.GetLeft(ellipse);

                if (y >= top && x >= left && y <= top + ellipse.Height && x <= left + ellipse.Width)
                {
                    DropShadowEffect glowEffect = new DropShadowEffect();
                    glowEffect.ShadowDepth = 0;
                    glowEffect.Opacity     = 1;
                    glowEffect.BlurRadius  = 30;

                    if (ellipse.Name != "refresh_selector" && ellipse.Name != "background_selector")
                    {
                        foreach (Ellipse el in buttons)
                        {
                            if (el.Name != "refresh_selector" && el.Name != "background_selector")
                            {
                                el.Fill.Opacity = 0.3;
                                el.Effect       = null;
                            }
                        }
                    }

                    // Use this button
                    if (ellipse.Name == "red_selector")
                    {
                        ellipse.Fill.Opacity = 1;
                        glowEffect.Color     = Color.FromArgb(255, 255, 44, 44);
                        ellipse.Effect       = glowEffect;
                        drawController.ChangeColor(Colors.Red);
                    }
                    else if (ellipse.Name == "green_selector")
                    {
                        ellipse.Fill.Opacity = 1;
                        glowEffect.Color     = Color.FromArgb(255, 53, 255, 53);
                        ellipse.Effect       = glowEffect;
                        drawController.ChangeColor(Colors.Green);
                    }
                    else if (ellipse.Name == "blue_selector")
                    {
                        ellipse.Fill.Opacity = 1;
                        glowEffect.Color     = Color.FromArgb(255, 115, 78, 255);
                        ellipse.Effect       = glowEffect;
                        drawController.ChangeColor(Colors.Blue);
                    }
                    else if (ellipse.Name == "eraser_selector")
                    {
                        ellipse.Fill.Opacity = 1;
                        glowEffect.Color     = Color.FromArgb(255, 255, 255, 255);
                        ellipse.Effect       = glowEffect;
                        drawController.ChangeColor(Colors.White);
                    }
                    else if (ellipse.Name == "background_selector")
                    {
                        TimeSpan interval = DateTime.Now - last_background_change;
                        if (interval.Seconds >= 0.5)
                        {
                            drawController.CycleBackgrounds();
                            last_background_change = DateTime.Now;
                        }
                    }
                    else if (ellipse.Name == "refresh_selector")
                    {
                        drawController.ClearScreen();
                    }

                    return;
                }
            }
            drawController.DrawEllipseAtPoint(x, y, (DepthThreshold - minDepth));
        }