Exemplo n.º 1
0
        private void checkUserGestures(int id)
        {
            SkeletonJointPosition head          = new SkeletonJointPosition();
            SkeletonJointPosition leftHand      = new SkeletonJointPosition();
            SkeletonJointPosition rightHand     = new SkeletonJointPosition();
            SkeletonJointPosition leftShoulder  = new SkeletonJointPosition();
            SkeletonJointPosition rightShoulder = new SkeletonJointPosition();

            head          = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.Head);
            leftHand      = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.LeftHand);
            rightHand     = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.RightHand);
            leftShoulder  = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.LeftShoulder);
            rightShoulder = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.RightShoulder);

            OpenNI.Point3D headPoint  = head.Position;
            OpenNI.Point3D leftPoint  = leftHand.Position;
            OpenNI.Point3D rightPoint = rightHand.Position;

            Ray3D leftPointer = new Ray3D(headPoint.X, headPoint.Y, headPoint.Z,
                                          leftPoint.X, leftPoint.Y, leftPoint.Z);
            Ray3D rightPointer = new Ray3D(headPoint.X, headPoint.Y, headPoint.Z,
                                           rightPoint.X, rightPoint.Y, rightPoint.Z);

            lock (animationLock)
            {
                raysToBeAnimated[0] = leftPointer;
                raysToBeAnimated[1] = rightPointer;
            }

            Console.Write("Left vector: " + leftPointer);
            Console.Write("Right vector: " + rightPointer);

            if (VerticallyClose(leftPoint, rightPoint))
            {
                // Handle dimming.
                if (FirstAboveSecond(leftPoint, headPoint) && FirstAboveSecond(rightPoint, headPoint))
                {
                    Console.Write("Beginning dim down!");
                    dimmingDown   = true;
                    dimmingStartY = leftPoint.Y;
                }
                else if (dimmingDown)
                {
                    int dimPercent = (int)((dimmingStartY - leftPoint.Y) / TOTAL_DIMMING_DISTANCE);
                    if (dimPercent < 0)
                    {
                        dimPercent = 0;
                    }
                    else if (dimPercent > 100)
                    {
                        dimPercent = 100;
                    }

                    Device.dimAllToPercent(dimPercent);
                }
                else if (VerticallyClose(leftPoint, leftShoulder.Position) &&
                         VerticallyClose(leftShoulder.Position, rightShoulder.Position) &&
                         VerticallyClose(rightShoulder.Position, rightPoint))
                {
                    Console.Write("Beginning dim up!");
                    dimmingUp     = true;
                    dimmingStartY = leftPoint.Y;
                }
                else if (dimmingUp)
                {
                    int dimPercent = (int)((leftPoint.Y - dimmingStartY) / TOTAL_DIMMING_DISTANCE);
                    if (dimPercent < 0)
                    {
                        dimPercent = 0;
                    }
                    else if (dimPercent > 100)
                    {
                        dimPercent = 100;
                    }

                    Device.dimAllToPercent(dimPercent);
                }
            }
            else
            {
                // Allow pointing.
                dimmingDown = false;
                dimmingUp   = false;
            }

            if (!dimmingUp && !dimmingDown)
            {
                foreach (Device d in devices)
                {
                    if (leftPointer.closeTo(d.position) || rightPointer.closeTo(d.position))
                    {
                        d.isInFocus();
                    }
                }
            }
            Console.Write("=============================");
        }
        private void checkUserGestures(int id)
        {
            SkeletonJointPosition head = new SkeletonJointPosition();
            SkeletonJointPosition leftHand = new SkeletonJointPosition();
            SkeletonJointPosition rightHand = new SkeletonJointPosition();
            SkeletonJointPosition leftShoulder = new SkeletonJointPosition();
            SkeletonJointPosition rightShoulder = new SkeletonJointPosition();

            head = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.Head);
            leftHand = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.LeftHand);
            rightHand = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.RightHand);
            leftShoulder = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.LeftShoulder);
            rightShoulder = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, SkeletonJoint.RightShoulder);

            OpenNI.Point3D headPoint = head.Position;
            OpenNI.Point3D leftPoint = leftHand.Position;
            OpenNI.Point3D rightPoint = rightHand.Position;

            Ray3D leftPointer = new Ray3D(headPoint.X, headPoint.Y, headPoint.Z,
                    leftPoint.X, leftPoint.Y, leftPoint.Z);
            Ray3D rightPointer = new Ray3D(headPoint.X, headPoint.Y, headPoint.Z,
                    rightPoint.X, rightPoint.Y, rightPoint.Z);

            lock (animationLock)
            {
                raysToBeAnimated[0] = leftPointer;
                raysToBeAnimated[1] = rightPointer;
            }

            Console.Write("Left vector: " + leftPointer);
            Console.Write("Right vector: " + rightPointer);

            if (VerticallyClose(leftPoint, rightPoint))
            {
                // Handle dimming.
                if (FirstAboveSecond(leftPoint, headPoint) && FirstAboveSecond(rightPoint, headPoint))
                {
                    Console.Write("Beginning dim down!");
                    dimmingDown = true;
                    dimmingStartY = leftPoint.Y;
                }
                else if (dimmingDown)
                {
                    int dimPercent = (int)((dimmingStartY - leftPoint.Y) / TOTAL_DIMMING_DISTANCE);
                    if (dimPercent < 0) dimPercent = 0;
                    else if (dimPercent > 100) dimPercent = 100;

                    Device.dimAllToPercent(dimPercent);
                }
                else if (VerticallyClose(leftPoint, leftShoulder.Position)
                    && VerticallyClose(leftShoulder.Position, rightShoulder.Position)
                    && VerticallyClose(rightShoulder.Position, rightPoint))
                {
                    Console.Write("Beginning dim up!");
                    dimmingUp = true;
                    dimmingStartY = leftPoint.Y;
                }
                else if (dimmingUp)
                {
                    int dimPercent = (int)((leftPoint.Y - dimmingStartY) / TOTAL_DIMMING_DISTANCE);
                    if (dimPercent < 0) dimPercent = 0;
                    else if (dimPercent > 100) dimPercent = 100;

                    Device.dimAllToPercent(dimPercent);
                }
            }
            else
            {
                // Allow pointing.
                dimmingDown = false;
                dimmingUp = false;
            }

            if (!dimmingUp && !dimmingDown)
                foreach (Device d in devices)
                    if (leftPointer.closeTo(d.position) || rightPointer.closeTo(d.position))
                        d.isInFocus();
            Console.Write("=============================");
        }