Пример #1
0
    void LateUpdate()
    {
        if (Input.GetKeyDown(button))
        {
            gestureWasTriggered = !gestureWasTriggered;
        }

        if (animateFist && skeletonController)
        {
            if (Input.GetKey(button))            //if(Input.GetKeyDown(button))
            {
                if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.RightFist)
                {
                    skeletonController.externalRightStatus = RUISSkeletonManager.Skeleton.handState.closed;
                }
                if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.LeftFist)
                {
                    skeletonController.externalLeftStatus = RUISSkeletonManager.Skeleton.handState.closed;
                }
            }
            else             //if(Input.GetKeyUp(button))
            {
                if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.RightFist)
                {
                    skeletonController.externalRightStatus = RUISSkeletonManager.Skeleton.handState.open;
                }
                if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.LeftFist)
                {
                    skeletonController.externalLeftStatus = RUISSkeletonManager.Skeleton.handState.open;
                }
            }
        }

        // Original skeletonController has been destroyed because the GameObject which had
        // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one.
        if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists)
        {
            if (skeletonParent)
            {
                RUISKinectAndMecanimCombiner combiner = skeletonParent.GetComponentInChildren <RUISKinectAndMecanimCombiner>();
                if (combiner && combiner.isChildrenInstantiated())
                {
                    skeletonController = combiner.skeletonController;

                    if (skeletonController == null)
                    {
                        Debug.LogError("Could not find Component " + typeof(RUISSkeletonController) + " from "
                                       + "children of " + gameObject.transform.parent.name
                                       + ", something is very wrong with this character setup!");
                    }

                    combinerChildrenInstantiated = true;
                }
            }
        }
    }
    RUISSkeletonController getSkeletonController()
    {
        // Original skeletonController has been destroyed because the GameObject which had
        // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one.
        if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists)
        {
            RUISKinectAndMecanimCombiner combiner = GetComponentInChildren <RUISKinectAndMecanimCombiner>();
            if (combiner && combiner.isChildrenInstantiated())
            {
                skeletonController = combiner.skeletonController;

                if (skeletonController == null)
                {
                    Debug.LogError("Could not find Component " + typeof(RUISSkeletonController) + " from "
                                   + "children of " + gameObject.name
                                   + ", something is very wrong with this character setup!");
                }
                combinerChildrenInstantiated = true;
            }
        }
        return(skeletonController);
    }
Пример #3
0
    void FixedUpdate()
    {
//		if(characterController != null && characterController.useOculusPositionalTracking /*&& UnityEditorInternal.InternalEditorUtility.HasPro()*/)
//		{
//			if(OVRDevice.IsCameraTracking() && oculusHmdObject != null)
//			{
//				ovrTrackingState trackingState = oculusHmdObject.GetTrackingState(Hmd.GetTimeInSeconds());
//
//				headPosition = new Vector3(trackingState.HeadPose.ThePose.Position.x, trackingState.HeadPose.ThePose.Position.y, trackingState.HeadPose.ThePose.Position.z);
//				torsoPosition = coordinateSystem.ConvertLocation(coordinateSystem.ConvertRawOculusDK2Location(headPosition), RUISDevice.Oculus_DK2);
//
//				measuredPos[0] = torsoPosition.x;
//				measuredPos[1] = torsoPosition.y;
//				measuredPos[2] = torsoPosition.z;
//				positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance);
//				positionKalman.predict();
//				positionKalman.update(measuredPos);
//				pos = positionKalman.getState();
//				torsoPosition.x = (float) pos[0];
//				torsoPosition.y = (float) pos[1] - coordinateYOffset;
//				torsoPosition.z = (float) pos[2];
//
//				newLocalPosition = torsoPosition;
//				newLocalPosition.y = (torsoPosition.y)/ 2 + coordinateYOffset;
//			}
//		}

        // Tuukka:
        // Original skeletonController has been destroyed because the GameObject which had
        // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one.
        if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists)
        {
            if (gameObject.transform.parent != null)
            {
                RUISKinectAndMecanimCombiner combiner = gameObject.transform.parent.GetComponentInChildren <RUISKinectAndMecanimCombiner>();
                if (combiner && combiner.isChildrenInstantiated())
                {
                    skeletonController = combiner.skeletonController;

                    if (skeletonController == null)
                    {
                        Debug.LogError("Could not find Component " + typeof(RUISSkeletonController) + " from "
                                       + "children of " + gameObject.transform.parent.name
                                       + ", something is very wrong with this character setup!");
                    }

                    bodyTrackingDeviceID         = skeletonController.bodyTrackingDeviceID;
                    playerId                     = skeletonController.playerId;
                    combinerChildrenInstantiated = true;
                }
            }
        }

        if (!skeletonManager || !skeletonManager.skeletons [bodyTrackingDeviceID, playerId].isTracking)
        {
            colliderHeight = defaultColliderHeight;

            if (combinerChildrenInstantiated)
            {
                if (skeletonController.followOculusController || skeletonController.followMoveController)
                {
                    // TODO *** Check that this works with other models. Before with grandma model torsoPos value was:
                    //torsoPos = skeletonController.transform.localPosition + defaultColliderHeight * Vector3.up;
                    torsoPosition      = skeletonController.transform.localPosition;
                    torsoPosition.y    = defaultColliderHeight;                  // torsoPos.y is lerped and 0 doesn't seem to work
                    newLocalPosition   = torsoPosition;
                    newLocalPosition.y = defaultColliderPosition.y;

                    measuredPos[0] = torsoPosition.x;
                    measuredPos[1] = torsoPosition.y;
                    measuredPos[2] = torsoPosition.z;
                    positionKalman.setR(Time.fixedDeltaTime * positionSmoothing);
                    positionKalman.predict();
                    positionKalman.update(measuredPos);
                    pos             = positionKalman.getState();
                    torsoPosition.x = (float)pos[0];
                    torsoPosition.y = (float)pos[1];
                    torsoPosition.z = (float)pos[2];
                }
                else
                {
                    //colliderHeight = defaultColliderHeight;
                    //transform.localPosition = defaultColliderPosition;
                    return;
                }
            }
            else
            {
                //colliderHeight = defaultColliderHeight;
                //transform.localPosition = defaultColliderPosition;
                return;
            }
        }
        else
        {
            if (coordinateSystem && (coordinateSystem.applyToRootCoordinates ||
                                     (bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && coordinateSystem.rootDevice == RUISDevice.Kinect_2) ||
                                     (bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && coordinateSystem.rootDevice == RUISDevice.Kinect_1)))
            {
                coordinateYOffset = coordinateSystem.positionOffset.y;
            }


            // Apply root scaling
            if (skeletonController)
            {
                torsoPosition = Vector3.Scale(skeletonManager.skeletons [bodyTrackingDeviceID, playerId].torso.position, skeletonController.rootSpeedScaling);
            }
            else
            {
                torsoPosition = skeletonManager.skeletons [bodyTrackingDeviceID, playerId].torso.position;
            }

            measuredPos[0] = torsoPosition.x;
            measuredPos[1] = torsoPosition.y;
            measuredPos[2] = torsoPosition.z;
            positionKalman.setR(Time.fixedDeltaTime * positionSmoothing);
            positionKalman.predict();
            positionKalman.update(measuredPos);
            pos             = positionKalman.getState();
            torsoPosition.x = (float)pos[0];
            torsoPosition.y = (float)pos[1] - coordinateYOffset;
            torsoPosition.z = (float)pos[2];

            // Capsule collider is from floor up till torsoPos, therefore the capsule's center point is half of that
            newLocalPosition   = torsoPosition;
            newLocalPosition.y = (torsoPosition.y) / 2 + coordinateYOffset;
        }

        // Updated collider height (from floor to torsoPos)
        colliderHeight = Mathf.Lerp(capsuleCollider.height, torsoPosition.y + colliderHeightTweaker, maxHeightChange * Time.fixedDeltaTime);

        // Updated collider position
        transform.localPosition = Vector3.MoveTowards(transform.localPosition, newLocalPosition, maxPositionChange * Time.fixedDeltaTime);
    }
Пример #4
0
    void FixedUpdate()
    {
        Vector3 torsoPos;
        Vector3 newLocalPosition;

        if (!skeletonManager || !skeletonManager.skeletons[playerId].isTracking)
        {
            colliderHeight = defaultColliderHeight;
            // Tuukka:
            // Original skeletonController has been destroyed because the GameObject which had
            // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one.
            if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists)
            {
                if (gameObject.transform.parent != null)
                {
                    RUISKinectAndMecanimCombiner combiner =
                        gameObject.transform.parent.GetComponentInChildren <RUISKinectAndMecanimCombiner>();
                    if (combiner && combiner.isChildrenInstantiated())
                    {
                        skeletonController           = combiner.skeletonController;
                        combinerChildrenInstantiated = true;
                    }
                }
            }

            if (combinerChildrenInstantiated)
            {
                if (skeletonController.followMoveController)
                {
                    // TODO *** Check that this works with other models. Before with grandma model torsoPos value was:
                    //torsoPos = skeletonController.transform.localPosition + defaultColliderHeight * Vector3.up;
                    torsoPos           = skeletonController.transform.localPosition;
                    torsoPos.y         = defaultColliderHeight;             // torsoPos.y is lerped and 0 doesn't seem to work
                    newLocalPosition   = torsoPos;
                    newLocalPosition.y = defaultColliderPosition.y;

                    measuredPos[0] = torsoPos.x;
                    measuredPos[1] = torsoPos.y;
                    measuredPos[2] = torsoPos.z;
                    positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance);
                    positionKalman.predict();
                    positionKalman.update(measuredPos);
                    pos        = positionKalman.getState();
                    torsoPos.x = (float)pos[0];
                    torsoPos.y = (float)pos[1];
                    torsoPos.z = (float)pos[2];
                }
                else
                {
                    colliderHeight          = defaultColliderHeight;
                    transform.localPosition = defaultColliderPosition;
                    return;
                }
            }
            else
            {
                colliderHeight          = defaultColliderHeight;
                transform.localPosition = defaultColliderPosition;
                return;
            }
        }
        else
        {
            torsoPos = skeletonManager.skeletons[playerId].torso.position;

            measuredPos[0] = torsoPos.x;
            measuredPos[1] = torsoPos.y;
            measuredPos[2] = torsoPos.z;
            positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance);
            positionKalman.predict();
            positionKalman.update(measuredPos);
            pos        = positionKalman.getState();
            torsoPos.x = (float)pos[0];
            torsoPos.y = (float)pos[1];
            torsoPos.z = (float)pos[2];

            // Capsule collider is from floor up till torsoPos, therefore the capsule's center point is half of that
            newLocalPosition   = torsoPos;
            newLocalPosition.y = torsoPos.y / 2;
        }

        // Updated collider height (from floor to torsoPos)
        colliderHeight = Mathf.Lerp(capsuleCollider.height, torsoPos.y + colliderHeightTweaker, maxHeightChange * Time.fixedDeltaTime);
        // Updated collider position
        transform.localPosition = Vector3.MoveTowards(transform.localPosition, newLocalPosition, maxPositionChange * Time.fixedDeltaTime);
    }