Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sensor"></param>
        /// <param name="GraphicsDevice"></param>
        /// <param name="position"></param>
        public KinectView(KinectSensor sensor, GraphicsDevice GraphicsDevice, Vector2 position)
        {
            this.GraphicsDevice = GraphicsDevice;
            this.sensor = sensor;

            this.positionRect = new Rectangle((int)position.X, (int)position.Y, 640, 480);

            this.trackedArea = new Quadrilateral(position, position, position, position, 0, Color.Red, this.GraphicsDevice);
        }
        public override void LoadContent()
        {
            point = Vector2.Zero;
            calibratedPoint = Vector2.Zero;

            Vector2 viewLocation = new Vector2((ScreenManager.GraphicsDevice.Viewport.Width / 2.0f) - 320, (ScreenManager.GraphicsDevice.Viewport.Height / 2.0f) - 240);

            view = new KinectView(ScreenManager.Input.Sensor, ScreenManager.GraphicsDevice, viewLocation);

            UR = UL = LR = LL = Vector2.Zero;

            trackedArea = new Quadrilateral(UL, UR, LL, LR, 3, Color.Red, ScreenManager.GraphicsDevice);

            trackedLimb = new KinectTrackedObject(UL, UR, LL, LR);

            Content = new ContentManager(ScreenManager.Game.Services, "Content");
            SpriteBatch = ScreenManager.SpriteBatch;

            if (((Manager)ScreenManager).Hand == "Left")
            {
                cursor = Content.Load<Texture2D>("Sprites/Left Hand");
            }

            else
            {
                cursor = Content.Load<Texture2D>("Sprites/Right Hand");
            }

            Texture2D textUR = Content.Load<Texture2D>("GUI/URButton");
            Texture2D textUL = Content.Load<Texture2D>("GUI/ULButton");
            Texture2D textLR = Content.Load<Texture2D>("GUI/LRButton");
            Texture2D textLL = Content.Load<Texture2D>("GUI/LLButton");

            Texture2D textSelect = Content.Load<Texture2D>("GUI/SelectButton");

            float xOffset = ScreenManager.ScaleXPosition(ScreenManager.GraphicsDevice.Viewport.Width - textUR.Width);
            float yOffset = ScreenManager.ScaleYPosition(ScreenManager.GraphicsDevice.Viewport.Height - textUR.Height);

            float middle = ScreenManager.ScaleXPosition((ScreenManager.GraphicsDevice.Viewport.Width / 2.0f) - (textUR.Width / 2.0f));

            Rectangle rectUL = new Rectangle(0, 0, textUR.Width, textUL.Height);
            Rectangle rectUR = new Rectangle((int)xOffset, 0, textUR.Width, textUR.Height);
            Rectangle rectLL = new Rectangle(0, (int)yOffset, textLR.Width, textLR.Height);
            Rectangle rectLR = new Rectangle((int)xOffset, (int)yOffset, textLL.Width, textLL.Height);

            Rectangle rectSelect = new Rectangle((int)middle, (int)yOffset, textSelect.Width, textSelect.Height);

            buttonUR = new GameLibrary.UI.Button(textUR, rectUR);
            buttonUL = new GameLibrary.UI.Button(textUL, rectUL);
            buttonLR = new GameLibrary.UI.Button(textLR, rectLR);
            buttonLL = new GameLibrary.UI.Button(textLL, rectLL);

            selectButton = new GameLibrary.UI.Button(textSelect, rectSelect);
        }
        public override void Update(GameTime gameTime)
        {
            view.Update();

            buttonUR.Update(state);
            buttonUL.Update(state);
            buttonLR.Update(state);
            buttonLL.Update(state);

            selectButton.Update(state);

            if (ScreenManager.Input.SkeletonData != null)
            {
                foreach (Skeleton skeleton in ScreenManager.Input.SkeletonData)
                {
                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        if (((Manager)ScreenManager).Hand == "Left")
                        {
                            point = ScreenManager.Input.SkeletonToColorMap(skeleton.Joints[JointType.HandLeft].Position);
                        }

                        else
                        {
                            point = ScreenManager.Input.SkeletonToColorMap(skeleton.Joints[JointType.HandRight].Position);
                        }

                        calibratedPoint = trackedLimb.TranslatePoint(point);

                        break;
                    }
                }

                if (buttonUR.IsClicked())
                {
                    UR = point;
                    trackedArea = new Quadrilateral(UL, UR, LL, LR, 3, Color.Red, ScreenManager.GraphicsDevice);

                    view.UpdateTrackedArea(trackedArea);

                    trackedLimb = new KinectTrackedObject(UL, UR, LL, LR);
                }

                if (buttonUL.IsClicked())
                {
                    UL = point;
                    trackedArea = new Quadrilateral(UL, UR, LL, LR, 3, Color.Red, ScreenManager.GraphicsDevice);

                    view.UpdateTrackedArea(trackedArea);

                    trackedLimb = new KinectTrackedObject(UL, UR, LL, LR);
                }

                if (buttonLR.IsClicked())
                {
                    LR = point;
                    trackedArea = new Quadrilateral(UL, UR, LL, LR, 3, Color.Red, ScreenManager.GraphicsDevice);

                    view.UpdateTrackedArea(trackedArea);

                    trackedLimb = new KinectTrackedObject(UL, UR, LL, LR);
                }

                if (buttonLL.IsClicked())
                {
                    LL = point;
                    trackedArea = new Quadrilateral(UL, UR, LL, LR, 3, Color.Red, ScreenManager.GraphicsDevice);

                    view.UpdateTrackedArea(trackedArea);

                    trackedLimb = new KinectTrackedObject(UL, UR, LL, LR);
                }

                if (selectButton.IsClicked())
                {
                    ((Manager)ScreenManager).kTrackedObj = trackedLimb;

                    GameScreen gs = new GameScreen();

                    ScreenManager.AddScreen(gs, false);

                    ScreenManager.RemoveScreen(this);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="trackedArea"></param>
        public void UpdateTrackedArea(Quadrilateral trackedArea)
        {
            this.trackedArea.UpperLeft = new Vector2(trackedArea.UpperLeft.X + positionRect.X, trackedArea.UpperLeft.Y + positionRect.Y);
            this.trackedArea.UpperRight = new Vector2(trackedArea.UpperRight.X + positionRect.X, trackedArea.UpperRight.Y + positionRect.Y);
            this.trackedArea.LowerLeft = new Vector2(trackedArea.LowerLeft.X + positionRect.X, trackedArea.LowerLeft.Y + positionRect.Y);
            this.trackedArea.LowerRight = new Vector2(trackedArea.LowerRight.X + positionRect.X, trackedArea.LowerRight.Y + positionRect.Y);

            this.trackedArea.Color = trackedArea.Color;
            this.trackedArea.LineWidth = trackedArea.LineWidth;
        }