Exemplo n.º 1
0
        private void bFrameReader(object sender, BodyFrameArrivedEventArgs e)
        {
            using (var bFrame = e.FrameReference.AcquireFrame())
            {
                if (bFrame == null)
                {
                    return;
                }
                bFrame.GetAndRefreshBodyData(bodies);
            }

            foreach (var value in bodies)
            {
                if (value.IsTracked)
                {
                    leftHand  = new Vector2PLUS(value.Joints[JointType.HandLeft].Position.X, value.Joints[JointType.HandLeft].Position.Y);
                    rightHand = new Vector2PLUS(value.Joints[JointType.HandRight].Position.X, value.Joints[JointType.HandRight].Position.Y);
                }
            }

            for (int ID = 9; ID > 0; ID--)
            {
                rHandPosi[ID] = rHandPosi[ID - 1];
            }

            rHandPosi[0] = rightHand;
        }
Exemplo n.º 2
0
        /// <summary> 手の位置を描画位置に反映させる </summary>
        /// <param name="screenSize"></param>
        /// <param name="leftHandPosi"></param>
        /// <param name="rightHandPosi"></param>
        private void HandPositionAppply(Vector2PLUS screenSize, Vector2PLUS leftHandPosi, Vector2PLUS[] rightHandPosi)
        {
            leftHnadPoint.Set_Position(PosiConverter(new Vector2PLUS(leftHandPosi.X, leftHandPosi.Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize));

            for (int ID = 0; ID < 10; ID++)
            {
                rightHnadPoint[ID].Set_Position(PosiConverter(new Vector2PLUS(rightHandPosi[ID].X, rightHandPosi[ID].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize));
            }
        }
Exemplo n.º 3
0
        /// <summary> コンストラクタ </summary>
        /// <param name="texAddres">画像アドレス</param>
        /// <param name="initPosi">初期位置</param>
        /// <param name="size">大きさ</param>
        public Figure(Vector2PLUS initPosi, Vector2PLUS size)
        {
            this.initPosi      = initPosi;
            this.size          = size;
            this.color         = Color.White;
            this.gravityFlag   = false;
            this.collisionFlag = false;
            this.vector        = new Vector2PLUS();

            Initialize();
        }
Exemplo n.º 4
0
 /// <summary>
 /// 円と矩形の衝突判定(Ohyama)
 /// </summary>
 /// <param name="TL">矩形の左上の座標</param>
 /// <param name="BR">矩形の右下の座標</param>
 /// <param name="CirclePosition">円の中心座標</param>
 /// <param name="radius">円の半径</param>
 /// <returns></returns>
 public static bool BoxToCircle(Vector2PLUS TL, Vector2PLUS BR, Vector2PLUS CirclePosition, int radius)
 {
     if (CirclePosition.Y + radius < TL.Y || CirclePosition.X + radius < TL.X ||
         CirclePosition.Y - radius > BR.Y || CirclePosition.X - radius > BR.X)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 矩形同士の衝突判定(Ohyama)
 /// </summary>
 /// <param name="ATL">BoxAの左上の座標</param>
 /// <param name="ABR">BoxAの右下の座標</param>
 /// <param name="BTL">BoxBの左上の座標</param>
 /// <param name="BBR">BoxBの右下の座標</param>
 /// <returns></returns>
 public static bool BoxToBox(Vector2PLUS ATL, Vector2PLUS ABR, Vector2PLUS BTL, Vector2PLUS BBR)
 {
     //衝突していなければ true / 衝突していれば false を返す
     if (ABR.X < BTL.X || ABR.Y < BTL.Y || ATL.X > BBR.X || ATL.Y > BBR.Y)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 6
0
        public Kinect()
        {
            kinect = KinectSensor.GetDefault();

            kinect.Open();

            bodies = new Body[kinect.BodyFrameSource.BodyCount];

            kinect.BodyFrameSource.OpenReader().FrameArrived += bFrameReader;

            leftHand  = new Vector2PLUS();
            rightHand = new Vector2PLUS();

            rHandPosi = new Vector2PLUS[10];
        }
Exemplo n.º 7
0
        public Source()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            Figure.Set_ContentManager(Content);

            // インスタンス
            mainScene = new MainScene();

            kinect     = new Kinect();
            leapMotion = new LeapMotion();

            screenSize = new Vector2PLUS(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
        }
Exemplo n.º 8
0
        /// <summary> 矩形が描かれているか判定する </summary>
        private void SquareCheck()
        {
            endPosi = new Vector2PLUS();

            for (int ID = 0; ID < directionNames.Length; ID++)
            {
                if (directionNames[ID] == DirectionName.Left)
                {
                    flagBottom = true;
                    for (int ID2 = ID; ID2 < directionNames.Length; ID2++)
                    {
                        if (directionNames[ID2] == DirectionName.Top)
                        {
                            endPosi   = oldRightHnadPosi[ID2];
                            flagRight = true;
                            for (int ID3 = ID2; ID3 < directionNames.Length; ID3++)
                            {
                                if (directionNames[ID3] == DirectionName.Right)
                                {
                                    flagTop = true;
                                    for (int ID4 = ID3; ID4 < directionNames.Length; ID4++)
                                    {
                                        if (directionNames[ID4] == DirectionName.Bottom)
                                        {
                                            flagLeft   = true;
                                            flagCreate = true;
                                            break;
                                        }
                                    }
                                }
                                if (flagCreate)
                                {
                                    break;
                                }
                            }
                        }
                        if (flagCreate)
                        {
                            break;
                        }
                    }
                }
                if (flagCreate)
                {
                    break;
                }
            }
        }
Exemplo n.º 9
0
        public void Logic(Vector2PLUS screenSize, Vector2PLUS leftHnadPosi, Vector2PLUS rightHnadPosi)
        {
            if (gravityFlag)
            {
                vector.Y += 0.098f;
            }

            if (vector.X != 0)
            {
                float tempVal = 0.05f;
                if (vector.X < -tempVal)
                {
                    vector.X += tempVal;
                }
                else if (vector.X > tempVal)
                {
                    vector.X -= tempVal;
                }
                else
                {
                    vector.X = 0;
                }
            }

            if (position.Y + vector.Y + size.Y > screenSize.Y - 100)
            {
                position.Y = screenSize.Y - size.Y - 100; vector.Y = 0;
            }

            if (collisionFlag)
            {
                if (CollisionCheck.BoxToBox(position, position + size, leftHnadPosi, leftHnadPosi + new Vector2PLUS(30, 30)))
                {
                    Vector2PLUS temp = (position + (size / 2)) - (leftHnadPosi + new Vector2PLUS(15, 15));

                    vector += new Vector2PLUS(1 / temp.X, 1 / temp.Y) * 10;
                }

                if (CollisionCheck.BoxToBox(position, position + size, rightHnadPosi, rightHnadPosi + new Vector2PLUS(30, 30)))
                {
                    Vector2PLUS temp = (position + (size / 2)) - (rightHnadPosi + new Vector2PLUS(15, 15));

                    vector += new Vector2PLUS(1 / temp.X, 1 / temp.Y) * 10;
                }
            }

            position += vector;
        }
Exemplo n.º 10
0
        public MainScene()
        {
            figures = new List <Figure>();

            squares          = new List <Square>();
            circles          = new List <Circle>();
            rightHnadPoint   = new Dot[10];
            oldRightHnadPosi = new Vector2PLUS[100];
            direction        = 0;

            for (int ID = 0; ID < 100; ID++)
            {
                directionNames[ID]   = DirectionName.None;
                oldRightHnadPosi[ID] = new Vector2PLUS();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///  円同士の衝突判定(Ohyama)
        /// </summary>
        /// <param name="positionA">円Aの中心座標</param>
        /// <param name="positionB">円Bの中心座標</param>
        /// <param name="radiusA">円Aの半径</param>
        /// <param name="radiusB">円Bの半径</param>
        /// <returns></returns>
        public static bool CircleToCircle(Vector2PLUS positionA, Vector2PLUS positionB, int radiusA, int radiusB)
        {
            float tempDistanceX = (positionA.X - positionB.X) * (positionA.X - positionB.X);
            float tempDistanceY = (positionA.Y - positionB.Y) * (positionA.Y - positionB.Y);
            float tmepDistance  = tempDistanceX + tempDistanceY;
            float tempRadiusSum = (radiusA + radiusB) * (radiusA + radiusB);

            if (tempDistanceY < tempRadiusSum)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 12
0
        /// <summary> 逆三角関数を使って角度を算出する </summary>
        private void DirectionConputing(Vector2PLUS[] rightHandPosi)
        {
            Vector2PLUS tempVect = rightHandPosi[0] - rightHandPosi[1];
            float       offset   = 0.01f;

            if (tempVect.X < offset && tempVect.X > -offset && tempVect.Y < offset && tempVect.Y > -offset)
            {
                direction = 0; nowDirectionName = DirectionName.Center;
            }
            else
            {
                float tempValue = (float)Math.Atan((tempVect.Y / tempVect.X));

                direction = MathHelper.ToDegrees(tempValue);

                if (tempVect.X < 0)
                {
                    direction += 180;
                }
                else if (tempVect.Y < 0)
                {
                    direction += 360;
                }

                if (direction >= 337.5f || direction < 22.5f)
                {
                    nowDirectionName = DirectionName.Right;
                }
                // else if (direction >= 22.5f && direction < 67.5f) { nowDirectionName = DirectionName.TopRight; }
                else if (direction >= 67.5f && direction < 112.5f)
                {
                    nowDirectionName = DirectionName.Top;
                }
                // else if (direction >= 112.5f && direction < 157.5f) { nowDirectionName = DirectionName.TopLeft; }
                else if (direction >= 157.5f && direction < 202.5f)
                {
                    nowDirectionName = DirectionName.Left;
                }
                // else if (direction >= 202.5f && direction < 247.5f) { nowDirectionName = DirectionName.BottomLeft; }
                else if (direction >= 247.5f && direction < 292.5f)
                {
                    nowDirectionName = DirectionName.Bottom;
                }
                // else if (direction >= 292.5f && direction < 337.5f) { nowDirectionName = DirectionName.BottomRight; }
            }
        }
Exemplo n.º 13
0
        /// <summary> 計算処理 </summary>
        public void Logic(KeyboardState keyState, bool handFlag, Vector2PLUS screenSize, Vector2PLUS leftHandPosi, Vector2PLUS[] rightHandPosi)
        {
            // 角度の算出
            DirectionConputing(rightHandPosi);

            // 手の位置を描画に反映
            HandPositionAppply(screenSize, leftHandPosi, rightHandPosi);


            // 矩形が絵がれているかを判定
            if (keyState.IsKeyDown(Keys.Enter) || !handFlag)
            {
                if (handInitFlag)
                {
                    startPosi = PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize); handInitFlag = false;
                }

                if (directionNames[0] == DirectionName.None)
                {
                    DirectionSave();
                }
                else if (nowDirectionName != DirectionName.Center)
                {
                    if (directionNames[0] == DirectionName.Top)
                    {
                        if (nowDirectionName == DirectionName.Left || nowDirectionName == DirectionName.Right)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).X) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                        else if (nowDirectionName == DirectionName.Bottom)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).Y) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                    }

                    else if (directionNames[0] == DirectionName.Bottom)
                    {
                        if (nowDirectionName == DirectionName.Left || nowDirectionName == DirectionName.Right)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).X) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                        else if (nowDirectionName == DirectionName.Top)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).Y) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                    }

                    else if (directionNames[0] == DirectionName.Left)
                    {
                        if (nowDirectionName == DirectionName.Top || nowDirectionName == DirectionName.Bottom)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).Y) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                        else if (nowDirectionName == DirectionName.Right)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).X) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                    }

                    else if (directionNames[0] == DirectionName.Right)
                    {
                        if (nowDirectionName == DirectionName.Top || nowDirectionName == DirectionName.Bottom)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).Y) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                        else if (nowDirectionName == DirectionName.Left)
                        {
                            if (Math.Abs((oldRightHnadPosi[0] - PosiConverter(new Vector2PLUS(rightHandPosi[0].X, rightHandPosi[0].Y * -1), new Vector2PLUS(2.0f, 2.0f), screenSize)).X) > 50)
                            {
                                // 方向の履歴を保存
                                DirectionSave();
                            }
                        }
                    }
                }
                SquareCheck();
            }
            else
            {
                DirectionNameInitialize();
            }

            // フラグが立ったら図形を作る
            if (flagCreate)
            {
                CreateFigures();
            }



            // 図形クラスをまとめる処理
            FiguresSet();

            foreach (var value in figures)
            {
                value.Logic(screenSize, leftHnadPoint.position, rightHnadPoint[0].position);
            }

            this.handFlag = handFlag;
        }
Exemplo n.º 14
0
 /// <summary> 初期化処理 </summary>
 public void Initialize()
 {
     this.position = initPosi;
 }
Exemplo n.º 15
0
 public Figure(Vector2PLUS initPosi, Vector2PLUS size, bool gravityFlag, bool collisionFlag) : this(initPosi, size)
 {
     this.gravityFlag   = gravityFlag;
     this.collisionFlag = collisionFlag;
 }
Exemplo n.º 16
0
 public void Set_Position(Vector2PLUS position)
 {
     this.position = position;
 }
Exemplo n.º 17
0
 public Circle(Vector2PLUS initPosi, Vector2PLUS size) : base(initPosi, size)
 {
     texture = Content.Load <Texture2D>("Circle");
 }
Exemplo n.º 18
0
 public Square(Vector2PLUS initPosi, Vector2PLUS size) : base(initPosi, size)
 {
     texture = Content.Load <Texture2D>("Square2");
 }
Exemplo n.º 19
0
 public Square(Vector2PLUS initPosi, Vector2PLUS size, bool gravityFlag, bool collisionFlag) : base(initPosi, size, gravityFlag, collisionFlag)
 {
     texture = Content.Load <Texture2D>("Square2");
 }
Exemplo n.º 20
0
 /// <summary> キネクト座標系を画面の座標系に変換する </summary>
 /// <param name="target">対象とするキネクト座標</param>
 /// <param name="targetMaxSize">キネクト座標のマックスの値</param>
 /// <param name="screenSize">ウィンドウのサイズ</param>
 /// <returns></returns>
 private Vector2PLUS PosiConverter(Vector2PLUS target, Vector2PLUS targetMaxSize, Vector2PLUS screenSize)
 {
     return(new Vector2PLUS(target.X / targetMaxSize.X * screenSize.X, target.Y / targetMaxSize.Y * screenSize.Y) + (screenSize / 2));
 }
Exemplo n.º 21
0
 public Dot(Vector2PLUS initPosi, Vector2PLUS size) : base(initPosi, size)
 {
     texture = Content.Load <Texture2D>("Dot");
 }