예제 #1
0
    public void Update()
    {
        if (!isTracking && skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking)
        {
            PlayerFound();
        }
        else if (isTracking && !skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking)
        {
            PlayerLost();
        }
        else if (!skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking)
        {
            return;
        }

        if (!highlightStartObject && wandSelector.HighlightedObject)
        {
            highlightStartObject = wandSelector.HighlightedObject;
            gestureRecognizer.EnableGesture();
        }
        else if (!wandSelector.HighlightedObject)
        {
            highlightStartObject = null;

            if (!wandSelector.Selection)
            {
                gestureRecognizer.DisableGesture();
            }
        }

        visualizerThreshold = Mathf.Clamp01(visualizerThreshold);

        RUISSkeletonManager.JointData startData = skeletonManager.GetJointData(wandStart, playerId, bodyTrackingDeviceID);
        RUISSkeletonManager.JointData endData   = skeletonManager.GetJointData(wandEnd, playerId, bodyTrackingDeviceID);

        if (endData.positionConfidence >= 0.5f)
        {
            // TUUKKA: Original code
//            transform.localPosition = endData.position;
//
//            if (startData != null && startData.positionConfidence >= 0.5f)
//            {
//                transform.localRotation = Quaternion.LookRotation(endData.position - startData.position);
//            }
//            else if (endData.rotationConfidence >= 0.5f)
//            {
//                transform.localRotation = endData.rotation;
//            }

            // First calculate local rotation
            if (startData != null && startData.positionConfidence >= 0.5f)
            {
                tempVector = endData.position - startData.position;
                if (Vector3.Angle(startData.rotation * Vector3.up, tempVector) > 5)
                {
                    tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.up);
                }
                else
                {
                    tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.right);
                }

                filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime);                 // HACK with kinect2 filtering is done in SkeletonManager
            }
//            else if (endData.rotationConfidence >= 0.5f)
//            {
//				tempRotation = endData.rotation;
//				filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime);
//            }

            if (rigidbody)
            {
                // TUUKKA:
                if (transform.parent)
                {
                    // If the wand has a parent, we need to apply its transformation first
                    rigidbody.MovePosition(transform.parent.TransformPoint(endData.position));
                    rigidbody.MoveRotation(transform.parent.rotation * filteredRotation);
                }
                else
                {
                    rigidbody.MovePosition(endData.position);
                    rigidbody.MoveRotation(filteredRotation);
                }
            }
            else
            {
                // If there is no rigidBody, then just change localPosition & localRotation
                transform.localPosition = endData.position;
                transform.localRotation = filteredRotation;
            }
        }
    }