示例#1
0
        /// <summary>
        /// Updates the position of the specified <see cref="TouchObject"/> to match that represented by the <see cref="GestureEvent"/> coordinates.
        /// </summary>
        /// <param name="touchObject">The <see cref="TouchObject"/> to rotate.</param>
        /// <param name="gesture">The <see cref="GestureEvent"/> containing the new position data.</param>
        private void HandleRotate(TouchObject touchObject, GestureEvent gesture)
        {
            //Since GestureWorks uses degrees, we have to convert to radians for XNA usage
            float theta = MathHelper.ToRadians(gesture.Values["rotate_dtheta"]);

            //Specify the rotation value of the GO
            touchObject.Rotation += theta;

            //Only update the position if there are two or more TouchPoints associated with the gesture
            if (gesture.N > 1)
            {
                //Rotate the TouchObject around the center of the Gesture, not the object
                touchObject.Position = RotateAboutCenter(touchObject.Position.X, touchObject.Position.Y, gesture.X, gesture.Y, theta);
            }
        }
示例#2
0
        /// <summary>
        /// Returns a value indicating whether the specified TouchPoint lies within the specified TouchObject's bounding box.
        /// </summary>
        /// <param name="touchPoint">TouchPoint to test for TouchObject collision.</param>
        /// <param name="touchObject">TouchObject to test for TouchPoint collision.</param>
        /// <returns><c>true</c> if the TouchPoint is within the TouchObject's bounding box, otherwise <c>false</c></returns>
        private bool Collision(TouchPoint touchPoint, TouchObject touchObject)
        {
            //Setup a bounding box for the touch point
            Rectangle touchPointBox = new Rectangle((int)touchPoint.X - 10,
                                                    (int)touchPoint.Y - 10,
                                                    20,
                                                    20);

            //Test to see if the touch point's bounding box intersects with the TouchObject
            if (touchPointBox.Intersects(touchObject.BoundingBox))
                return true;
            else
                return false;
        }