Ejemplo n.º 1
0
    // Updates the newX and newY for moving the specified paddle in relation to the specified hand and boundaries
    // Override for use with Kinect sensor
    private void UpdatePaddleNewPosition(GameObject paddle, Vector3 handPosition, PaddleBounds kinectBounds, PaddleBounds paddleBounds, out Vector3 newPosition)
    {
        float newX = handPosition.x;
        float newY = handPosition.y;

        // Clamp newX and newY to be within the kinect bounds
        if (newY > kinectBounds.Top)
        {
            newY = kinectBounds.Top;
        }
        else if (newY < kinectBounds.Bottom)
        {
            newY = kinectBounds.Bottom;
        }
        if (newX > kinectBounds.Right)
        {
            newX = kinectBounds.Right;
        }
        else if (newX < kinectBounds.Left)
        {
            newX = kinectBounds.Left;
        }

        // Scale newX and newY to be within the paddle bounds
        newX = ((newX - kinectBounds.Left) * (paddleBounds.Right - paddleBounds.Left)) / (kinectBounds.Right - kinectBounds.Left) + paddleBounds.Left;
        newY = ((newY - kinectBounds.Bottom) * (paddleBounds.Top - paddleBounds.Bottom)) / (kinectBounds.Top - kinectBounds.Bottom) + paddleBounds.Bottom;

        newPosition = new Vector3(newX, newY, this.transform.position.z);
    }
Ejemplo n.º 2
0
    // Updates the newX and newY for moving the specified paddle in relation to the specified hand and boundaries
    private void UpdatePaddleNewPosition(GameObject paddle, Hand hand, PaddleBounds leapBounds, PaddleBounds paddleBounds, out Vector3 newPosition)
    {
        float newX = hand.PalmPosition.x;
        float newY = hand.PalmPosition.y;

        // Clamp newX and newY to be within the leap bounds
        if (newY > leapBounds.Top)
        {
            newY = leapBounds.Top;
        }
        else if (newY < leapBounds.Bottom)
        {
            newY = leapBounds.Bottom;
        }
        if (newX > leapBounds.Right)
        {
            newX = leapBounds.Right;
        }
        else if (newX < leapBounds.Left)
        {
            newX = leapBounds.Left;
        }

        // Scale newX and newY to be within the paddle bounds
        newX = ((newX - leapBounds.Left) * (paddleBounds.Right - paddleBounds.Left)) / (leapBounds.Right - leapBounds.Left) + paddleBounds.Left;
        newY = ((newY - leapBounds.Bottom) * (paddleBounds.Top - paddleBounds.Bottom)) / (leapBounds.Top - leapBounds.Bottom) + paddleBounds.Bottom;

        newPosition = new Vector3(newX, newY, this.transform.position.z);
    }