Example #1
0
    private Vector3 GetPivotPositionInTrackerCoordinates()
    {
        if (useHmdPositionalTracking && RUISDisplayManager.IsHmdPositionTrackable() && coordinateSystem)
        {
            if (coordinateSystem.applyToRootCoordinates)
            {
                return(coordinateSystem.ConvertLocation(coordinateSystem.GetHmdRawPosition(), RUISDevice.OpenVR));
            }
            else
            {
                return(coordinateSystem.GetHmdRawPosition());
            }
        }
        else
        {
            switch (characterPivotType)
            {
            case CharacterPivotType.KinectHead:
            {
                if ((bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && !inputManager.enableKinect2) ||
                    (bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && !inputManager.enableKinect))
                {
                    break;
                }

                if (skeletonManager && skeletonManager.skeletons[bodyTrackingDeviceID, kinectPlayerId] != null)
                {
                    if (skeletonController)                            // Add root speed scaling
                    {
                        return(Vector3.Scale(skeletonManager.skeletons[bodyTrackingDeviceID, kinectPlayerId].head.position, skeletonController.rootSpeedScaling));
                    }
                    else
                    {
                        return(skeletonManager.skeletons[bodyTrackingDeviceID, kinectPlayerId].head.position);
                    }
                }
                break;
            }

            case CharacterPivotType.KinectTorso:
            {
                if ((bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && !inputManager.enableKinect2) ||
                    (bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && !inputManager.enableKinect))
                {
                    break;
                }

                if (skeletonManager && skeletonManager.skeletons[bodyTrackingDeviceID, kinectPlayerId] != null)
                {
                    if (skeletonController)                            // Add root speed scaling
                    {
                        return(Vector3.Scale(skeletonManager.skeletons[bodyTrackingDeviceID, kinectPlayerId].torso.position, skeletonController.rootSpeedScaling));
                    }
                    else
                    {
                        return(skeletonManager.skeletons[bodyTrackingDeviceID, kinectPlayerId].torso.position);
                    }
                }
                break;
            }

            case CharacterPivotType.MoveController:
            {
                if (!inputManager.enablePSMove)
                {
                    break;
                }

                //if(inputManager.GetMoveWand(moveControllerId))
                //	return inputManager.GetMoveWand(moveControllerId).handlePosition;
                break;
            }
            }
        }

        if (skeletonController != null)
        {
            return(skeletonController.transform.localPosition);
        }
        else
        {
            return(Vector3.zero);
        }
    }