void Awake()
    {
        characterController = GetComponent<RUISCharacterController>();
        jumpGesture = GetComponentInChildren<RUISJumpGestureRecognizer>();

        moveWrapper = FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;

        try
        {
            Input.GetAxis("Sprint");
        }
        catch (UnityException)
        {
			Debug.LogWarning("'Sprint' not defined in Unity Input settings");
        }

        try
        {
            Input.GetAxis("Turn");
        }
        catch (UnityException)
        {
			Debug.LogWarning("'Turn' not defined in Unity Input settings");
        }
		
		try
		{
			Input.GetAxis("Jump");
		}
		catch (UnityException)
		{
			Debug.LogWarning("'Jump' not defined in Unity Input settings");
		}
    }
예제 #2
0
    void Awake()
    {
        characterController = GetComponent <RUISCharacterController>();
        jumpGesture         = GetComponentInChildren <RUISJumpGestureRecognizer>();

        moveWrapper = FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;

        try
        {
            Input.GetAxis("Sprint");
        }
        catch (UnityException)
        {
            Debug.LogWarning("'Sprint' not defined in Unity Input settings");
        }

        try
        {
            Input.GetAxis("Turn");
        }
        catch (UnityException)
        {
            Debug.LogWarning("'Turn' not defined in Unity Input settings");
        }

        try
        {
            Input.GetAxis("Jump");
        }
        catch (UnityException)
        {
            Debug.LogWarning("'Jump' not defined in Unity Input settings");
        }
    }
    public void OnEnable()
    {
		characterPivotType = serializedObject.FindProperty("characterPivotType");
		useOculusPositionalTracking = serializedObject.FindProperty("useOculusPositionalTracking");
		headRotatesBody = serializedObject.FindProperty("headRotatesBody");
		headPointsWalkingDirection = serializedObject.FindProperty("headPointsWalkingDirection");
        moveControllerId = serializedObject.FindProperty("moveControllerId");
        ignorePitchAndRoll = serializedObject.FindProperty("ignorePitchAndRoll");
        groundLayers = serializedObject.FindProperty("groundLayers");
        groundedErrorTweaker = serializedObject.FindProperty("groundedErrorTweaker");
        dynamicFriction = serializedObject.FindProperty("dynamicFriction");
        dynamicMaterial = serializedObject.FindProperty("dynamicMaterial");
		psmoveOffset = serializedObject.FindProperty("psmoveOffset");
		feetAlsoAffectGrounding = serializedObject.FindProperty("feetAlsoAffectGrounding");
		
		characterController = target as RUISCharacterController;
    }
예제 #4
0
    public void OnEnable()
    {
        characterPivotType          = serializedObject.FindProperty("characterPivotType");
        useOculusPositionalTracking = serializedObject.FindProperty("useOculusPositionalTracking");
        headRotatesBody             = serializedObject.FindProperty("headRotatesBody");
        headPointsWalkingDirection  = serializedObject.FindProperty("headPointsWalkingDirection");
        moveControllerId            = serializedObject.FindProperty("moveControllerId");
        ignorePitchAndRoll          = serializedObject.FindProperty("ignorePitchAndRoll");
        groundLayers            = serializedObject.FindProperty("groundLayers");
        groundedErrorTweaker    = serializedObject.FindProperty("groundedErrorTweaker");
        dynamicFriction         = serializedObject.FindProperty("dynamicFriction");
        dynamicMaterial         = serializedObject.FindProperty("dynamicMaterial");
        psmoveOffset            = serializedObject.FindProperty("psmoveOffset");
        feetAlsoAffectGrounding = serializedObject.FindProperty("feetAlsoAffectGrounding");

        characterController = target as RUISCharacterController;
    }
예제 #5
0
    // end // Head/Body turn gesture

    void Awake()
    {
        characterController = GetComponent <RUISCharacterController>();
        jumpGesture         = GetComponentInChildren <RUISJumpGestureRecognizer>();

        //moveWrapper = FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
        bimanualSwingingRecognizer = FindObjectOfType(typeof(RUISBimanualSwingingRecognizer)) as RUISBimanualSwingingRecognizer;         // TODO: Shouldn't probably check whole scene
        coordinateSystem           = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
        skeletonManager            = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;

        try
        {
            Input.GetAxis("Sprint");
        }
        catch (UnityException)
        {
            Debug.LogWarning("'Sprint' not defined in Unity Input settings");
        }

        try
        {
            Input.GetAxis("Turn");
        }
        catch (UnityException)
        {
            Debug.LogWarning("'Turn' not defined in Unity Input settings");
        }

        try
        {
            Input.GetAxis("Jump");
        }
        catch (UnityException)
        {
            Debug.LogWarning("'Jump' not defined in Unity Input settings");
        }
    }
    void Start()
    {
		
		if (skeletonManager == null)
		{
			skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
			if (!skeletonManager)
				Debug.LogError("The scene is missing " + typeof(RUISSkeletonManager) + " script!");
		}

		// Disable features that are only available for Kinect2 or custom motion tracker
		if (bodyTrackingDevice == bodyTrackingDeviceType.Kinect1) 
		{
			fistCurlFingers = false;
			trackThumbs = false;
			trackWrist  = false;
			trackAnkle  = false;
			rotateWristFromElbow = false;
		}

        if (useHierarchicalModel)
        {
            //fix all shoulder and hip rotations to match the default kinect rotations
            rightShoulder.rotation = FindFixingRotation(rightShoulder.position, rightElbow.position, transform.right) * rightShoulder.rotation;
            leftShoulder.rotation = FindFixingRotation(leftShoulder.position, leftElbow.position, -transform.right) * leftShoulder.rotation;
            rightHip.rotation = FindFixingRotation(rightHip.position, rightFoot.position, -transform.up) * rightHip.rotation;
            leftHip.rotation = FindFixingRotation(leftHip.position, leftFoot.position, -transform.up) * leftHip.rotation;

			Vector3 scaler = new Vector3(1/transform.lossyScale.x, 1/transform.lossyScale.y, 1/transform.lossyScale.z);
			Vector3 assumedRootPos = Vector3.Scale((rightShoulder.position + leftShoulder.position + leftHip.position + rightHip.position) / 4, scaler); 
															// (1/transform.lossyScale.x, 1/transform.lossyScale.y, 1/transform.lossyScale.z)
			Vector3 realRootPos = Vector3.Scale(torso.position, scaler);

			Vector3 torsoUp = head.position - torso.position;
			torsoUp.Normalize();
			torsoOffset = Vector3.Dot(realRootPos - assumedRootPos, torsoUp);
			//torsoOffset = (realRootPos - assumedRootPos).y;

            if (neck)
            {
                neckOriginalLocalPosition = neck.localPosition;
				if(neck.parent)
				{
					chest = neck.parent;
					if(chest == torso)
					{
						Debug.Log(	typeof(RUISSkeletonController) + ": Hierarchical model stored in GameObject " + this.name 
						          + " does not have enough joints between neck and torso for Hips Vertical Tweaker to work.");
						chest = null;
					}
					chestOriginalLocalPosition = chest.localPosition;
				}
            }
        }

        SaveInitialRotation(root);
        SaveInitialRotation(head);
        SaveInitialRotation(torso);
        SaveInitialRotation(rightShoulder);
        SaveInitialRotation(rightElbow);
        SaveInitialRotation(rightHand);
        SaveInitialRotation(leftShoulder);
        SaveInitialRotation(leftElbow);
        SaveInitialRotation(leftHand);
        SaveInitialRotation(rightHip);
        SaveInitialRotation(rightKnee);
        SaveInitialRotation(rightFoot);
        SaveInitialRotation(leftHip);
        SaveInitialRotation(leftKnee);
        SaveInitialRotation(leftFoot);

		SaveInitialRotation(leftThumb);
		SaveInitialRotation(rightThumb);

		saveInitialFingerRotations();
		
        SaveInitialDistance(rightShoulder, rightElbow);
        SaveInitialDistance(rightElbow, rightHand);
        SaveInitialDistance(leftShoulder, leftElbow);
        SaveInitialDistance(leftElbow, leftHand);

        SaveInitialDistance(rightHip, rightKnee);
        SaveInitialDistance(rightKnee, rightFoot);
        SaveInitialDistance(leftHip, leftKnee);
        SaveInitialDistance(leftKnee, leftFoot);

        SaveInitialDistance(torso, head);

        SaveInitialDistance(rightShoulder, leftShoulder);
        SaveInitialDistance(rightHip, leftHip);

		
		if (rightElbow)
			unalteredRightForearmScale = rightElbow.localScale;
		
		if (leftElbow)
			unalteredLeftForearmScale = leftElbow.localScale;
		
		if(rightKnee)
			unalteredRightShinScale = rightKnee.localScale;
		
		if(leftKnee)
			unalteredLeftShinScale = leftKnee.localScale;

		// Finger clench rotations: these depend on your animation rig
		// Also see method handleFingersCurling() and its clenchedRotationThumbTM_corrected and clenchedRotationThumbIP_corrected
		// variables, if you are not tracking thumbs with Kinect 2. They also depend on your animation rig.
		switch(boneLengthAxis)
		{
		case RUISAxis.X:
			// Thumb phalange rotations when hand is clenched to a fist
			clenchedRotationThumbTM = Quaternion.Euler (45, 0, 0); 
			clenchedRotationThumbMCP = Quaternion.Euler (0, 0, -25 );
			clenchedRotationThumbIP = Quaternion.Euler (0, 0, -80);
			// Phalange rotations of other fingers when hand is clenched to a fist
			clenchedRotationMCP = Quaternion.Euler (0, 0, -45);
			clenchedRotationPIP = Quaternion.Euler (0, 0, -100);
			clenchedRotationDIP = Quaternion.Euler (0, 0, -70);
			break;
		case RUISAxis.Y:
			// Thumb phalange rotations when hand is clenched to a fist
			clenchedRotationThumbTM = Quaternion.Euler (0, 0, 0); 
			clenchedRotationThumbMCP = Quaternion.Euler (0, 0, 0);
			clenchedRotationThumbIP = Quaternion.Euler (0, 0, 80);
			// Phalange rotations of other fingers when hand is clenched to a fist
			clenchedRotationMCP = Quaternion.Euler (45, 0, 0);
			clenchedRotationPIP = Quaternion.Euler (100, 0, 0);
			clenchedRotationDIP = Quaternion.Euler (70, 0, 0);
			break;
		case RUISAxis.Z: // TODO: Not yet tested with a real rig
			// Thumb phalange rotations when hand is clenched to a fist
			clenchedRotationThumbTM = Quaternion.Euler (45, 0, 0); 
			clenchedRotationThumbMCP = Quaternion.Euler (0, 0, -25 );
			clenchedRotationThumbIP = Quaternion.Euler (0, 0, -80);
			// Phalange rotations of other fingers when hand is clenched to a fist
			clenchedRotationMCP = Quaternion.Euler (0, -45, 0);
			clenchedRotationPIP = Quaternion.Euler (0, -100, 0);
			clenchedRotationDIP = Quaternion.Euler (0, -70, 0);
			break;
		}

		if(inputManager)
		{
			if(gameObject.transform.parent != null)
			{
				characterController = gameObject.transform.parent.GetComponent<RUISCharacterController>();
				if(characterController != null)
				{
					if(		characterController.characterPivotType == RUISCharacterController.CharacterPivotType.MoveController
						&&	inputManager.enablePSMove																			)
					{
						followMoveController = true;
						followMoveID = characterController.moveControllerId;
//						if(		 gameObject.GetComponent<RUISKinectAndMecanimCombiner>() == null 
//							||	!gameObject.GetComponent<RUISKinectAndMecanimCombiner>().enabled )
							Debug.LogWarning(	"Using PS Move controller #" + characterController.moveControllerId + " as a source "
						                 	 +	"for avatar root position of " + gameObject.name + ", because PS Move is enabled"
											 +	"and the PS Move controller has been assigned as a "
											 +	"Character Pivot in " + gameObject.name + "'s parent GameObject");
					}

					if(!inputManager.enableKinect && !inputManager.enableKinect2 && !followMoveController)
					{
						
						if(OVRManager.display != null && OVRManager.display.isPresent)
						{
							followOculusController = true;
							Debug.LogWarning(	"Using Oculus Rift HMD as a Character Pivot for " + gameObject.name
							                 +	", because Kinects are disabled and an Oculus Rift was detected.");
						}
					}
				}
			}
		}

		
		try
		{
			if(OVRManager.capiHmd != null)
				ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type;
		}
		catch(UnityException e)
		{
			Debug.LogError(e);
		}

		if(oculusRotatesHead && (OVRManager.display == null || !OVRManager.display.isPresent))
		   oculusRotatesHead = false;

		// HACK for filtering Kinect 2 arm rotations
		skeletonManager.skeletons [bodyTrackingDeviceID, playerId].filterRotations = filterRotations;
		skeletonManager.skeletons [bodyTrackingDeviceID, playerId].rotationNoiseCovariance = rotationNoiseCovariance;
		for(int i=0; i < skeletonManager.skeletons [bodyTrackingDeviceID, playerId].filterRot.Length; ++i)
		{
			if(skeletonManager.skeletons [bodyTrackingDeviceID, playerId].filterRot[i] != null)
				skeletonManager.skeletons [bodyTrackingDeviceID, playerId].filterRot[i].rotationNoiseCovariance = rotationNoiseCovariance;
		}
		skeletonManager.skeletons [bodyTrackingDeviceID, playerId].thumbZRotationOffset = thumbZRotationOffset;
    }
예제 #7
0
 void Start()
 {
     player = GetComponent <RUISCharacterController> ();
 }
예제 #8
0
 // Use this for initialization
 void Start()
 {
     charControl = gameObject.GetComponent <RUISCharacterController>();
     audio       = gameObject.GetComponent <AudioSource>();
 }
예제 #9
0
    void Awake()
    {
        if (!scriptEnabled)
        {
            return;
        }

        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        bool kinect2   = false;
        bool kinect    = false;
        bool psmove    = false;
        bool razer     = false;
        bool oculusDK2 = false;

        bool isRiftConnected = false;

        //#if UNITY_EDITOR
        //if(UnityEditorInternal.InternalEditorUtility.HasPro())
        //#endif
        {
            try
            {
                // Find out if an Oculus HMD is connected
                if (OVRManager.display != null)
                {
                    isRiftConnected = OVRManager.display.isPresent;
                }

                // Find out the Oculus HMD version
                if (OVRManager.capiHmd != null)
                {
                    ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type;
                }
            }
            catch (UnityException e)
            {
                Debug.LogError(e);
            }
        }

        if (inputManager)
        {
            if (isRiftConnected && (ovrHmdVersion == Ovr.HmdType.DK2 || ovrHmdVersion == Ovr.HmdType.Other))
            {
                oculusDK2 = true;
            }

            kinect2 = inputManager.enableKinect2;
            kinect  = inputManager.enableKinect;
            psmove  = inputManager.enablePSMove;
            razer   = inputManager.enableRazerHydra;

            int         trackerCount      = 0;
            RUISTracker closestMatch      = null;
            int         currentMatchScore = 0;

            RUISHeadTrackerAssigner[] assigners = FindObjectsOfType(typeof(RUISHeadTrackerAssigner)) as RUISHeadTrackerAssigner[];
            if (!allowMultipleAssigners && assigners.Length > 1)
            {
                Debug.LogError("Multiple active RUISHeadTrackerAssigner scripts found while 'Allow Multiple Assigners' is false: "
                               + "Disabling all headtrackers and their child objects that are listed in the RUISHeadTrackerAssigner "
                               + "component of '" + gameObject.name + "' object.");

                for (int i = 0; i < headTrackers.Capacity; ++i)
                {
                    if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy)
                    {
                        headTrackers[i].gameObject.SetActive(false);
                    }
                }
                return;
            }

            foreach (RUISTracker trackerScript in headTrackers)
            {
                if (trackerScript && trackerScript.gameObject.activeInHierarchy)
                {
                    ++trackerCount;
                    int foundTrackerScore = 0;

                    // Give score to found head trackers
                    if (oculusDK2 && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.OculusDK2)
                    {
                        foundTrackerScore = 7;
                        print(trackerScript);
                    }
                    else if (psmove && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.PSMove)
                    {
                        foundTrackerScore = 6;
                    }
                    else if (razer && trackerScript.isRazerBaseMobile &&                         // Legacy: Mobile Hydra Base (custom tracker)
                             trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&
                             trackerScript.mobileRazerBase == RUISTracker.RazerHydraBase.InputTransform)
                    {
                        foundTrackerScore = 5;
                    }
                    else if (kinect2 && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.Kinect2)
                    {
                        foundTrackerScore = 4;
                    }
                    else if (kinect && razer && trackerScript.isRazerBaseMobile &&                         // Legacy: Mobile Hydra Base (Kinect)
                             trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&
                             trackerScript.mobileRazerBase == RUISTracker.RazerHydraBase.Kinect1)
                    {
                        foundTrackerScore = 3;
                    }
                    else if (kinect && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.Kinect1)
                    {
                        foundTrackerScore = 2;
                    }
                    else if (razer && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&                         // Plain ol' Razer Hydra
                             !trackerScript.isRazerBaseMobile)
                    {
                        foundTrackerScore = 1;
                    }

                    // Assign new best head tracker candidate if it is better than the previously found
                    if (currentMatchScore < foundTrackerScore)
                    {
                        closestMatch      = trackerScript;
                        currentMatchScore = foundTrackerScore;
                    }
                }
            }

            if (trackerCount == 0 && Application.isEditor)
            {
                Debug.LogError("No active GameObjects with RUISTracker script found from headTrackers list!");
            }

            string     positionTracker = "<None>";
            string     logString       = "";
            string     names           = "";
            RUISCamera ruisCamera      = null;

            if (closestMatch == null)
            {
                // Disable all but the first active head tracker from the headTrackers list
                logString = "Could not find a suitable head tracker with regard to "
                            + "enabled devices in RUISInputManager!";

                bool disabling        = false;
                int  leftEnabledIndex = -1;
                for (int i = 0; i < headTrackers.Capacity; ++i)
                {
                    if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy)
                    {
                        if (disabling)
                        {
                            if (names.Length > 0)
                            {
                                names = names + ", ";
                            }
                            names = names + headTrackers[i].gameObject.name;
                            headTrackers[i].gameObject.SetActive(false);
                        }
                        else
                        {
                            leftEnabledIndex = i;
                            closestMatch     = headTrackers[leftEnabledIndex];
                            positionTracker  = headTrackers[leftEnabledIndex].gameObject.name;
                            disabling        = true;
                        }
                    }
                }
                if (leftEnabledIndex >= 0)
                {
                    logString = logString + " Choosing the first head tracker in the list. Using "
                                + positionTracker + " for tracking head position";
                    if (names.Length > 0)
                    {
                        logString = logString + ", and disabling the following: " + names;
                    }
                    logString = logString + ". This choice was made using a pre-selected list of "
                                + "head trackers.";

                    ruisCamera = headTrackers[leftEnabledIndex].gameObject.GetComponentInChildren <RUISCamera>();
                }
                Debug.LogError(logString);
            }
            else
            {
                // Disable all but the closest match head tracker from the headTrackers list
                for (int i = 0; i < headTrackers.Capacity; ++i)
                {
                    if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy)
                    {
                        if (headTrackers[i] != closestMatch)
                        {
                            if (names.Length > 0)
                            {
                                names = names + ", ";
                            }
                            names = names + headTrackers[i].gameObject.name;
                            headTrackers[i].gameObject.SetActive(false);
                        }
                        else
                        {
                            positionTracker = headTrackers[i].gameObject.name;
                        }
                    }
                }
                logString = "Found the best head tracker with regard to enabled devices in "
                            + "RUISInputManager! Using " + positionTracker + " for tracking head position";
                if (names.Length > 0)
                {
                    logString = logString + ", and disabling the following: " + names;
                }
                Debug.Log(logString + ". This choice was made using a pre-selected list of head trackers.");

                ruisCamera = closestMatch.gameObject.GetComponentInChildren <RUISCamera>();

                if (changePivotIfNoKinect && psmove && !kinect && !kinect2 &&
                    closestMatch.headPositionInput == RUISTracker.HeadPositionSource.PSMove)
                {
                    RUISCharacterController characterController = gameObject.GetComponentInChildren <RUISCharacterController>();
                    if (characterController != null &&
                        characterController.characterPivotType != RUISCharacterController.CharacterPivotType.MoveController)
                    {
                        characterController.characterPivotType = RUISCharacterController.CharacterPivotType.MoveController;
                        characterController.moveControllerId   = closestMatch.positionPSMoveID;
                        Debug.Log("PS Move enabled and Kinect disabled. Setting " + characterController.name
                                  + "'s CharacterCamera Pivot as PS Move controller #" + closestMatch.positionPSMoveID
                                  + ". PS Move position offset for this pivot is " + characterController.psmoveOffset);
                    }
                }
            }


            if (ruisCamera)
            {
                if (display == null)
                {
                    Debug.LogWarning("No RUISDisplay attached to the RUISHeadTrackerAssigner script!");
                    RUISDisplay[] displays = FindObjectsOfType(typeof(RUISDisplay)) as RUISDisplay[];
                    for (int i = 0; i < displays.Length; ++i)
                    {
                        if (displays[i].linkedCamera == null)
                        {
                            Debug.LogWarning("Assigned RUISCamera component from the child of " + positionTracker
                                             + " to render on " + displays[i].gameObject.name + " because that "
                                             + "RUISDisplay component's RUISCamera field was empty.");
                            displays[i].linkedCamera = ruisCamera;
                            break;
                        }
                    }
                }
                else
                {
                    if (display.linkedCamera == null)
                    {
                        Debug.Log("Assigned RUISCamera component from the child of " + positionTracker
                                  + " to render on " + display.gameObject.name);
                        display.linkedCamera = ruisCamera;
                    }
                    else
                    {
                        Debug.LogWarning("RUISDisplay " + display.gameObject.name + " is already connected with a "
                                         + "RUISCamera object! Leave the RUISCamera field empty in your RUISDisplay "
                                         + "component if you want RUISHeadTrackerAssigner script to automatically "
                                         + "assign a RUISCamera to your RUISDisplay.");
                    }
                }
            }
            else
            {
                if (closestMatch)
                {
                    Debug.LogError(positionTracker + " did not have a child with RUISCamera component, "
                                   + "and therefore it is not used to draw on any of the displays in "
                                   + "DisplayManager.");
                }
            }

            // If we are using Razer with a static base for head tracking, then apply onlyRazerOffset
            // on the parent objects of the Razer head tracker and the hand-held Razer
            if (closestMatch != null && razer &&
                closestMatch.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra &&
                !closestMatch.isRazerBaseMobile)
            {
                // The parent object of the Razer head tracker must not have RUISCharacterConroller,
                // because that script will modify the object's position
                if (closestMatch.transform.parent != null &&
                    closestMatch.transform.parent.GetComponent <RUISCharacterController>() == null &&
                    (onlyRazerOffset.x != 0 || onlyRazerOffset.y != 0 || onlyRazerOffset.z != 0))
                {
                    string razerWandOffsetInfo = "";
                    closestMatch.transform.parent.localPosition += onlyRazerOffset;
                    if (razerWandParent != null)
                    {
                        razerWandParent.localPosition += onlyRazerOffset;
                        razerWandOffsetInfo            = " and " + razerWandParent.gameObject.name + " (parent of hand-held Razer "
                                                         + "Hydra)";
                    }
                    Debug.Log("Applying offset of " + onlyRazerOffset + " to "
                              + closestMatch.transform.parent.gameObject.name + " (parent of Razer Hydra head tracker)"
                              + razerWandOffsetInfo + ".");
                }
            }

            // If no Razer, Kinect, or PS Move is available, then apply onlyMouseOffset
            // on the parent object of the head tracker that is left enabled
//			if(		closestMatch != null && !razer && !kinect && !psmove)
//			{
//				// The parent object of the Razer head tracker must not have RUISCharacterConroller,
//				// because that script will modify the object's position
//				if(		closestMatch.transform.parent != null
//					&&	closestMatch.transform.parent.GetComponent<RUISCharacterController>() == null
//					&& (onlyMouseOffset.x != 0 || onlyMouseOffset.y != 0 || onlyMouseOffset.z != 0)  )
//				{
//					closestMatch.transform.parent.localPosition += onlyMouseOffset;
//					Debug.Log(  "Applying offset of " + onlyMouseOffset + " to "
//							   + closestMatch.transform.parent.gameObject.name + " (parent of assigned head tracker).");
//				}
//			}

            // *** TODO: Below is slightly hacky
            // Read inputConfig.xml to see if Kinect yaw drift correction for Oculus Rift should be enabled
            if (closestMatch != null &&
                closestMatch.useOculusRiftRotation && applyKinectDriftCorrectionPreference)
            {
                if (inputManager.kinectDriftCorrectionPreferred)
                {
                    // Preference is to use Kinect for drift correction (if PS Move is not used for head tracking)
                    switch (closestMatch.headPositionInput)
                    {
                    case RUISTracker.HeadPositionSource.Kinect1:
                        if (!psmove && kinect)
                        {
                            closestMatch.externalDriftCorrection = true;
                            closestMatch.compass = RUISTracker.CompassSource.Kinect1;
                        }
                        break;

                    case RUISTracker.HeadPositionSource.RazerHydra:
                        if (!psmove && kinect && razer)
                        {
                            if (closestMatch.isRazerBaseMobile)
                            {
                                closestMatch.externalDriftCorrection = true;
                                closestMatch.compass = RUISTracker.CompassSource.Kinect1;
                            }
                        }
                        break;
                    }
                }
                else
                {
                    // Preference is NOT to use Kinect for drift correction
                    if (closestMatch.headPositionInput == RUISTracker.HeadPositionSource.Kinect1 &&
                        !psmove && kinect)
                    {
                        closestMatch.externalDriftCorrection = false;
                    }
                }
            }
        }
    }
    void Start()
    {
        if (useHierarchicalModel)
        {
            //fix all shoulder and hip rotations to match the default kinect rotations
            rightShoulder.rotation = FindFixingRotation(rightShoulder.position, rightElbow.position, transform.right) * rightShoulder.rotation;
            leftShoulder.rotation = FindFixingRotation(leftShoulder.position, leftElbow.position, -transform.right) * leftShoulder.rotation;
            rightHip.rotation = FindFixingRotation(rightHip.position, rightFoot.position, -transform.up) * rightHip.rotation;
            leftHip.rotation = FindFixingRotation(leftHip.position, leftFoot.position, -transform.up) * leftHip.rotation;

            Vector3 assumedRootPos = (rightShoulder.position + leftShoulder.position + leftHip.position + rightHip.position) / 4;
            Vector3 realRootPos = torso.position;
            torsoOffset = (realRootPos - assumedRootPos).y;

            if (neck)
            {
                neckOriginalLocalPosition = neck.localPosition;
            }
        }

        SaveInitialRotation(root);
        SaveInitialRotation(head);
        SaveInitialRotation(torso);
        SaveInitialRotation(rightShoulder);
        SaveInitialRotation(rightElbow);
        SaveInitialRotation(rightHand);
        SaveInitialRotation(leftShoulder);
        SaveInitialRotation(leftElbow);
        SaveInitialRotation(leftHand);
        SaveInitialRotation(rightHip);
        SaveInitialRotation(rightKnee);
        SaveInitialRotation(rightFoot);
        SaveInitialRotation(leftHip);
        SaveInitialRotation(leftKnee);
        SaveInitialRotation(leftFoot);

        SaveInitialDistance(rightShoulder, rightElbow);
        SaveInitialDistance(rightElbow, rightHand);
        SaveInitialDistance(leftShoulder, leftElbow);
        SaveInitialDistance(leftElbow, leftHand);

        SaveInitialDistance(rightHip, rightKnee);
        SaveInitialDistance(rightKnee, rightFoot);
        SaveInitialDistance(leftHip, leftKnee);
        SaveInitialDistance(leftKnee, leftFoot);

        SaveInitialDistance(torso, head);

        SaveInitialDistance(rightShoulder, leftShoulder);
        SaveInitialDistance(rightHip, leftHip);

        if (rightElbow)
        {
            originalRightForearmScale = rightElbow.localScale;
        }

        if (leftElbow)
        {
            originalLeftForearmScale = leftElbow.localScale;
        }

        if(rightKnee)
        {
            originalRightShinScale = rightKnee.localScale;
        }

        if(leftKnee)
        {
            originalLeftShinScale = leftKnee.localScale;
        }

        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        if(inputManager && !inputManager.enableKinect)
        {
            //			Debug.Log("Kinect is not enabled. Disabling RUISSkeletonController script from Kinect-controlled GameObject " + gameObject.name + ".");
            //			MonoBehaviour[] scripts = GetComponents<MonoBehaviour>();
            //			foreach(MonoBehaviour script in scripts)
            //			{
            //				if(script.GetType().Equals(typeof(RUISSkeletonController)))
            //					script.enabled = false;
            //			}

            if(gameObject.transform.parent != null)
            {
                characterController = gameObject.transform.parent.GetComponent<RUISCharacterController>();
                if(characterController != null)
                    if(		characterController.characterPivotType == RUISCharacterController.CharacterPivotType.MoveController
                       &&	inputManager.enablePSMove																			)
                {
                    followMoveController = true;
                    followMoveID = characterController.moveControllerId;
                    if(		 gameObject.GetComponent<RUISKinectAndMecanimCombiner>() == null
                       ||	!gameObject.GetComponent<RUISKinectAndMecanimCombiner>().enabled )
                        Debug.LogWarning(	"Using PS Move controller #" + characterController.moveControllerId + " as a source "
                                         +	"for avatar root position of " + gameObject.name + ", because Kinect is disabled "
                                         +	"and PS Move is enabled, while that PS Move controller has been assigned as a "
                                         +	"Character Pivot in " + gameObject.name + "'s parent GameObject");
                }
            }
        }
    }
예제 #11
0
    void Start()
    {
        if (useHierarchicalModel)
        {
            //fix all shoulder and hip rotations to match the default kinect rotations
            rightShoulder.rotation = FindFixingRotation(rightShoulder.position, rightElbow.position, transform.right) * rightShoulder.rotation;
            leftShoulder.rotation  = FindFixingRotation(leftShoulder.position, leftElbow.position, -transform.right) * leftShoulder.rotation;
            rightHip.rotation      = FindFixingRotation(rightHip.position, rightFoot.position, -transform.up) * rightHip.rotation;
            leftHip.rotation       = FindFixingRotation(leftHip.position, leftFoot.position, -transform.up) * leftHip.rotation;

            Vector3 assumedRootPos = (rightShoulder.position + leftShoulder.position + leftHip.position + rightHip.position) / 4;
            Vector3 realRootPos    = torso.position;
            torsoOffset = (realRootPos - assumedRootPos).y;

            if (neck)
            {
                neckOriginalLocalPosition = neck.localPosition;
            }
        }

        SaveInitialRotation(root);
        SaveInitialRotation(head);
        SaveInitialRotation(torso);
        SaveInitialRotation(rightShoulder);
        SaveInitialRotation(rightElbow);
        SaveInitialRotation(rightHand);
        SaveInitialRotation(leftShoulder);
        SaveInitialRotation(leftElbow);
        SaveInitialRotation(leftHand);
        SaveInitialRotation(rightHip);
        SaveInitialRotation(rightKnee);
        SaveInitialRotation(rightFoot);
        SaveInitialRotation(leftHip);
        SaveInitialRotation(leftKnee);
        SaveInitialRotation(leftFoot);

        SaveInitialDistance(rightShoulder, rightElbow);
        SaveInitialDistance(rightElbow, rightHand);
        SaveInitialDistance(leftShoulder, leftElbow);
        SaveInitialDistance(leftElbow, leftHand);

        SaveInitialDistance(rightHip, rightKnee);
        SaveInitialDistance(rightKnee, rightFoot);
        SaveInitialDistance(leftHip, leftKnee);
        SaveInitialDistance(leftKnee, leftFoot);

        SaveInitialDistance(torso, head);

        SaveInitialDistance(rightShoulder, leftShoulder);
        SaveInitialDistance(rightHip, leftHip);

        if (rightElbow)
        {
            originalRightForearmScale = rightElbow.localScale;
        }

        if (leftElbow)
        {
            originalLeftForearmScale = leftElbow.localScale;
        }

        if (rightKnee)
        {
            originalRightShinScale = rightKnee.localScale;
        }

        if (leftKnee)
        {
            originalLeftShinScale = leftKnee.localScale;
        }

        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        if (inputManager && !inputManager.enableKinect)
        {
//			Debug.Log("Kinect is not enabled. Disabling RUISSkeletonController script from Kinect-controlled GameObject " + gameObject.name + ".");
//			MonoBehaviour[] scripts = GetComponents<MonoBehaviour>();
//			foreach(MonoBehaviour script in scripts)
//			{
//				if(script.GetType().Equals(typeof(RUISSkeletonController)))
//					script.enabled = false;
//			}

            if (gameObject.transform.parent != null)
            {
                characterController = gameObject.transform.parent.GetComponent <RUISCharacterController>();
                if (characterController != null)
                {
                    if (characterController.characterPivotType == RUISCharacterController.CharacterPivotType.MoveController &&
                        inputManager.enablePSMove)
                    {
                        followMoveController = true;
                        followMoveID         = characterController.moveControllerId;
                        if (gameObject.GetComponent <RUISKinectAndMecanimCombiner>() == null ||
                            !gameObject.GetComponent <RUISKinectAndMecanimCombiner>().enabled)
                        {
                            Debug.LogWarning("Using PS Move controller #" + characterController.moveControllerId + " as a source "
                                             + "for avatar root position of " + gameObject.name + ", because Kinect is disabled "
                                             + "and PS Move is enabled, while that PS Move controller has been assigned as a "
                                             + "Character Pivot in " + gameObject.name + "'s parent GameObject");
                        }
                    }
                }
            }
        }
    }