コード例 #1
0
//    SerializedProperty riftMagnetometerMode;

    
    void OnEnable()
    {
        inputConfig = target as RUISInputManager;
		
        xmlSchema = serializedObject.FindProperty("xmlSchema");
        filename = serializedObject.FindProperty("filename");

        psMoveEnabled = serializedObject.FindProperty("enablePSMove");
        loadFromTextFileInEditor = serializedObject.FindProperty("loadFromTextFileInEditor");
        connectToMoveOnStartup = serializedObject.FindProperty("connectToPSMoveOnStartup");
        psMoveIp = serializedObject.FindProperty("PSMoveIP");
        psMovePort = serializedObject.FindProperty("PSMovePort");
        inGameMoveCalibration = serializedObject.FindProperty("enableMoveCalibrationDuringPlay");
        amountOfPSMoveControllers = serializedObject.FindProperty("amountOfPSMoveControllers");

		delayedWandActivation = serializedObject.FindProperty("delayedWandActivation");
		delayTime = serializedObject.FindProperty("delayTime");
		moveWand0 = serializedObject.FindProperty("moveWand0");
		moveWand1 = serializedObject.FindProperty("moveWand1");
		moveWand2 = serializedObject.FindProperty("moveWand2");
		moveWand3 = serializedObject.FindProperty("moveWand3");
		
        kinectEnabled = serializedObject.FindProperty("enableKinect");
        maxNumberOfKinectPlayers = serializedObject.FindProperty("maxNumberOfKinectPlayers");
		kinect1FloorDetectionOnSceneStart = serializedObject.FindProperty("kinectFloorDetection");

		kinect2Enabled = serializedObject.FindProperty("enableKinect2");
		kinect2FloorDetectionOnSceneStart = serializedObject.FindProperty("kinect2FloorDetection");

		enableRazerHydra = serializedObject.FindProperty("enableRazerHydra");

//        riftMagnetometerMode = serializedObject.FindProperty("riftMagnetometerMode");
        
	}
コード例 #2
0
	public static bool ImportInputManager(RUISInputManager inputManager, string filename, TextAsset xmlSchema)
	{
		XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, xmlSchema);
		if (xmlDoc == null)
		{
			return false;
		}
		
		XmlNode psMoveNode = xmlDoc.GetElementsByTagName("PSMoveSettings").Item(0);
		inputManager.enablePSMove = bool.Parse(psMoveNode.SelectSingleNode("enabled").Attributes["value"].Value);
		inputManager.PSMoveIP = psMoveNode.SelectSingleNode("ip").Attributes["value"].Value;
		inputManager.PSMovePort = int.Parse(psMoveNode.SelectSingleNode("port").Attributes["value"].Value);
		inputManager.connectToPSMoveOnStartup = bool.Parse(psMoveNode.SelectSingleNode("autoConnect").Attributes["value"].Value);
		inputManager.enableMoveCalibrationDuringPlay = bool.Parse(psMoveNode.SelectSingleNode("enableInGameCalibration").Attributes["value"].Value);
		inputManager.amountOfPSMoveControllers = int.Parse(psMoveNode.SelectSingleNode("maxControllers").Attributes["value"].Value);
		
		XmlNode kinectNode = xmlDoc.GetElementsByTagName("KinectSettings").Item(0);
		inputManager.enableKinect = bool.Parse(kinectNode.SelectSingleNode("enabled").Attributes["value"].Value);
		inputManager.maxNumberOfKinectPlayers = int.Parse(kinectNode.SelectSingleNode("maxPlayers").Attributes["value"].Value);
		inputManager.kinectFloorDetection = bool.Parse(kinectNode.SelectSingleNode("floorDetection").Attributes["value"].Value);
		inputManager.jumpGestureEnabled = bool.Parse(kinectNode.SelectSingleNode("jumpGestureEnabled").Attributes["value"].Value);
		
		XmlNode kinect2Node = xmlDoc.GetElementsByTagName("Kinect2Settings").Item(0);
		inputManager.enableKinect2 = bool.Parse(kinect2Node.SelectSingleNode("enabled").Attributes["value"].Value);
		
		XmlNode razerNode = xmlDoc.GetElementsByTagName("RazerSettings").Item(0);
		inputManager.enableRazerHydra = bool.Parse(razerNode.SelectSingleNode("enabled").Attributes["value"].Value);
		
		XmlNode riftDriftNode = xmlDoc.GetElementsByTagName("OculusDriftSettings").Item(0);
//		string magnetometerMode = riftDriftNode.SelectSingleNode("magnetometerDriftCorrection").Attributes["value"].Value;
		//inputManager.riftMagnetometerMode = (RUISInputManager.RiftMagnetometer)System.Enum.Parse(typeof(RUISInputManager.RiftMagnetometer), magnetometerMode);
		inputManager.kinectDriftCorrectionPreferred = bool.Parse(riftDriftNode.SelectSingleNode("kinectDriftCorrectionIfAvailable").Attributes["value"].Value);
		
		return true;
	}
コード例 #3
0
    void OnEnable()
    {
        inputConfig = target as RUISInputManager;

        xmlSchema = serializedObject.FindProperty("xmlSchema");
        filename  = serializedObject.FindProperty("filename");

        psMoveEnabled            = serializedObject.FindProperty("enablePSMove");
        loadFromTextFileInEditor = serializedObject.FindProperty("loadFromTextFileInEditor");
        connectToMoveOnStartup   = serializedObject.FindProperty("connectToPSMoveOnStartup");
        psMoveIp                  = serializedObject.FindProperty("PSMoveIP");
        psMovePort                = serializedObject.FindProperty("PSMovePort");
        inGameMoveCalibration     = serializedObject.FindProperty("enableMoveCalibrationDuringPlay");
        amountOfPSMoveControllers = serializedObject.FindProperty("amountOfPSMoveControllers");

        delayedWandActivation = serializedObject.FindProperty("delayedWandActivation");
        delayTime             = serializedObject.FindProperty("delayTime");
        moveWand0             = serializedObject.FindProperty("moveWand0");
        moveWand1             = serializedObject.FindProperty("moveWand1");
        moveWand2             = serializedObject.FindProperty("moveWand2");
        moveWand3             = serializedObject.FindProperty("moveWand3");

        kinectEnabled              = serializedObject.FindProperty("enableKinect");
        maxNumberOfKinectPlayers   = serializedObject.FindProperty("maxNumberOfKinectPlayers");
        floorDetectionOnSceneStart = serializedObject.FindProperty("kinectFloorDetection");

        enableRazerHydra = serializedObject.FindProperty("enableRazerHydra");

        riftMagnetometerMode = serializedObject.FindProperty("riftMagnetometerMode");
    }
コード例 #4
0
    public void Start()
    {
        switch (compass)
        {
        case CompassSource.Kinect:
            if (!skeletonManager)
            {
                skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
            }
            if (!skeletonManager)
            {
                Debug.LogError("RUISSkeletonManager script is missing from this scene!");
            }
            break;

        case CompassSource.PSMove:
            inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
            if (!inputManager)
            {
                Debug.LogError("RUISInputManager script is missing from this scene!");
            }
            break;
        }

        if (driftingSensor == DriftingRotation.InputTransform && !driftingTransform)
        {
            Debug.LogError("driftingTransform is none, you need to set it from the inspector!");
        }

        oculusCamController = FindObjectOfType(typeof(OVRCameraController)) as OVRCameraController;
    }
コード例 #5
0
    void Start()
    {
        RUISInputManager inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        if (useRazerHydra && inputManager && !inputManager.enableRazerHydra)
        {
            useRazerHydra = false;
//			Debug.LogWarning(	"Your settings indicate that you want to use Razer Hydra for "
//							 +	"character locomotion controls, but you have disabled Razer "
//							 +	"Hydra from " + typeof(RUISInputManager));
        }

        if (usePSNavigationController && inputManager && !inputManager.enablePSMove)
        {
            usePSNavigationController = false;
//			Debug.LogWarning(	"Your settings indicate that you want to use PS Navigation "
//							 +	"controller for character locomotion controls, but you have "
//							 +	"disabled PS Move from RUIS InputManager.");
        }

        if (useOpenVrController && !RUISDisplayManager.IsOpenVrAccessible())
        {
            useOpenVrController = false;
        }
    }
コード例 #6
0
 void Awake()
 {
     inputManager        = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
     skeletonManager     = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
     stabilizingCollider = GetComponentInChildren <RUISCharacterStabilizingCollider>();
     lastJumpTime        = 0;
 }
コード例 #7
0
    // Use this for initialization
    void Start()
    {
        try
        {
            Input.GetButtonDown("RUISMenu");
        }
        catch (UnityException)
        {
            ruisMenuButtonDefined = false;
        }

        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        enablePSMove = inputManager.enablePSMove;
        psMoveIP     = inputManager.PSMoveIP;
        psMovePort   = inputManager.PSMovePort;

        jumpGesture = FindObjectOfType(typeof(RUISJumpGestureRecognizer)) as RUISJumpGestureRecognizer;

        displayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;
        riftDisplay    = displayManager.GetOculusRiftDisplay();

        // TODO: This menu should work with any stereo view, not just Rift. riftDisplay.linkedCamera is null when Rift is disabled.
        if (oculusRiftMenu && riftDisplay && riftDisplay.linkedCamera)
        {
            windowRect = new Rect(riftDisplay.linkedCamera.leftCamera.pixelRect.x
                                  + riftDisplay.resolutionX / 4 - 100, riftDisplay.resolutionY / 2 - 220, 250, 250);
        }

        SaveInputChanges();
    }
コード例 #8
0
    void Awake()
    {
        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
        stabilizingCollider = GetComponentInChildren<RUISCharacterStabilizingCollider>();
		lastJumpTime = 0;
		skeletonController = gameObject.GetComponentInChildren<RUISSkeletonController>();
    }
コード例 #9
0
ファイル: RUISMouseWand.cs プロジェクト: Leejunhee17/HRP
    public void Start()
    {
        displayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;

        distanceFromCameraLerped = distanceFromCamera;

        if (disableIfOtherDevices)
        {
            RUISInputManager inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
            if (inputManager)
            {
                bool   otherDevices = false;
                string deviceNames  = "";
                if (inputManager.enableKinect)
                {
                    deviceNames += "Kinect 1";
                    otherDevices = true;
                }
                if (inputManager.enableKinect2)
                {
                    deviceNames += "Kinect 2";
                    otherDevices = true;
                }
                if (inputManager.enableRazerHydra)
                {
                    if (deviceNames.Length > 0)
                    {
                        deviceNames += ", ";
                    }
                    deviceNames += "Razer Hydra";
                    otherDevices = true;
                }

                if (inputManager.enablePSMove)
                {
                    if (deviceNames.Length > 0)
                    {
                        deviceNames += ", ";
                    }
                    deviceNames += "PS Move";
                    otherDevices = true;
                }
                if (otherDevices)
                {
                    Debug.Log("Disabling MouseWand GameObject '" + gameObject.name + "' because the "
                              + "following input devices were found: " + deviceNames);
                    gameObject.SetActive(false);
                }
            }
        }

        if (!displayManager)
        {
            Debug.LogError("RUISMouseWand requires a RUISDisplayManager in the scene!");
        }
    }
コード例 #10
0
ファイル: RespawnObject.cs プロジェクト: mauromina/Ensayo
    void Start()
    {
        RUISInputManager inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        if (inputManager)
        {
            //RUISPSMoveWand[] moveWands = inputManager.GetComponentsInChildren<RUISPSMoveWand>();
            //foreach(RUISPSMoveWand wand in moveWands)
            //{
            //	if(moveID == wand.controllerId)
            //		moveWand = wand;
            //}
        }
        rigidBody = this.gameObject.GetComponent <Rigidbody>();
    }
コード例 #11
0
ファイル: RUISSkeletonWand.cs プロジェクト: mauromina/Ensayo
    public void Start()
    {
        RUISInputManager          inputManager          = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        RUISHoldGestureRecognizer holdGestureRecognizer = GetComponent <RUISHoldGestureRecognizer>();

        if (inputManager)
        {
            if (switchToAvailableKinect)
            {
                if (bodyTrackingDevice == RUISSkeletonController.bodyTrackingDeviceType.Kinect1 &&
                    !inputManager.enableKinect && inputManager.enableKinect2)
                {
                    bodyTrackingDevice = RUISSkeletonController.bodyTrackingDeviceType.Kinect2;
                }
                else if (bodyTrackingDevice == RUISSkeletonController.bodyTrackingDeviceType.Kinect2 &&
                         !inputManager.enableKinect2 && inputManager.enableKinect)
                {
                    bodyTrackingDevice = RUISSkeletonController.bodyTrackingDeviceType.Kinect1;

                    if (gestureRecognizer != holdGestureRecognizer)                    // Switching to the only selection gesture that RUIS has for Kinect 1
                    {
                        gestureRecognizer.enabled     = false;
                        holdGestureRecognizer.enabled = true;
                        gestureRecognizer             = holdGestureRecognizer;
                        Debug.LogWarning("Switched gesture recognizer of '" + name + "' to " + typeof(RUISHoldGestureRecognizer) + " because "
                                         + "Kinect 1 is enabled instead of Kinect 2, and at the moment that is the only supported Kinect 1 gesture.");
                        gestureSelectionScriptName = holdGestureRecognizer.ToString();
                    }
                }
                else if (!inputManager.enableKinect2 && !inputManager.enableKinect)
                {
                    Debug.LogWarning("Kinect 1 and 2 are not enabled in RUIS InputManager, disabling Skeleton Wand gameobject '" + name + "'.");
                    gameObject.SetActive(false);
                }
                bodyTrackingDeviceID = (int)bodyTrackingDevice;
            }
        }
        if (gestureRecognizer == holdGestureRecognizer)
        {
            wandSelector.toggleSelection     = true;
            wandSelector.grabWhileButtonDown = false;
        }
        else
        {
            showVisualizer = false;             // HACK: this is mainly for RUISFistGestureRecognizer. If other gestures are added, comment this line
        }
    }
コード例 #12
0
    void Awake()
    {
        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        playerManager   = GetComponent <NIPlayerManager>();
        RUISKinect2Data = GetComponent <RUISKinect2Data>();

        if (!inputManager.enableKinect)
        {
            playerManager.enabled = false;
        }
        if (!inputManager.enableKinect2)
        {
            RUISKinect2Data.enabled = false;
        }

        if (coordinateSystem == null)
        {
            coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
        }

        for (int x = 0; x < 3; x++)         // Kinect 1, Kinect 2, Custom Tracker
        {
            for (int i = 0; i < 6; i++)
            {
                skeletons [x, i] = new Skeleton();

                // HACK  for filtering Kinect 2 arm rotations
                if (x == kinect2SensorID)
                {
                    for (int k = 0; k < skeletons[x, i].filterRot.Length; ++k)
                    {
                        skeletons[x, i].filterRot[k] = new KalmanFilteredRotation();
                        skeletons[x, i].filterRot[k].skipIdenticalMeasurements = true;
                        skeletons[x, i].filterRot[k].rotationNoiseCovariance   = skeletons[x, i].rotationNoiseCovariance;
                        skeletons[x, i].previousRotation[k] = Quaternion.identity;
                    }
                }
            }
        }

        isNewKinect2Frame         = false;
        timeSinceLastKinect2Frame = 0;
    }
コード例 #13
0
    void Start()
    {
        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        if (useRazerHydra && inputManager && !inputManager.enableRazerHydra)
        {
            useRazerHydra = false;
            Debug.LogWarning("Your settings indicate that you want to use Razer Hydra for "
                             + "character locomotion controls, but you have disabled Razer "
                             + "Hydra from RUIS InputManager.");
        }

        if (usePSNavigationController && inputManager && !inputManager.enablePSMove)
        {
            usePSNavigationController = false;
            Debug.LogWarning("Your settings indicate that you want to use PS Navigation "
                             + "controller for character locomotion controls, but you have "
                             + "disabled PS Move from RUIS InputManager.");
        }
    }
コード例 #14
0
ファイル: XmlImportExport.cs プロジェクト: qipa/NordeusNinja
    public static bool ImportInputManager(RUISInputManager inputManager, string filename, TextAsset xmlSchema)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, xmlSchema);

        if (xmlDoc == null)
        {
            return(false);
        }

        XmlNode psMoveNode = xmlDoc.GetElementsByTagName("PSMoveSettings").Item(0);

        inputManager.enablePSMove                    = bool.Parse(psMoveNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.PSMoveIP                        = psMoveNode.SelectSingleNode("ip").Attributes["value"].Value;
        inputManager.PSMovePort                      = int.Parse(psMoveNode.SelectSingleNode("port").Attributes["value"].Value);
        inputManager.connectToPSMoveOnStartup        = bool.Parse(psMoveNode.SelectSingleNode("autoConnect").Attributes["value"].Value);
        inputManager.enableMoveCalibrationDuringPlay = bool.Parse(psMoveNode.SelectSingleNode("enableInGameCalibration").Attributes["value"].Value);
        inputManager.amountOfPSMoveControllers       = int.Parse(psMoveNode.SelectSingleNode("maxControllers").Attributes["value"].Value);

        XmlNode kinectNode = xmlDoc.GetElementsByTagName("KinectSettings").Item(0);

        inputManager.enableKinect             = bool.Parse(kinectNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.maxNumberOfKinectPlayers = int.Parse(kinectNode.SelectSingleNode("maxPlayers").Attributes["value"].Value);
        inputManager.kinectFloorDetection     = bool.Parse(kinectNode.SelectSingleNode("floorDetection").Attributes["value"].Value);
        inputManager.jumpGestureEnabled       = bool.Parse(kinectNode.SelectSingleNode("jumpGestureEnabled").Attributes["value"].Value);

        XmlNode kinect2Node = xmlDoc.GetElementsByTagName("Kinect2Settings").Item(0);

        inputManager.enableKinect2 = bool.Parse(kinect2Node.SelectSingleNode("enabled").Attributes["value"].Value);

        XmlNode razerNode = xmlDoc.GetElementsByTagName("RazerSettings").Item(0);

        inputManager.enableRazerHydra = bool.Parse(razerNode.SelectSingleNode("enabled").Attributes["value"].Value);

        XmlNode riftDriftNode = xmlDoc.GetElementsByTagName("OculusDriftSettings").Item(0);

//		string magnetometerMode = riftDriftNode.SelectSingleNode("magnetometerDriftCorrection").Attributes["value"].Value;
        //inputManager.riftMagnetometerMode = (RUISInputManager.RiftMagnetometer)System.Enum.Parse(typeof(RUISInputManager.RiftMagnetometer), magnetometerMode);
        inputManager.kinectDriftCorrectionPreferred = bool.Parse(riftDriftNode.SelectSingleNode("kinectDriftCorrectionIfAvailable").Attributes["value"].Value);

        return(true);
    }
コード例 #15
0
    void Awake()
    {
        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        if (inputManager)
        {
            if (switchToAvailableKinect)
            {
                if (bodyTrackingDevice == bodyTrackingDeviceType.Kinect1 &&
                    !inputManager.enableKinect && inputManager.enableKinect2)
                {
                    bodyTrackingDevice = bodyTrackingDeviceType.Kinect2;
                }
                else if (bodyTrackingDevice == bodyTrackingDeviceType.Kinect2 &&
                         !inputManager.enableKinect2 && inputManager.enableKinect)
                {
                    bodyTrackingDevice = bodyTrackingDeviceType.Kinect1;
                }
            }
        }

        coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;

        if (bodyTrackingDevice == bodyTrackingDeviceType.Kinect1)
        {
            bodyTrackingDeviceID = RUISSkeletonManager.kinect1SensorID;
        }
        if (bodyTrackingDevice == bodyTrackingDeviceType.Kinect2)
        {
            bodyTrackingDeviceID = RUISSkeletonManager.kinect2SensorID;
        }
        if (bodyTrackingDevice == bodyTrackingDeviceType.GenericMotionTracker)
        {
            bodyTrackingDeviceID = RUISSkeletonManager.customSensorID;
        }

        positionKalman = new KalmanFilter();
        positionKalman.initialize(3, 3);
    }
コード例 #16
0
    public void Start()
    {
        RUISInputManager inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        if (inputManager)
        {
            if (switchToAvailableKinect)
            {
                if (bodyTrackingDevice == RUISSkeletonController.bodyTrackingDeviceType.Kinect1 &&
                    !inputManager.enableKinect && inputManager.enableKinect2)
                {
                    bodyTrackingDevice = RUISSkeletonController.bodyTrackingDeviceType.Kinect2;
                }
                else if (bodyTrackingDevice == RUISSkeletonController.bodyTrackingDeviceType.Kinect2 &&
                         !inputManager.enableKinect2 && inputManager.enableKinect)
                {
                    bodyTrackingDevice = RUISSkeletonController.bodyTrackingDeviceType.Kinect1;

                    RUISHoldGestureRecognizer holdGestureRecognizer = GetComponent <RUISHoldGestureRecognizer>();

                    if (gestureRecognizer != holdGestureRecognizer)
                    {
                        gestureRecognizer.enabled     = false;
                        holdGestureRecognizer.enabled = true;
                        gestureRecognizer             = holdGestureRecognizer;
                        Debug.LogWarning("Switched gesture recognizer of '" + name + "' to " + typeof(RUISHoldGestureRecognizer) + " because "
                                         + "Kinect 1 is enabled instead of Kinect 2, and at the moment that is the only supported Kinect 1 gesture.");
                        gestureSelectionScriptName = holdGestureRecognizer.ToString();
                    }
                }
                else if (!inputManager.enableKinect2 && !inputManager.enableKinect)
                {
                    Debug.LogWarning("Kinect 1 and 2 are not enabled in RUIS InputManager, disabling Skeleton Wand gameobject '" + name + "'.");
                    gameObject.SetActive(false);
                }
                bodyTrackingDeviceID = (int)bodyTrackingDevice;
            }
        }
    }
コード例 #17
0
//	Ovr.HmdType ovrHmdVersion; //06to08

    void Awake()
    {
        // BUTTONS
        // Phase: select and configure devices
        buttons.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Calibration").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Display Management").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Save Config & Restart Scene").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Discard Configuration").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Quit Application").gameObject);

        // Phase: key stone configuration
        buttons.Add(this.transform.Find("NGUIControls/Panel/keyStoneConfiguration/Button - Reset Keystoning").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/keyStoneConfiguration/Button - Save Configurations").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/keyStoneConfiguration/Button - Load Old Configurations").gameObject);
        buttons.Add(this.transform.Find("NGUIControls/Panel/keyStoneConfiguration/Button - End Display Editing").gameObject);

        // CHECKBOXES
        checkBoxes.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Kinect/Checkbox - Use Kinect").gameObject);
        checkBoxes.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Kinect2/Checkbox - Use Kinect 2").gameObject);
        checkBoxes.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Kinect/Checkbox - Use Kinect Drift Correction").gameObject);
        checkBoxes.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/PSMove/Checkbox - Use PSMove").gameObject);
        checkBoxes.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Hydra/Checkbox - Use Hydra").gameObject);

        // TEXTFIELDS
        textFields.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/PSMove/Input - PSMove Port").gameObject);
        textFields.Add(this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/PSMove/Input - PSMove IP").gameObject);

        inputManager     = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        displayManager   = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;
        coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;

        kinectOrigGUIPos   = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Kinect").transform.localPosition;
        kinect2OrigGUIPos  = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Kinect2").transform.localPosition;
        hydraOrigGUIPos    = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Hydra").transform.localPosition;
        infotextOrigGUIPos = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Infotexts").transform.localPosition;
//		psMoveOrigGUIPos = this.transform.Find  ("NGUIControls/Panel/selectAndConfigureDevices/PSMove").transform.localPosition;
//		buttonsOrigGUIPos = this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons").transform.localPosition;
    }
コード例 #18
0
ファイル: RUISMouseWand.cs プロジェクト: mauromina/Ensayo
    public void Start()
    {
        displayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;

        distanceFromCameraLerped = distanceFromCamera;

        if (disableIfOtherDevices)
        {
            RUISInputManager inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
            if (inputManager)
            {
                bool   otherDevices = false;
                string deviceNames  = "";
                if (inputManager.enableKinect)
                {
                    deviceNames += "Kinect 1";
                    otherDevices = true;
                }
                if (inputManager.enableKinect2)
                {
                    deviceNames += "Kinect 2";
                    otherDevices = true;
                }
                if (inputManager.enableRazerHydra)
                {
                    if (deviceNames.Length > 0)
                    {
                        deviceNames += ", ";
                    }
                    deviceNames += "Razer Hydra";
                    otherDevices = true;
                }

                if (inputManager.enablePSMove)
                {
                    if (deviceNames.Length > 0)
                    {
                        deviceNames += ", ";
                    }
                    deviceNames += "PS Move";
                    otherDevices = true;
                }

                try
                {
                    var system = Valve.VR.OpenVR.System;
                    if (system != null)
                    {
                        for (int i = 0; i < Valve.VR.OpenVR.k_unMaxTrackedDeviceCount; ++i)
                        {
                            //SteamVR_Controller.Device device = SteamVR_Controller.Input(i);
                            //if(device != null && device.connected && device.valid && system.GetTrackedDeviceClass(device.index) == Valve.VR.ETrackedDeviceClass.Controller)
                            //{
                            //	if(deviceNames.Length > 0)
                            //		deviceNames += ", ";
                            //	deviceNames += "OpenVR controller";
                            //	otherDevices = true;
                            //	break;
                            //}
                        }
                    }
                } catch {}

                if (otherDevices)
                {
                    Debug.Log("Disabling MouseWand GameObject '" + gameObject.name + "' because the "
                              + "following input devices were found: " + deviceNames);
                    gameObject.SetActive(false);
                }
            }
        }

        if (!displayManager)
        {
            Debug.LogError("RUISMouseWand requires a RUISDisplayManager in the scene!");
        }
    }
コード例 #19
0
	void Awake() 
	{
		// BUTTONS
		// Phase: select and configure devices
		buttons.Add(this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Calibration").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Display Management").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Save Config & Restart Scene").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Discard Configuration").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons/Button - Quit Application").gameObject);
		
		// Phase: key stone configuration
		buttons.Add(this.transform.Find ("NGUIControls/Panel/keyStoneConfiguration/Button - Reset Keystoning").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/keyStoneConfiguration/Button - Save Configurations").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/keyStoneConfiguration/Button - Load Old Configurations").gameObject);
		buttons.Add(this.transform.Find ("NGUIControls/Panel/keyStoneConfiguration/Button - End Display Editing").gameObject);
		
		// CHECKBOXES
		checkBoxes.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Kinect/Checkbox - Use Kinect").gameObject);
		checkBoxes.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Kinect2/Checkbox - Use Kinect 2").gameObject);
		checkBoxes.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Kinect/Checkbox - Use Kinect Drift Correction").gameObject);
		checkBoxes.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/PSMove/Checkbox - Use PSMove").gameObject);
		checkBoxes.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Hydra/Checkbox - Use Hydra").gameObject);
		
		// TEXTFIELDS
		textFields.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/PSMove/Input - PSMove Port").gameObject);
		textFields.Add (this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/PSMove/Input - PSMove IP").gameObject);
		
		inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
		displayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;

		kinectOrigGUIPos = this.transform.Find ( "NGUIControls/Panel/selectAndConfigureDevices/Kinect").transform.localPosition;
		kinect2OrigGUIPos = this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Kinect2").transform.localPosition;
		hydraOrigGUIPos = this.transform.Find (  "NGUIControls/Panel/selectAndConfigureDevices/Hydra").transform.localPosition;
		infotextOrigGUIPos = this.transform.Find("NGUIControls/Panel/selectAndConfigureDevices/Infotexts").transform.localPosition;
//		psMoveOrigGUIPos = this.transform.Find  ("NGUIControls/Panel/selectAndConfigureDevices/PSMove").transform.localPosition;
//		buttonsOrigGUIPos = this.transform.Find ("NGUIControls/Panel/selectAndConfigureDevices/Buttons").transform.localPosition;
	}
	public RUISKinect2ToKinectCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) {
		
		this.inputDevice1 = RUISDevice.Kinect_2;
		this.inputDevice2 = RUISDevice.Kinect_1;
		
		this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake;
		this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;
		
		trackingIDs = new trackedBody[6]; 
		for(int y = 0; y < trackingIDs.Length; y++) {
			trackingIDs[y] = new trackedBody(-1, false, 1);
		}
		
		kinectSelection = MonoBehaviour.FindObjectOfType(typeof(NIPlayerManagerCOMSelection)) as NIPlayerManagerCOMSelection;
		settingsManager = MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;
		inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
		coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
		kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;
		
		this.timeSinceScriptStart = 0;
		this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond;
		
		// Limit sample rate
		if(this.timeBetweenSamples < 0.1f) {
			this.timeBetweenSamples = 0.1f;
		}
		
		calibrationSpheres = new List<GameObject>();
		
		samples_Kinect1 = new List<Vector3>();
		samples_Kinect2 = new List<Vector3>();
		
		this.calibrationCube = calibrationSettings.calibrationCubePrefab;
		this.calibrationSphere = calibrationSettings.calibrationSpherePrefab;
		this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects;
		this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;
		
		this.deviceModelObjects = calibrationSettings.deviceModelObjects;
		this.depthViewObjects = calibrationSettings.depthViewObjects;
		this.iconObjects = calibrationSettings.iconObjects;
		
		if(GameObject.Find ("PSMoveWand") != null)
			GameObject.Find ("PSMoveWand").SetActive(false);
		
		// Models
		this.kinect1ModelObject = GameObject.Find ("KinectCamera");
		this.kinect2ModelObject = GameObject.Find ("Kinect2Camera");
		
		RUISSkeletonController skeletonController = Component.FindObjectOfType<RUISSkeletonController>();
		Transform rightHand = null;
		if(skeletonController)
			rightHand = skeletonController.rightHand;
		FixedFollowTransform followTransform = Component.FindObjectOfType<FixedFollowTransform>();
		if(followTransform && rightHand)
			followTransform.transformToFollow = rightHand;
		
		// Depth view
		this.depthView = GameObject.Find ("KinectDepthView");
		this.depthView2 = GameObject.Find ("Kinect2DepthView");
		// Icons
		this.Kinect1Icon = GameObject.Find ("Kinect Icon");
		this.Kinect2Icon = GameObject.Find ("Kinect2 Icon");

		this.floorPlane = GameObject.Find ("Floor");

		if(this.Kinect1Icon && this.Kinect1Icon.GetComponent<GUITexture>())
			this.Kinect1Icon.GetComponent<GUITexture>().pixelInset = new Rect(5.1f, 10.0f, 70.0f, 70.0f);
		
		foreach (Transform child in this.deviceModelObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.depthViewObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.iconObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		if(this.kinect1ModelObject)
			this.kinect1ModelObject.SetActive(true);
		if(this.kinect2ModelObject)
			this.kinect2ModelObject.SetActive(true);
		if(this.Kinect1Icon)
			this.Kinect1Icon.SetActive(true);
		if(this.Kinect2Icon)
			this.Kinect2Icon.SetActive(true);
		if(this.calibrationPhaseObjects)
			this.calibrationPhaseObjects.SetActive(true);
		if(this.calibrationResultPhaseObjects)
			this.calibrationResultPhaseObjects.SetActive(false);
		if(this.depthView)
			this.depthView.SetActive(true);
		if(this.depthView2)
			this.depthView2.SetActive(true);
		this.xmlFilename = calibrationSettings.xmlFilename;
	}
コード例 #21
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;
                    }
                }
            }
        }
    }
コード例 #22
0
    void Awake()
    {
        string[] names = System.Enum.GetNames(typeof(RUISDevice));
        foreach (string device in names)
        {
            RUISDevice device1Enum = (RUISDevice)System.Enum.Parse(typeof(RUISDevice), device, true);
            RUISCalibrationResultsFloorPitchRotation[device1Enum] = Quaternion.identity;
            RUISCalibrationResultsDistanceFromFloor[device1Enum]  = 0.0f;
            foreach (string device2 in names)
            {
                if (device != device2)
                {
                    string devicePairString = device + "-" + device2;
                    RUISCalibrationResultsInVector3[devicePairString]    = new Vector3(0, 0, 0);
                    RUISCalibrationResultsInQuaternion[devicePairString] = Quaternion.identity;
                    RUISCalibrationResultsIn4x4Matrix[devicePairString]  = Matrix4x4.identity;
                }
            }
        }

        if (loadFromXML)
        {
            if (!LoadMultiXML(coordinateXmlFile))
            {
                createExampleXML(coordinateXmlFile);
            }
        }

        inputManager = FindObjectOfType <RUISInputManager>();
        if (switchToAvailableDevice && inputManager)
        {
            bool       needToSwitch   = false;
            RUISDevice previousDevice = rootDevice;

            switch (rootDevice)
            {
            case RUISDevice.Kinect_1:
                if (!inputManager.enableKinect)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.Kinect_2:
                if (!inputManager.enableKinect2)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.PS_Move:
                if (!inputManager.enablePSMove)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.Oculus_DK2:
                if (!isPositionTrackableRiftPresent())
                {
                    needToSwitch = true;
                }
                break;
            }

            if (needToSwitch)
            {
                if (inputManager.enableKinect2)
                {
                    rootDevice = RUISDevice.Kinect_2;
                }
                else if (inputManager.enableKinect)
                {
                    rootDevice = RUISDevice.Kinect_1;
                }
                else if (isPositionTrackableRiftPresent())
                {
                    rootDevice = RUISDevice.Oculus_DK2;
                }
                else if (inputManager.enablePSMove)
                {
                    rootDevice = RUISDevice.PS_Move;
                }

                if (rootDevice != previousDevice)
                {
                    if (previousDevice == RUISDevice.Oculus_DK2)
                    {
                        Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
                                         + "because Oculus Rift DK2+ was not detected!");
                    }
                    else
                    {
                        Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
                                         + "because the former was not enabled in " + typeof(RUISInputManager) + " while the latter was!");
                    }
                }
            }
        }
    }
コード例 #23
0
    void Awake()
    {
        string[] names = System.Enum.GetNames(typeof(RUISDevice));
        foreach (string device in names)
        {
            RUISDevice device1Enum = (RUISDevice)System.Enum.Parse(typeof(RUISDevice), device, true);
            RUISCalibrationResultsFloorPitchRotation[device1Enum] = Quaternion.identity;
            RUISCalibrationResultsDistanceFromFloor[device1Enum]  = 0.0f;
            foreach (string device2 in names)
            {
                if (device != device2)
                {
                    string devicePairString = device + "-" + device2;
                    RUISCalibrationResultsInVector3[devicePairString]    = new Vector3(0, 0, 0);
                    RUISCalibrationResultsInQuaternion[devicePairString] = Quaternion.identity;
                    RUISCalibrationResultsIn4x4Matrix[devicePairString]  = Matrix4x4.identity;
                }
            }
        }

        if (loadFromXML)
        {
            if (!LoadMultiXML(coordinateXmlFile))
            {
                createExampleXML(coordinateXmlFile);
            }
        }

        inputManager = FindObjectOfType <RUISInputManager>();
        if (switchToAvailableDevice && inputManager)
        {
            bool       needToSwitch   = false;
            RUISDevice previousDevice = rootDevice;

            switch (rootDevice)
            {
            case RUISDevice.Kinect_1:
                if (!inputManager.enableKinect)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.Kinect_2:
                if (!inputManager.enableKinect2)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.PS_Move:
                if (!inputManager.enablePSMove)
                {
                    needToSwitch = true;
                }
                break;

            case RUISDevice.OpenVR:             // If OpenVR can't accessed AND a HMD can't be detected
                if (!RUISDisplayManager.IsOpenVrAccessible() && !RUISDisplayManager.IsHmdPresent())
                {
                    needToSwitch = true;
                }
                break;
            }

            if (needToSwitch)
            {
                // Try to determine if Kinect2 can be used (because this method is run before RUISInputManager can disable enableKinect2)
                bool kinect2FoundBySystem = false;
                if (inputManager.enableKinect2)
                {
                    try
                    {
                        Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;
                        if (kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen)
                        {
                            // IsOpen seems to return false mostly if Kinect 2 drivers are not installed?
                            //					Debug.Log("Kinect 2 was detected by the system.");
                            kinect2FoundBySystem = true;
                        }
                    }
                    catch
                    {}
                }

                if (RUISDisplayManager.IsHmdPositionTrackable())
                {
                    rootDevice = RUISDevice.OpenVR;
                }
                else if (inputManager.enableKinect2 && kinect2FoundBySystem)
                {
                    rootDevice = RUISDevice.Kinect_2;
                }
                else if (inputManager.enableKinect)
                {
                    rootDevice = RUISDevice.Kinect_1;
                }
                else if (inputManager.enablePSMove)
                {
                    rootDevice = RUISDevice.PS_Move;
                }

                if (rootDevice != previousDevice)
                {
                    if (previousDevice == RUISDevice.OpenVR)
                    {
                        Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
                                         + "because OpenVR could not be accessed! Is SteamVR installed?");
                    }
                    else
                    {
                        Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
                                         + "because the former was not enabled in " + typeof(RUISInputManager) + " while the latter was!");
                    }
                }
            }
        }
    }
コード例 #24
0
    public RUISKinectToOculusDK2CalibrationProcess(RUISCalibrationProcessSettings calibrationSettings)
    {
        this.inputDevice1 = RUISDevice.Oculus_DK2;
        this.inputDevice2 = RUISDevice.Kinect_1;

        this.numberOfSamplesToTake    = calibrationSettings.numberOfSamplesToTake;
        this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;

        trackingIDs = new trackedBody[6];
        for (int y = 0; y < trackingIDs.Length; y++)
        {
            trackingIDs[y] = new trackedBody(-1, false, 1);
        }

        inputManager     = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
        kinectSelection  = MonoBehaviour.FindObjectOfType(typeof(NIPlayerManagerCOMSelection)) as NIPlayerManagerCOMSelection;
        settingsManager  = MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;

        this.timeSinceScriptStart = 0;
        this.timeBetweenSamples   = 1 / (float)numberOfSamplesPerSecond;

        // Limit sample rate
        if (this.timeBetweenSamples < 0.1f)
        {
            this.timeBetweenSamples = 0.1f;
        }

        calibrationSpheres = new List <GameObject>();

        samples_Kinect1   = new List <Vector3>();
        samples_OculusDK2 = new List <Vector3>();

        this.calibrationCube               = calibrationSettings.calibrationCubePrefab;
        this.calibrationSphere             = calibrationSettings.calibrationSpherePrefab;
        this.calibrationPhaseObjects       = calibrationSettings.calibrationPhaseObjects;
        this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;

        this.deviceModelObjects = calibrationSettings.deviceModelObjects;
        this.depthViewObjects   = calibrationSettings.depthViewObjects;
        this.iconObjects        = calibrationSettings.iconObjects;


        if (GameObject.Find("PSMoveWand") != null)
        {
            GameObject.Find("PSMoveWand").SetActive(false);
        }

        // Models
        this.oculusDK2CameraObject = GameObject.Find("OculusDK2Camera");
        this.kinect1ModelObject    = GameObject.Find("KinectCamera");
        this.oculusRiftModel       = GameObject.Find("OculusRift");

        FixedFollowTransform followTransform = Component.FindObjectOfType <FixedFollowTransform>();

        if (followTransform && this.oculusRiftModel)
        {
            followTransform.transformToFollow = this.oculusRiftModel.transform;
        }

        // Depth view
        this.depthView = GameObject.Find("KinectDepthView");

        // Icons
        this.oculusDK2Icon = GameObject.Find("OculusDK2 Icon");
        this.kinectIcon    = GameObject.Find("Kinect Icon");

        this.floorPlane = GameObject.Find("Floor");

        if (this.oculusDK2Icon && this.oculusDK2Icon.GetComponent <GUITexture>())
        {
            this.oculusDK2Icon.GetComponent <GUITexture>().pixelInset = new Rect(5.1f, 10.0f, 70.0f, 70.0f);
        }

        foreach (Transform child in this.deviceModelObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.depthViewObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.iconObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        if (this.oculusDK2CameraObject)
        {
            this.oculusDK2CameraObject.SetActive(true);
        }
        if (this.kinect1ModelObject)
        {
            this.kinect1ModelObject.SetActive(true);
        }
        if (this.oculusRiftModel)
        {
            this.oculusRiftModel.SetActive(true);
        }
        if (this.oculusDK2Icon)
        {
            this.oculusDK2Icon.SetActive(true);
        }
        if (this.kinectIcon)
        {
            this.kinectIcon.SetActive(true);
        }
        if (this.calibrationPhaseObjects)
        {
            this.calibrationPhaseObjects.SetActive(true);
        }
        if (this.calibrationResultPhaseObjects)
        {
            this.calibrationResultPhaseObjects.SetActive(false);
        }
        if (this.depthView)
        {
            this.depthView.SetActive(true);
        }
        this.xmlFilename = calibrationSettings.xmlFilename;
    }
コード例 #25
0
	void Awake() 
	{
		string[] names = System.Enum.GetNames( typeof( RUISDevice ) );
		foreach(string device in names) {
			RUISDevice device1Enum = (RUISDevice) System.Enum.Parse( typeof(RUISDevice), device, true );
			RUISCalibrationResultsFloorPitchRotation[device1Enum] = Quaternion.identity;
			RUISCalibrationResultsDistanceFromFloor[device1Enum] = 0.0f;
			foreach(string device2 in names) {
				if(device != device2) {
					string devicePairString = device + "-" + device2;
					RUISCalibrationResultsInVector3[devicePairString] = new Vector3(0,0,0);
					RUISCalibrationResultsInQuaternion[devicePairString] = Quaternion.identity;
					RUISCalibrationResultsIn4x4Matrix[devicePairString] = Matrix4x4.identity;
				}
			}
		}
		
		if (loadFromXML)
		{
			if(!LoadMultiXML(coordinateXmlFile)) {
				createExampleXML(coordinateXmlFile);
			}
		}

		inputManager = FindObjectOfType<RUISInputManager>();
		if(switchToAvailableDevice && inputManager)
		{
			bool needToSwitch = false;
			RUISDevice previousDevice = rootDevice;

			switch(rootDevice)
			{
				case RUISDevice.Kinect_1:
					if(!inputManager.enableKinect)
						needToSwitch = true;
					break;
				case RUISDevice.Kinect_2:
					if(!inputManager.enableKinect2)
						needToSwitch = true;
					break;
				case RUISDevice.PS_Move:
					if(!inputManager.enablePSMove)
						needToSwitch = true;
					break;
				case RUISDevice.Oculus_DK2:
					if(!isPositionTrackableRiftPresent())
						needToSwitch = true;
				break;
			}

			if(needToSwitch)
			{
				if(inputManager.enableKinect2)
					rootDevice = RUISDevice.Kinect_2;
				else if(inputManager.enableKinect)
					rootDevice = RUISDevice.Kinect_1;
				else if(isPositionTrackableRiftPresent())
					rootDevice = RUISDevice.Oculus_DK2;
				else if(inputManager.enablePSMove)
					rootDevice = RUISDevice.PS_Move;

				if(rootDevice != previousDevice)
				{
					if(previousDevice == RUISDevice.Oculus_DK2)
						Debug.LogWarning(  "Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
						                 + "because Oculus Rift DK2+ was not detected!");
					else
						Debug.LogWarning(  "Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " "
						                 + "because the former was not enabled in " + typeof(RUISInputManager) + " while the latter was!");
				}
			}
		}
	}
コード例 #26
0
//	Quaternion kinect1PitchRotation = Quaternion.identity;

    public RUISPSMoveToOculusDK2CalibrationProcess(RUISCalibrationProcessSettings calibrationSettings)
    {
        this.inputDevice1 = RUISDevice.Oculus_DK2;
        this.inputDevice2 = RUISDevice.PS_Move;

        this.numberOfSamplesToTake    = calibrationSettings.numberOfSamplesToTake;
        this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;

        psMoveWrapper    = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
        inputManager     = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;


        this.timeSinceScriptStart = 0;
        this.timeBetweenSamples   = 1 / (float)numberOfSamplesPerSecond;

        // Limit sample rate
        if (this.timeBetweenSamples < 0.1f)
        {
            this.timeBetweenSamples = 0.1f;
        }

        calibrationSpheres = new List <GameObject>();

        samples_PSMove    = new List <Vector3>();
        samples_OculusDK2 = new List <Vector3>();

        this.calibrationCube               = calibrationSettings.calibrationCubePrefab;
        this.calibrationSphere             = calibrationSettings.calibrationSpherePrefab;
        this.calibrationPhaseObjects       = calibrationSettings.calibrationPhaseObjects;
        this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;

        this.deviceModelObjects = calibrationSettings.deviceModelObjects;
        this.depthViewObjects   = calibrationSettings.depthViewObjects;
        this.iconObjects        = calibrationSettings.iconObjects;

        this.PSMoveWandObject = GameObject.Find("PSMoveWand");
        this.mannequin        = GameObject.Find("Mannequin");

        // Models
        this.psEyeModelObject      = GameObject.Find("PS Eye");
        this.oculusDK2CameraObject = GameObject.Find("OculusDK2Camera");
        this.oculusRiftModel       = GameObject.Find("OculusRift");

        // Icons
        this.psMoveIcon    = GameObject.Find("PS Move Icon");
        this.oculusDK2Icon = GameObject.Find("OculusDK2 Icon");

//		this.floorPlane = GameObject.Find ("Floor");

        foreach (Transform child in this.deviceModelObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.depthViewObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.iconObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        if (this.mannequin)
        {
            this.mannequin.SetActive(false);
        }
        if (this.psEyeModelObject)
        {
            this.psEyeModelObject.SetActive(true);
        }
        if (this.PSMoveWandObject)
        {
            this.PSMoveWandObject.SetActive(true);
        }
        if (this.oculusRiftModel)
        {
            this.oculusRiftModel.SetActive(true);
        }
        if (this.oculusDK2CameraObject)
        {
            this.oculusDK2CameraObject.SetActive(true);
        }
        if (this.psMoveIcon)
        {
            this.psMoveIcon.SetActive(true);
        }
        if (this.oculusDK2Icon)
        {
            this.oculusDK2Icon.SetActive(true);
        }
        if (this.calibrationPhaseObjects)
        {
            this.calibrationPhaseObjects.SetActive(true);
        }
        if (this.calibrationResultPhaseObjects)
        {
            this.calibrationResultPhaseObjects.SetActive(false);
        }
        this.xmlFilename = calibrationSettings.xmlFilename;
    }
コード例 #27
0
ファイル: RUISMenu.cs プロジェクト: Zerphed/miscellaneous
    // Use this for initialization
    void Start()
    {
        try
        {
            Input.GetButtonDown("RUISMenu");
        }
        catch (UnityException)
        {
            ruisMenuButtonDefined = false;
        }

        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        enablePSMove = inputManager.enablePSMove;
        psMoveIP = inputManager.PSMoveIP;
        psMovePort = inputManager.PSMovePort;

        jumpGesture = FindObjectOfType(typeof(RUISJumpGestureRecognizer)) as RUISJumpGestureRecognizer;

        displayManager = FindObjectOfType(typeof(RUISDisplayManager)) as RUISDisplayManager;
        riftDisplay = displayManager.GetOculusRiftDisplay();

        // TODO: This menu should work with any stereo view, not just Rift. riftDisplay.linkedCamera is null when Rift is disabled.
        if (oculusRiftMenu && riftDisplay && riftDisplay.linkedCamera )
        {
            windowRect = new Rect(riftDisplay.linkedCamera.leftCamera.pixelRect.x
                                    + riftDisplay.resolutionX / 4 - 100, riftDisplay.resolutionY / 2 - 220, 250, 250);
        }

        SaveInputChanges();
    }
コード例 #28
0
 void Awake()
 {
     inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
 }
コード例 #29
0
ファイル: XmlImportExport.cs プロジェクト: mauromina/Ensayo
    public static bool ImportInputManager(RUISInputManager inputManager, RUISCoordinateSystem coordinateSystem, string filename, TextAsset xmlSchema)
    {
        XmlDocument xmlDoc = XMLUtil.LoadAndValidateXml(filename, xmlSchema);

        if (xmlDoc == null)
        {
            return(false);
        }

        XmlNode psMoveNode = xmlDoc.GetElementsByTagName("PSMoveSettings").Item(0);

        inputManager.enablePSMove                    = bool.Parse(psMoveNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.PSMoveIP                        = psMoveNode.SelectSingleNode("ip").Attributes["value"].Value;
        inputManager.PSMovePort                      = int.Parse(psMoveNode.SelectSingleNode("port").Attributes["value"].Value);
        inputManager.connectToPSMoveOnStartup        = bool.Parse(psMoveNode.SelectSingleNode("autoConnect").Attributes["value"].Value);
        inputManager.enableMoveCalibrationDuringPlay = bool.Parse(psMoveNode.SelectSingleNode("enableInGameCalibration").Attributes["value"].Value);
        inputManager.amountOfPSMoveControllers       = int.Parse(psMoveNode.SelectSingleNode("maxControllers").Attributes["value"].Value);

        XmlNode kinectNode = xmlDoc.GetElementsByTagName("KinectSettings").Item(0);

        inputManager.enableKinect             = bool.Parse(kinectNode.SelectSingleNode("enabled").Attributes["value"].Value);
        inputManager.maxNumberOfKinectPlayers = int.Parse(kinectNode.SelectSingleNode("maxPlayers").Attributes["value"].Value);
        inputManager.kinectFloorDetection     = bool.Parse(kinectNode.SelectSingleNode("floorDetection").Attributes["value"].Value);
        inputManager.jumpGestureEnabled       = bool.Parse(kinectNode.SelectSingleNode("jumpGestureEnabled").Attributes["value"].Value);

        XmlNode kinect2Node = xmlDoc.GetElementsByTagName("Kinect2Settings").Item(0);

        inputManager.enableKinect2 = bool.Parse(kinect2Node.SelectSingleNode("enabled").Attributes["value"].Value);

        XmlNode razerNode = xmlDoc.GetElementsByTagName("RazerSettings").Item(0);

        inputManager.enableRazerHydra = bool.Parse(razerNode.SelectSingleNode("enabled").Attributes["value"].Value);

//		XmlNode riftDriftNode = xmlDoc.GetElementsByTagName("OculusDriftSettings").Item(0);
//		string magnetometerMode = riftDriftNode.SelectSingleNode("magnetometerDriftCorrection").Attributes["value"].Value;
//		inputManager.riftMagnetometerMode = (RUISInputManager.RiftMagnetometer)System.Enum.Parse(typeof(RUISInputManager.RiftMagnetometer), magnetometerMode);
//		inputManager.kinectDriftCorrectionPreferred = bool.Parse(riftDriftNode.SelectSingleNode("kinectDriftCorrectionIfAvailable").Attributes["value"].Value);

        XmlNode coordinateSystemNode = xmlDoc.GetElementsByTagName("CoordinateSystemSettings").Item(0);

        if (coordinateSystemNode != null)
        {
            if (coordinateSystemNode.SelectSingleNode("useMasterCoordinateSystem") != null)
            {
                coordinateSystem.applyToRootCoordinates = bool.Parse(coordinateSystemNode.SelectSingleNode("useMasterCoordinateSystem").Attributes["value"].Value);
            }
            if (coordinateSystemNode.SelectSingleNode("masterCoordinateSystemSensor") != null)
            {
                string masterDevice = coordinateSystemNode.SelectSingleNode("masterCoordinateSystemSensor").Attributes["value"].Value;
                coordinateSystem.rootDevice = (RUISDevice)System.Enum.Parse(typeof(RUISDevice), masterDevice);
            }
            if (coordinateSystemNode.SelectSingleNode("switchMasterToAvailableSensor") != null)
            {
                coordinateSystem.switchToAvailableDevice = bool.Parse(coordinateSystemNode.SelectSingleNode("switchMasterToAvailableSensor").Attributes["value"].Value);
            }
            if (coordinateSystemNode.SelectSingleNode("setKinectOriginToFloor") != null)
            {
                coordinateSystem.setKinectOriginToFloor = bool.Parse(coordinateSystemNode.SelectSingleNode("setKinectOriginToFloor").Attributes["value"].Value);
            }
            if (coordinateSystemNode.SelectSingleNode("coordinateSystemYRotationOffset") != null)
            {
                coordinateSystem.yawOffset = float.Parse(coordinateSystemNode.SelectSingleNode("coordinateSystemYRotationOffset").Attributes["value"].Value);
            }

            if (coordinateSystemNode.SelectSingleNode("coordinateSystemLocationOffset") != null)
            {
                XmlNode translationElement = coordinateSystemNode.SelectSingleNode("coordinateSystemLocationOffset");
                float   x = float.Parse(translationElement.Attributes["x"].Value);
                float   y = float.Parse(translationElement.Attributes["y"].Value);
                float   z = float.Parse(translationElement.Attributes["z"].Value);
                coordinateSystem.positionOffset = new Vector3(x, y, z);
            }
        }

        return(true);
    }
コード例 #30
0
    public static bool ExportInputManager(RUISInputManager inputManager, string filename)
    {
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");

        XmlElement inputManagerRootElement = xmlDoc.CreateElement("ns2", "RUISInputManager", "http://ruisystem.net/RUISInputManager");
        xmlDoc.AppendChild(inputManagerRootElement);

        XmlComment booleanComment = xmlDoc.CreateComment("Boolean values always with a lower case, e.g. \"true\" or \"false\"");
        inputManagerRootElement.AppendChild(booleanComment);

        XmlElement psMoveSettingsElement = xmlDoc.CreateElement("PSMoveSettings");
        inputManagerRootElement.AppendChild(psMoveSettingsElement);

        XmlElement psMoveEnabledElement = xmlDoc.CreateElement("enabled");
        psMoveEnabledElement.SetAttribute("value", inputManager.enablePSMove.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveEnabledElement);

        XmlElement psMoveIPElement = xmlDoc.CreateElement("ip");
        psMoveIPElement.SetAttribute("value", inputManager.PSMoveIP.ToString());
        psMoveSettingsElement.AppendChild(psMoveIPElement);

        XmlElement psMovePortElement = xmlDoc.CreateElement("port");
        psMovePortElement.SetAttribute("value", inputManager.PSMovePort.ToString());
        psMoveSettingsElement.AppendChild(psMovePortElement);

        XmlElement psMoveAutoConnectElement = xmlDoc.CreateElement("autoConnect");
        psMoveAutoConnectElement.SetAttribute("value", inputManager.connectToPSMoveOnStartup.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveAutoConnectElement);

        XmlElement psMoveEnableInGameCalibration = xmlDoc.CreateElement("enableInGameCalibration");
        psMoveEnableInGameCalibration.SetAttribute("value", inputManager.enableMoveCalibrationDuringPlay.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveEnableInGameCalibration);

        XmlElement psMoveMaxControllersElement = xmlDoc.CreateElement("maxControllers");
        psMoveMaxControllersElement.SetAttribute("value", inputManager.amountOfPSMoveControllers.ToString());
        psMoveSettingsElement.AppendChild(psMoveMaxControllersElement);

        XmlElement kinectSettingsElement = xmlDoc.CreateElement("KinectSettings");
        inputManagerRootElement.AppendChild(kinectSettingsElement);

        XmlElement kinectEnabledElement = xmlDoc.CreateElement("enabled");
        kinectEnabledElement.SetAttribute("value", inputManager.enableKinect.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(kinectEnabledElement);

        XmlElement maxKinectPlayersElement = xmlDoc.CreateElement("maxPlayers");
        maxKinectPlayersElement.SetAttribute("value", inputManager.maxNumberOfKinectPlayers.ToString());
        kinectSettingsElement.AppendChild(maxKinectPlayersElement);

        XmlElement kinectFloorDetectionElement = xmlDoc.CreateElement("floorDetection");
        kinectFloorDetectionElement.SetAttribute("value", inputManager.kinectFloorDetection.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(kinectFloorDetectionElement);

        XmlElement jumpGestureElement = xmlDoc.CreateElement("jumpGestureEnabled");
        jumpGestureElement.SetAttribute("value", inputManager.jumpGestureEnabled.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(jumpGestureElement);

        XmlElement kinect2SettingsElement = xmlDoc.CreateElement("Kinect2Settings");
        inputManagerRootElement.AppendChild(kinect2SettingsElement);

        XmlElement kinect2EnabledElement = xmlDoc.CreateElement("enabled");
        kinect2EnabledElement.SetAttribute("value", inputManager.enableKinect2.ToString().ToLowerInvariant());
        kinect2SettingsElement.AppendChild(kinect2EnabledElement);

        XmlElement kinect2FloorDetectionElement = xmlDoc.CreateElement("floorDetection");
        kinect2FloorDetectionElement.SetAttribute("value", inputManager.kinect2FloorDetection.ToString().ToLowerInvariant());
        kinect2SettingsElement.AppendChild(kinect2FloorDetectionElement);

        XmlElement razerSettingsElement = xmlDoc.CreateElement("RazerSettings");
        inputManagerRootElement.AppendChild(razerSettingsElement);

        XmlElement razerEnabledElement = xmlDoc.CreateElement("enabled");
        razerEnabledElement.SetAttribute("value", inputManager.enableRazerHydra.ToString().ToLowerInvariant());
        razerSettingsElement.AppendChild(razerEnabledElement);

        XmlElement riftDriftSettingsElement = xmlDoc.CreateElement("OculusDriftSettings");
        inputManagerRootElement.AppendChild(riftDriftSettingsElement);

        //XmlElement magnetometerDriftCorrectionElement = xmlDoc.CreateElement("magnetometerDriftCorrection");
        //magnetometerDriftCorrectionElement.SetAttribute("value", System.Enum.GetName(typeof(RUISInputManager.RiftMagnetometer), inputManager.riftMagnetometerMode));
        //riftDriftSettingsElement.AppendChild(magnetometerDriftCorrectionElement);

        XmlElement kinectDriftCorrectionElement = xmlDoc.CreateElement("kinectDriftCorrectionIfAvailable");
        kinectDriftCorrectionElement.SetAttribute("value", inputManager.kinectDriftCorrectionPreferred.ToString().ToLowerInvariant());
        riftDriftSettingsElement.AppendChild(kinectDriftCorrectionElement);

        XMLUtil.SaveXmlToFile(filename, xmlDoc);

        return true;
    }
コード例 #31
0
    public void Start()
    {
        switch(compass)
        {
            case CompassSource.Kinect:
                if (!skeletonManager)
                {
                    skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
                }
                if(!skeletonManager)
                    Debug.LogError("RUISSkeletonManager script is missing from this scene!");
                break;
            case CompassSource.PSMove:
                inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
                if(!inputManager)
                    Debug.LogError("RUISInputManager script is missing from this scene!");
                break;
        }

        if(driftingSensor == DriftingRotation.InputTransform && !driftingTransform)
            Debug.LogError("driftingTransform is none, you need to set it from the inspector!");

        oculusCamController = FindObjectOfType(typeof(OVRCameraController)) as OVRCameraController;
    }
コード例 #32
0
ファイル: RUISTracker.cs プロジェクト: Zerphed/miscellaneous
    void Start()
    {
        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        if(		!inputManager
            &&  (	headPositionInput == HeadPositionSource.PSMove
                 || headRotationInput == HeadRotationSource.PSMove
                 || (externalDriftCorrection && compass == CompassSource.PSMove)))
            Debug.LogError("RUISInputManager script is missing from this scene!");

        if(inputManager && !inputManager.enablePSMove)
        {
            if(headPositionInput == HeadPositionSource.PSMove)
                Debug.LogError(	"Your settings indicate that you want to use PS Move for position "
                                 +	"tracking, but you have not enabled it from InputManager.");
            if(headRotationInput == HeadRotationSource.PSMove)
                Debug.LogError(	"Your settings indicate that you want to use PS Move for rotation "
                                 +	"tracking, but you have not enabled it from InputManager.");
            if(externalDriftCorrection && compass == CompassSource.PSMove)
                Debug.LogError(	"Your settings indicate that you want to use PS Move for yaw drift "
                                 +	"correction, but you have not enabled it from InputManager.");
        }

        if (!skeletonManager)
            skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
        if(		!skeletonManager
            &&  (	headPositionInput == HeadPositionSource.Kinect
                 || (headRotationInput == HeadRotationSource.Kinect && !useOculusRiftRotation)
                 || (externalDriftCorrection && compass == CompassSource.Kinect)))
        {
            Debug.LogError("RUISSkeletonManager script is missing from this scene!");
        }

        if(inputManager && !inputManager.enableRazerHydra)
        {
            if(headPositionInput == HeadPositionSource.RazerHydra)
                Debug.LogError(		"Your settings indicate that you want to use Razer Hydra for "
                                +	"position tracking, but you have disabled Razer Hydra from RUIS "
                                +	"InputManager.");
            if(headRotationInput == HeadRotationSource.RazerHydra)
                Debug.LogError(		"Your settings indicate that you want to use Razer Hydra for "
                                +	"rotation tracking, but you have disabled Razer Hydra from RUIS "
                                +	"InputManager.");
            if(externalDriftCorrection && compass == CompassSource.RazerHydra)
                Debug.LogError(		"Your settings indicate that you want to use Razer Hydra for "
                                +	"yaw drift correction, but you have disabled Razer Hydra from RUIS "
                                +	"InputManager.");
        }

        if(headPositionInput == HeadPositionSource.InputTransform && !positionInput)
            Debug.LogError("Position tracker's Input Transform is none, you need to set it in Unity inspector!");

        if(headRotationInput == HeadRotationSource.InputTransform && !rotationInput && !useOculusRiftRotation)
            Debug.LogError("Rotation tracker's Input Transform is none, you need to set it in Unity inspector!");

        if(headPositionInput == HeadPositionSource.Kinect && positionJoint == RUISSkeletonManager.Joint.None)
            Debug.LogError(	 "Your settings indicate that you want to track position with a "
                           + "Kinect joint, but you have left its value to None in Unity inspector!");

        if(		headRotationInput == HeadRotationSource.Kinect && rotationJoint == RUISSkeletonManager.Joint.None
            &&	!useOculusRiftRotation																			 )
            Debug.LogError(	 "Your settings indicate that you want to track rotation with a "
                           + "Kinect joint, but you have left its value to None in Unity inspector!");

        if(		externalDriftCorrection && compass == CompassSource.Kinect && compassJoint == RUISSkeletonManager.Joint.None
            &&  !compassIsPositionTracker && (useOculusRiftRotation || headRotationInput == HeadRotationSource.InputTransform))
            Debug.LogError(	 "Your settings indicate that you want to do yaw drift correction with a "
                           + "Kinect joint, but you have left its value to None in Unity inspector!");

        if(		externalDriftCorrection && compass == CompassSource.InputTransform && !compassTransform
            &&  !compassIsPositionTracker && (useOculusRiftRotation || headRotationInput == HeadRotationSource.InputTransform))
            Debug.LogError("Yaw drift corrector's Input Transform is none, you need to set it in Unity inspector!");

        if(externalDriftCorrection && compassIsPositionTracker && headPositionInput == HeadPositionSource.None)
            Debug.LogError(		"Position Tracker is set to None, but in 'Yaw Drift Correction' you have enabled "
                            +	"'Use Position Tracker'!");

        if(isRazerBaseMobile && (	headPositionInput == HeadPositionSource.RazerHydra
                                 || headRotationInput == HeadRotationSource.RazerHydra
                                 || compass == CompassSource.RazerHydra				  ))
        {
            if(mobileRazerBase == RazerHydraBase.InputTransform && hydraBaseInput == null)
                Debug.LogError(	 "Your settings indicate that you want to track Razer Hydra base station with a "
                               + "custom Input Transform, but you have left its value to None in Unity inspector!");
            if(mobileRazerBase == RazerHydraBase.Kinect && hydraBaseJoint == RUISSkeletonManager.Joint.None)
                Debug.LogError(	 "Your settings indicate that you want to track Razer Hydra base station with a "
                               + "Kinect joint, but you have left its value to None in Unity inspector!");
        }

        if(oculusCamController && Application.isEditor)
            Debug.Log("OVRCameraController script detected in a child object of this " + gameObject.name
                    + " object. Using Oculus Rift as a Rotation Tracker. You can access other rotation "
                    + "trackers when you remove the OVRCameraController component from the child object(s).");

        //		if(useOculusRiftRotation && inputManager)
        //		{
        //			if(		(inputManager.enableKinect 		&& headPositionInput == HeadPositionSource.Kinect)
        //				||	(inputManager.enableRazerHydra 	&& headPositionInput == HeadPositionSource.RazerHydra)
        //				||	(inputManager.enablePSMove 		&& headPositionInput == HeadPositionSource.PSMove)
        //				||	headPositionInput == HeadPositionSource.InputTransform								  )
        //			{
        //				oculusCamController.SetNeckPosition(Vector3.zero);
        //				oculusCamController.SetEyeCenterPosition(Vector3.zero);
        //				Debug.Log(	"Head position tracker found, setting NeckPosition and EyeCenterPosition to zero from "
        //						  + "OVRCameraController.");
        //			}
        //		}
    }
コード例 #33
0
ファイル: XmlImportExport.cs プロジェクト: qipa/NordeusNinja
    public static bool ExportInputManager(RUISInputManager inputManager, string filename)
    {
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");

        XmlElement inputManagerRootElement = xmlDoc.CreateElement("ns2", "RUISInputManager", "http://ruisystem.net/RUISInputManager");

        xmlDoc.AppendChild(inputManagerRootElement);

        XmlComment booleanComment = xmlDoc.CreateComment("Boolean values always with a lower case, e.g. \"true\" or \"false\"");

        inputManagerRootElement.AppendChild(booleanComment);

        XmlElement psMoveSettingsElement = xmlDoc.CreateElement("PSMoveSettings");

        inputManagerRootElement.AppendChild(psMoveSettingsElement);

        XmlElement psMoveEnabledElement = xmlDoc.CreateElement("enabled");

        psMoveEnabledElement.SetAttribute("value", inputManager.enablePSMove.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveEnabledElement);

        XmlElement psMoveIPElement = xmlDoc.CreateElement("ip");

        psMoveIPElement.SetAttribute("value", inputManager.PSMoveIP.ToString());
        psMoveSettingsElement.AppendChild(psMoveIPElement);

        XmlElement psMovePortElement = xmlDoc.CreateElement("port");

        psMovePortElement.SetAttribute("value", inputManager.PSMovePort.ToString());
        psMoveSettingsElement.AppendChild(psMovePortElement);

        XmlElement psMoveAutoConnectElement = xmlDoc.CreateElement("autoConnect");

        psMoveAutoConnectElement.SetAttribute("value", inputManager.connectToPSMoveOnStartup.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveAutoConnectElement);

        XmlElement psMoveEnableInGameCalibration = xmlDoc.CreateElement("enableInGameCalibration");

        psMoveEnableInGameCalibration.SetAttribute("value", inputManager.enableMoveCalibrationDuringPlay.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveEnableInGameCalibration);

        XmlElement psMoveMaxControllersElement = xmlDoc.CreateElement("maxControllers");

        psMoveMaxControllersElement.SetAttribute("value", inputManager.amountOfPSMoveControllers.ToString());
        psMoveSettingsElement.AppendChild(psMoveMaxControllersElement);



        XmlElement kinectSettingsElement = xmlDoc.CreateElement("KinectSettings");

        inputManagerRootElement.AppendChild(kinectSettingsElement);

        XmlElement kinectEnabledElement = xmlDoc.CreateElement("enabled");

        kinectEnabledElement.SetAttribute("value", inputManager.enableKinect.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(kinectEnabledElement);

        XmlElement maxKinectPlayersElement = xmlDoc.CreateElement("maxPlayers");

        maxKinectPlayersElement.SetAttribute("value", inputManager.maxNumberOfKinectPlayers.ToString());
        kinectSettingsElement.AppendChild(maxKinectPlayersElement);

        XmlElement kinectFloorDetectionElement = xmlDoc.CreateElement("floorDetection");

        kinectFloorDetectionElement.SetAttribute("value", inputManager.kinectFloorDetection.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(kinectFloorDetectionElement);

        XmlElement jumpGestureElement = xmlDoc.CreateElement("jumpGestureEnabled");

        jumpGestureElement.SetAttribute("value", inputManager.jumpGestureEnabled.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(jumpGestureElement);

        XmlElement kinect2SettingsElement = xmlDoc.CreateElement("Kinect2Settings");

        inputManagerRootElement.AppendChild(kinect2SettingsElement);

        XmlElement kinect2EnabledElement = xmlDoc.CreateElement("enabled");

        kinect2EnabledElement.SetAttribute("value", inputManager.enableKinect2.ToString().ToLowerInvariant());
        kinect2SettingsElement.AppendChild(kinect2EnabledElement);

        XmlElement kinect2FloorDetectionElement = xmlDoc.CreateElement("floorDetection");

        kinect2FloorDetectionElement.SetAttribute("value", inputManager.kinect2FloorDetection.ToString().ToLowerInvariant());
        kinect2SettingsElement.AppendChild(kinect2FloorDetectionElement);

        XmlElement razerSettingsElement = xmlDoc.CreateElement("RazerSettings");

        inputManagerRootElement.AppendChild(razerSettingsElement);

        XmlElement razerEnabledElement = xmlDoc.CreateElement("enabled");

        razerEnabledElement.SetAttribute("value", inputManager.enableRazerHydra.ToString().ToLowerInvariant());
        razerSettingsElement.AppendChild(razerEnabledElement);



        XmlElement riftDriftSettingsElement = xmlDoc.CreateElement("OculusDriftSettings");

        inputManagerRootElement.AppendChild(riftDriftSettingsElement);

        //XmlElement magnetometerDriftCorrectionElement = xmlDoc.CreateElement("magnetometerDriftCorrection");
        //magnetometerDriftCorrectionElement.SetAttribute("value", System.Enum.GetName(typeof(RUISInputManager.RiftMagnetometer), inputManager.riftMagnetometerMode));
        //riftDriftSettingsElement.AppendChild(magnetometerDriftCorrectionElement);

        XmlElement kinectDriftCorrectionElement = xmlDoc.CreateElement("kinectDriftCorrectionIfAvailable");

        kinectDriftCorrectionElement.SetAttribute("value", inputManager.kinectDriftCorrectionPreferred.ToString().ToLowerInvariant());
        riftDriftSettingsElement.AppendChild(kinectDriftCorrectionElement);

        XMLUtil.SaveXmlToFile(filename, xmlDoc);

        return(true);
    }
コード例 #34
0
    void Awake()
    {
		inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

		if(inputManager)
		{
			if(switchToAvailableKinect)
			{
				if(   bodyTrackingDevice == bodyTrackingDeviceType.Kinect1
				   && !inputManager.enableKinect && inputManager.enableKinect2)
				{
					bodyTrackingDevice = bodyTrackingDeviceType.Kinect2;
				}
				else if(   bodyTrackingDevice == bodyTrackingDeviceType.Kinect2
				   && !inputManager.enableKinect2 && inputManager.enableKinect)
				{
					bodyTrackingDevice = bodyTrackingDeviceType.Kinect1;
				}
			}
		}

		coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
		
		if(bodyTrackingDevice == bodyTrackingDeviceType.Kinect1) bodyTrackingDeviceID = RUISSkeletonManager.kinect1SensorID;
		if(bodyTrackingDevice == bodyTrackingDeviceType.Kinect2) bodyTrackingDeviceID = RUISSkeletonManager.kinect2SensorID;
		if(bodyTrackingDevice == bodyTrackingDeviceType.GenericMotionTracker) bodyTrackingDeviceID = RUISSkeletonManager.customSensorID;

		followOculusController = false;
		followMoveController = false;
		trackedDeviceYawRotation = Quaternion.identity;
		
        jointInitialRotations = new Dictionary<Transform, Quaternion>();
        jointInitialDistances = new Dictionary<KeyValuePair<Transform, Transform>, float>();
		
		positionKalman = new KalmanFilter();
		positionKalman.initialize(3,3);

		for(int i=0; i<fourJointsKalman.Length; ++i)
		{
			fourJointsKalman[i] = new KalmanFilter();
			fourJointsKalman[i].initialize(3,3);
			fourJointPositions[i] = Vector3.zero;
		}
    }
コード例 #35
0
	public RUISKinect2ToPSMoveCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) {
		
		this.inputDevice1 = RUISDevice.Kinect_2;
		this.inputDevice2 = RUISDevice.PS_Move;
		
		this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake;
		this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;
		
		trackingIDs = new trackedBody[6]; 
		for(int y = 0; y < trackingIDs.Length; y++) {
			trackingIDs[y] = new trackedBody(-1, false, 1);
		}
		
		psMoveWrapper = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
		inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
		coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
		kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;
		
		this.timeSinceScriptStart = 0;
		this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond;
		
		// Limit sample rate
		if(this.timeBetweenSamples < 0.1f) {
			this.timeBetweenSamples = 0.1f;
		}
		
		calibrationSpheres = new List<GameObject>();
		
		samples_PSMove = new List<Vector3>();
		samples_Kinect2 = new List<Vector3>();
		
		this.calibrationCube = calibrationSettings.calibrationCubePrefab;
		this.calibrationSphere = calibrationSettings.calibrationSpherePrefab;
		this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects;
		this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;
		
		this.deviceModelObjects = calibrationSettings.deviceModelObjects;
		this.depthViewObjects = calibrationSettings.depthViewObjects;
		this.iconObjects = calibrationSettings.iconObjects;
		
		this.PSMoveWandObject = GameObject.Find ("PSMoveWand");
		
		// Models
		this.psEyeModelObject = GameObject.Find ("PS Eye");
		this.kinect2ModelObject = GameObject.Find ("Kinect2Camera");
		
		// Depth view
		this.depthView = GameObject.Find ("Kinect2DepthView");
		
		// Icons
		this.psMoveIcon = GameObject.Find ("PS Move Icon");
		this.KinectIcon = GameObject.Find ("Kinect2 Icon");
		
		this.floorPlane = GameObject.Find ("Floor");
		
		foreach (Transform child in this.deviceModelObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.depthViewObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.iconObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		if(this.psEyeModelObject)
			this.psEyeModelObject.SetActive(true);
		if(this.PSMoveWandObject)
			this.PSMoveWandObject.SetActive(true);
		if(this.kinect2ModelObject)
			this.kinect2ModelObject.SetActive(true);
		if(this.psMoveIcon)
			this.psMoveIcon.SetActive(true);
		if(this.KinectIcon)
			this.KinectIcon.SetActive(true);
		if(this.calibrationPhaseObjects)
			this.calibrationPhaseObjects.SetActive(true);
		if(this.calibrationResultPhaseObjects)
			this.calibrationResultPhaseObjects.SetActive(false);
		if(this.depthView)
			this.depthView.SetActive(true);
		this.xmlFilename = calibrationSettings.xmlFilename;
	}
コード例 #36
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");
                        }
                    }
                }
            }
        }
    }
//	Quaternion kinect1PitchRotation = Quaternion.identity;
	
	public RUISPSMoveToOculusDK2CalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) {
		
		
		this.inputDevice1 = RUISDevice.Oculus_DK2;
		this.inputDevice2 = RUISDevice.PS_Move;
		
		this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake;
		this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;
		
		psMoveWrapper = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
		inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
		coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
		
		
		this.timeSinceScriptStart = 0;
		this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond;
		
		// Limit sample rate
		if(this.timeBetweenSamples < 0.1f) {
			this.timeBetweenSamples = 0.1f;
		}
		
		calibrationSpheres = new List<GameObject>();
		
		samples_PSMove = new List<Vector3>();
		samples_OculusDK2 = new List<Vector3>();
		
		this.calibrationCube = calibrationSettings.calibrationCubePrefab;
		this.calibrationSphere = calibrationSettings.calibrationSpherePrefab;
		this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects;
		this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;
		
		this.deviceModelObjects = calibrationSettings.deviceModelObjects;
		this.depthViewObjects = calibrationSettings.depthViewObjects;
		this.iconObjects = calibrationSettings.iconObjects;
		
		this.PSMoveWandObject = GameObject.Find ("PSMoveWand");
		this.mannequin = GameObject.Find ("Mannequin");		
		
		// Models
		this.psEyeModelObject = GameObject.Find ("PS Eye");
		this.oculusDK2CameraObject = GameObject.Find ("OculusDK2Camera");
		this.oculusRiftModel = GameObject.Find ("OculusRift");
		
		// Icons
		this.psMoveIcon = GameObject.Find ("PS Move Icon");
		this.oculusDK2Icon = GameObject.Find ("OculusDK2 Icon");
		
//		this.floorPlane = GameObject.Find ("Floor");
		
		foreach (Transform child in this.deviceModelObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.depthViewObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.iconObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		if(this.mannequin)
			this.mannequin.SetActive(false);
		if(this.psEyeModelObject)
			this.psEyeModelObject.SetActive(true);
		if(this.PSMoveWandObject)
			this.PSMoveWandObject.SetActive(true);
		if(this.oculusRiftModel)
			this.oculusRiftModel.SetActive(true);
		if(this.oculusDK2CameraObject)
			this.oculusDK2CameraObject.SetActive(true);
		if(this.psMoveIcon)
			this.psMoveIcon.SetActive(true);
		if(this.oculusDK2Icon)
			this.oculusDK2Icon.SetActive(true);
		if(this.calibrationPhaseObjects)
			this.calibrationPhaseObjects.SetActive(true);
		if(this.calibrationResultPhaseObjects)
			this.calibrationResultPhaseObjects.SetActive(false);
		this.xmlFilename = calibrationSettings.xmlFilename;
	}
コード例 #38
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");
                }
            }
        }
    }
コード例 #39
0
ファイル: XmlImportExport.cs プロジェクト: mauromina/Ensayo
    public static bool ExportInputManager(RUISInputManager inputManager, string filename)
    {
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");

        XmlElement inputManagerRootElement = xmlDoc.CreateElement("ns2", "RUISInputManager", "http://ruisystem.net/RUISInputManager");

        xmlDoc.AppendChild(inputManagerRootElement);

        XmlComment booleanComment = xmlDoc.CreateComment("Boolean values always with a lower case, e.g. \"true\" or \"false\"");

        inputManagerRootElement.AppendChild(booleanComment);

        XmlElement psMoveSettingsElement = xmlDoc.CreateElement("PSMoveSettings");

        inputManagerRootElement.AppendChild(psMoveSettingsElement);

        XmlElement psMoveEnabledElement = xmlDoc.CreateElement("enabled");

        psMoveEnabledElement.SetAttribute("value", inputManager.enablePSMove.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveEnabledElement);

        XmlElement psMoveIPElement = xmlDoc.CreateElement("ip");

        psMoveIPElement.SetAttribute("value", inputManager.PSMoveIP.ToString());
        psMoveSettingsElement.AppendChild(psMoveIPElement);

        XmlElement psMovePortElement = xmlDoc.CreateElement("port");

        psMovePortElement.SetAttribute("value", inputManager.PSMovePort.ToString());
        psMoveSettingsElement.AppendChild(psMovePortElement);

        XmlElement psMoveAutoConnectElement = xmlDoc.CreateElement("autoConnect");

        psMoveAutoConnectElement.SetAttribute("value", inputManager.connectToPSMoveOnStartup.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveAutoConnectElement);

        XmlElement psMoveEnableInGameCalibration = xmlDoc.CreateElement("enableInGameCalibration");

        psMoveEnableInGameCalibration.SetAttribute("value", inputManager.enableMoveCalibrationDuringPlay.ToString().ToLowerInvariant());
        psMoveSettingsElement.AppendChild(psMoveEnableInGameCalibration);

        XmlElement psMoveMaxControllersElement = xmlDoc.CreateElement("maxControllers");

        psMoveMaxControllersElement.SetAttribute("value", inputManager.amountOfPSMoveControllers.ToString());
        psMoveSettingsElement.AppendChild(psMoveMaxControllersElement);



        XmlElement kinectSettingsElement = xmlDoc.CreateElement("KinectSettings");

        inputManagerRootElement.AppendChild(kinectSettingsElement);

        XmlElement kinectEnabledElement = xmlDoc.CreateElement("enabled");

        kinectEnabledElement.SetAttribute("value", inputManager.enableKinect.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(kinectEnabledElement);

        XmlElement maxKinectPlayersElement = xmlDoc.CreateElement("maxPlayers");

        maxKinectPlayersElement.SetAttribute("value", inputManager.maxNumberOfKinectPlayers.ToString());
        kinectSettingsElement.AppendChild(maxKinectPlayersElement);

        XmlElement kinectFloorDetectionElement = xmlDoc.CreateElement("floorDetection");

        kinectFloorDetectionElement.SetAttribute("value", inputManager.kinectFloorDetection.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(kinectFloorDetectionElement);

        XmlElement jumpGestureElement = xmlDoc.CreateElement("jumpGestureEnabled");

        jumpGestureElement.SetAttribute("value", inputManager.jumpGestureEnabled.ToString().ToLowerInvariant());
        kinectSettingsElement.AppendChild(jumpGestureElement);

        XmlElement kinect2SettingsElement = xmlDoc.CreateElement("Kinect2Settings");

        inputManagerRootElement.AppendChild(kinect2SettingsElement);

        XmlElement kinect2EnabledElement = xmlDoc.CreateElement("enabled");

        kinect2EnabledElement.SetAttribute("value", inputManager.enableKinect2.ToString().ToLowerInvariant());
        kinect2SettingsElement.AppendChild(kinect2EnabledElement);

        XmlElement kinect2FloorDetectionElement = xmlDoc.CreateElement("floorDetection");

        kinect2FloorDetectionElement.SetAttribute("value", inputManager.kinect2FloorDetection.ToString().ToLowerInvariant());
        kinect2SettingsElement.AppendChild(kinect2FloorDetectionElement);

        XmlElement razerSettingsElement = xmlDoc.CreateElement("RazerSettings");

        inputManagerRootElement.AppendChild(razerSettingsElement);

        XmlElement razerEnabledElement = xmlDoc.CreateElement("enabled");

        razerEnabledElement.SetAttribute("value", inputManager.enableRazerHydra.ToString().ToLowerInvariant());
        razerSettingsElement.AppendChild(razerEnabledElement);



//		XmlElement riftDriftSettingsElement = xmlDoc.CreateElement("OculusDriftSettings");
//		inputManagerRootElement.AppendChild(riftDriftSettingsElement);

//		XmlElement kinectDriftCorrectionElement = xmlDoc.CreateElement("kinectDriftCorrectionIfAvailable");
//		kinectDriftCorrectionElement.SetAttribute("value", inputManager.kinectDriftCorrectionPreferred.ToString().ToLowerInvariant());
//		riftDriftSettingsElement.AppendChild(kinectDriftCorrectionElement);

        //XmlElement magnetometerDriftCorrectionElement = xmlDoc.CreateElement("magnetometerDriftCorrection");
        //magnetometerDriftCorrectionElement.SetAttribute("value", System.Enum.GetName(typeof(RUISInputManager.RiftMagnetometer), inputManager.riftMagnetometerMode));
        //riftDriftSettingsElement.AppendChild(magnetometerDriftCorrectionElement);

        XmlElement coordinateSystemSettingsElement = xmlDoc.CreateElement("CoordinateSystemSettings");

        inputManagerRootElement.AppendChild(coordinateSystemSettingsElement);

        XmlComment coordinateComment0 = xmlDoc.CreateComment("Below values will override the settings made in Unity Editor if you uncomment them.");

        coordinateSystemSettingsElement.AppendChild(coordinateComment0);

        // HACK TODO: Add all coordinate system settings when they can be altered in the menu
        //		XmlElement useMasterCoordinateSystemElement = xmlDoc.CreateElement("useMasterCoordinateSystem");
        //		useMasterCoordinateSystemElement.SetAttribute("value", inputManager.useMasterCoordinateSystem.ToString().ToLowerInvariant());
        //		coordinateSystemSettingsElement.AppendChild(useMasterCoordinateSystemElement);
        // ...
        XmlComment coordinateComment1 = xmlDoc.CreateComment("\n    <useMasterCoordinateSystem value=\"true\" /> \n"
                                                             + "    <masterCoordinateSystemSensor value=\"Kinect_2\" />\n");

        coordinateSystemSettingsElement.AppendChild(coordinateComment1);

        XmlComment coordinateComment2 = xmlDoc.CreateComment(" Kinect_2, Kinect_1, OpenVR, PS_Move ");

        coordinateSystemSettingsElement.AppendChild(coordinateComment2);

        XmlComment coordinateComment3 = xmlDoc.CreateComment("\n    <switchMasterToAvailableSensor value=\"true\" />\n"
                                                             + "    <coordinateSystemLocationOffset x=\"0\" y=\"0\" z=\"0\" />\n"
                                                             + "    <coordinateSystemYRotationOffset value=\"0\" />\n"
                                                             + "    <setKinectOriginToFloor value=\"true\" />\n");

        coordinateSystemSettingsElement.AppendChild(coordinateComment3);

        XMLUtil.SaveXmlToFile(filename, xmlDoc);

        return(true);
    }
    public RUISKinect2ToPSMoveCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings)
    {
        this.inputDevice1 = RUISDevice.Kinect_2;
        this.inputDevice2 = RUISDevice.PS_Move;

        this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake;
        this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;

        trackingIDs = new trackedBody[6];
        for(int y = 0; y < trackingIDs.Length; y++) {
            trackingIDs[y] = new trackedBody(-1, false, 1);
        }

        psMoveWrapper = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
        inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
        kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;

        this.timeSinceScriptStart = 0;
        this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond;

        // Limit sample rate
        if(this.timeBetweenSamples < 0.1f) {
            this.timeBetweenSamples = 0.1f;
        }

        calibrationSpheres = new List<GameObject>();

        samples_PSMove = new List<Vector3>();
        samples_Kinect2 = new List<Vector3>();

        this.calibrationCube = calibrationSettings.calibrationCubePrefab;
        this.calibrationSphere = calibrationSettings.calibrationSpherePrefab;
        this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects;
        this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;

        this.deviceModelObjects = calibrationSettings.deviceModelObjects;
        this.depthViewObjects = calibrationSettings.depthViewObjects;
        this.iconObjects = calibrationSettings.iconObjects;

        this.PSMoveWandObject = GameObject.Find ("PSMoveWand");

        // Models
        this.psEyeModelObject = GameObject.Find ("PS Eye");
        this.kinect2ModelObject = GameObject.Find ("Kinect2Camera");

        // Depth view
        this.depthView = GameObject.Find ("Kinect2DepthView");

        // Icons
        this.psMoveIcon = GameObject.Find ("PS Move Icon");
        this.KinectIcon = GameObject.Find ("Kinect2 Icon");

        this.floorPlane = GameObject.Find ("Floor");

        foreach (Transform child in this.deviceModelObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.depthViewObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.iconObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        if(this.psEyeModelObject)
            this.psEyeModelObject.SetActive(true);
        if(this.PSMoveWandObject)
            this.PSMoveWandObject.SetActive(true);
        if(this.kinect2ModelObject)
            this.kinect2ModelObject.SetActive(true);
        if(this.psMoveIcon)
            this.psMoveIcon.SetActive(true);
        if(this.KinectIcon)
            this.KinectIcon.SetActive(true);
        if(this.calibrationPhaseObjects)
            this.calibrationPhaseObjects.SetActive(true);
        if(this.calibrationResultPhaseObjects)
            this.calibrationResultPhaseObjects.SetActive(false);
        if(this.depthView)
            this.depthView.SetActive(true);
        this.xmlFilename = calibrationSettings.xmlFilename;
    }
コード例 #41
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 Character 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;
				}
			}
		}
	}
コード例 #42
0
	void Start()
	{
		// Get information about Oculus Rift version and if it is connected
		ovrManager = FindObjectOfType<OVRManager>();
		bool isRiftConnected = false;
		//		#if UNITY_EDITOR
		//		if(UnityEditorInternal.InternalEditorUtility.HasPro())
		//		#endif
		{
			try
			{
				if(OVRManager.capiHmd != null)
					ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type;
				if(OVRManager.display != null)
				{
					isRiftConnected = OVRManager.display.isPresent;
					
					if(coordinateSystem && coordinateSystem.applyToRootCoordinates && headPositionInput == HeadPositionSource.OculusDK2)
					{
						OVRManager.display.RecenteredPose += RecenterPoseWarning;
					}	
				}
			}
			catch(UnityException e)
			{
				Debug.LogError(e);
			}
		}
		
		if(headPositionInput == HeadPositionSource.OculusDK2)
		{
			if(!isRiftConnected) 
			{
				headPositionInput = HeadPositionSource.None;
				this.transform.localPosition = defaultPosition;
			}
			else 
			{
				OculusCounterPoseOffset();
				if(coordinateSystem && coordinateSystem.applyToRootCoordinates)
					this.localRotation = coordinateSystem.GetOculusCameraYRotation();
			}
		}
		
		if(headPositionInput == HeadPositionSource.Kinect1) {
			kinectSensorID = RUISSkeletonManager.kinect1SensorID;
		}
		if(headPositionInput == HeadPositionSource.Kinect2) {
			kinectSensorID = RUISSkeletonManager.kinect2SensorID;
		}
		
		inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
		if(		!inputManager
		   &&  (	headPositionInput == HeadPositionSource.PSMove
		     || headRotationInput == HeadRotationSource.PSMove
		     || (externalDriftCorrection && compass == CompassSource.PSMove)))
			Debug.LogError("RUISInputManager script is missing from this scene!");
		
		if(inputManager && !inputManager.enablePSMove)
		{
			if(headPositionInput == HeadPositionSource.PSMove)
				Debug.LogError(	"Your " + typeof(RUISTracker) + " settings indicate that you want to use PS Move for position "
				               +	"tracking, but you have not enabled it from InputManager.");
			if(headRotationInput == HeadRotationSource.PSMove)
				Debug.LogError(	"Your " + typeof(RUISTracker) + " settings indicate that you want to use PS Move for rotation "
				               +	"tracking, but you have not enabled it from InputManager.");
			if(externalDriftCorrection && compass == CompassSource.PSMove)
				Debug.LogError(	"Your " + typeof(RUISTracker) + " settings indicate that you want to use PS Move for yaw drift "
				               +	"correction, but you have not enabled it from InputManager.");
		}
		
		if (!skeletonManager)
			skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager;
		if(		!skeletonManager
		   &&  (	headPositionInput == HeadPositionSource.Kinect1
		     || headPositionInput == HeadPositionSource.Kinect2
		     || (!useOculusRiftRotation && (headRotationInput == HeadRotationSource.Kinect1 || headRotationInput == HeadRotationSource.Kinect2))
		     || (externalDriftCorrection && (compass == CompassSource.Kinect1 || compass == CompassSource.Kinect2))))
		{
			Debug.LogError("RUISSkeletonManager script is missing from this scene!");
		}
		
		if(inputManager && !inputManager.enableRazerHydra)
		{
			if(headPositionInput == HeadPositionSource.RazerHydra)
				Debug.LogWarning(	"Your " + typeof(RUISTracker) + " settings indicate that you want to use Razer Hydra for "
				                 +	"position tracking, but you have disabled Razer Hydra from RUIS "
				                 +	"InputManager.");
			if(headRotationInput == HeadRotationSource.RazerHydra)
				Debug.LogWarning(	"Your " + typeof(RUISTracker) + " settings indicate that you want to use Razer Hydra for "
				                 +	"rotation tracking, but you have disabled Razer Hydra from RUIS "
				                 +	"InputManager.");
			if(externalDriftCorrection && compass == CompassSource.RazerHydra)
				Debug.LogWarning(	"Your " + typeof(RUISTracker) + " settings indicate that you want to use Razer Hydra for "
				                 +	"yaw drift correction, but you have disabled Razer Hydra from RUIS "
				                 +	"InputManager.");
		}
		
		if(headPositionInput == HeadPositionSource.InputTransform && !positionInput)
			Debug.LogError("Position tracker's Input Transform is none, you need to set it in Unity inspector!");
		
		if(headRotationInput == HeadRotationSource.InputTransform && !rotationInput && !useOculusRiftRotation)
			Debug.LogError("Rotation tracker's Input Transform is none, you need to set it in Unity inspector!");
		
		if(headPositionInput == HeadPositionSource.Kinect1 && positionJoint == RUISSkeletonManager.Joint.None)
			Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to track position with a "
			               + "Kinect joint, but you have left its value to None in Unity inspector!");
		
		if(		headRotationInput == HeadRotationSource.Kinect1 && rotationJoint == RUISSkeletonManager.Joint.None
		   &&	!useOculusRiftRotation																
		   )
			Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to track rotation with a "
			               + "Kinect joint, but you have left its value to None in Unity inspector!");
		
		if(		externalDriftCorrection && compass == CompassSource.Kinect1 && compassJoint == RUISSkeletonManager.Joint.None
		   &&  !compassIsPositionTracker && (useOculusRiftRotation || headRotationInput == HeadRotationSource.InputTransform))
			Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to do yaw drift correction with a "
			               + "Kinect joint, but you have left its value to None in Unity inspector!");
		
		if(headPositionInput == HeadPositionSource.Kinect2 && positionJoint == RUISSkeletonManager.Joint.None)
			Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to track position with a "
			               + "Kinect2 joint, but you have left its value to None in Unity inspector!");
		
		if(		headRotationInput == HeadRotationSource.Kinect2 && rotationJoint == RUISSkeletonManager.Joint.None
		   &&	!useOculusRiftRotation																	
		   )
			Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to track rotation with a "
			               + "Kinect2 joint, but you have left its value to None in Unity inspector!");
		
		if(		externalDriftCorrection && compass == CompassSource.Kinect2 && compassJoint == RUISSkeletonManager.Joint.None
		   &&  !compassIsPositionTracker && (useOculusRiftRotation || headRotationInput == HeadRotationSource.InputTransform))
			Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to do yaw drift correction with a "
			               + "Kinect2 joint, but you have left its value to None in Unity inspector!");
		
		if(		externalDriftCorrection && compass == CompassSource.InputTransform && !compassTransform 
		   &&  !compassIsPositionTracker && (useOculusRiftRotation || headRotationInput == HeadRotationSource.InputTransform))
			Debug.LogError("Yaw drift corrector's Input Transform is none, you need to set it in Unity inspector!");
		
		if(externalDriftCorrection && compassIsPositionTracker && headPositionInput == HeadPositionSource.None)
			Debug.LogError(		"Position Tracker is set to None, but in 'Yaw Drift Correction' you have enabled "
			               +	"'Use Position Tracker'!");
		
		if(isRazerBaseMobile && (	headPositionInput == HeadPositionSource.RazerHydra
		                         || headRotationInput == HeadRotationSource.RazerHydra
		                         || compass == CompassSource.RazerHydra				  ))
		{
			if(mobileRazerBase == RazerHydraBase.InputTransform && hydraBaseInput == null)
				Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to track Razer Hydra base station with a "
				               + "custom Input Transform, but you have left its value to None in Unity inspector!");
			if(mobileRazerBase == RazerHydraBase.Kinect1 && hydraBaseJoint == RUISSkeletonManager.Joint.None)
				Debug.LogError(	 "Your " + typeof(RUISTracker) + " settings indicate that you want to track Razer Hydra base station with a "
				               + "Kinect joint, but you have left its value to None in Unity inspector!");
		}
		
		if(useOculusRiftRotation && headPositionInput != HeadPositionSource.OculusDK2 && ovrCameraRig != null)
		{
			DisableOculusPositionalTracking();
			
			// OVR manager is not necessarily initialized, so lets do the above disabling later as well
			StartCoroutine(DelayedDisableOculusPositionalTracking());
			
			Debug.Log(  typeof(RUISTracker) + ": Position Tracker is " + headPositionInput + " and " + typeof(OVRCameraRig)
			          + " found in a child gameObject, turning off Oculus Rift position tracking altogether. If you do not "
			          + "want this, then remove the " + typeof(OVRCameraRig) + " component from the child object(s).");
		}
		
		if(ovrCameraRig && Application.isEditor)
			Debug.Log(typeof(OVRCameraRig) + " script detected in a child object of this " + gameObject.name
			          + " object. Using Oculus Rift as a Rotation Tracker. You can access other rotation "
			          + "trackers when you remove the " + typeof(OVRCameraRig) + " component from the child object(s).");
		
		//		if(useOculusRiftRotation && inputManager)
		//		{
		//			if(		(inputManager.enableKinect 		&& headPositionInput == HeadPositionSource.Kinect)
		//				||	(inputManager.enableRazerHydra 	&& headPositionInput == HeadPositionSource.RazerHydra)
		//				||	(inputManager.enablePSMove 		&& headPositionInput == HeadPositionSource.PSMove)
		//				||	headPositionInput == HeadPositionSource.InputTransform								  )
		//			{
		//				oculusCamController.SetNeckPosition(Vector3.zero);
		//				oculusCamController.SetEyeCenterPosition(Vector3.zero);
		//				Debug.Log(	"Head position tracker found, setting NeckPosition and EyeCenterPosition to zero from "
		//						  + "OVRManager.");
		//			}
		//		}
	}
コード例 #43
0
 public static bool ExportInputManager(RUISInputManager inputManager, string filename)
 {
     return(true);
 }
コード例 #44
0
    void Awake()
    {
		inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

		playerManager = GetComponent<NIPlayerManager>();
		RUISKinect2Data = GetComponent<RUISKinect2Data>();

		if (!inputManager.enableKinect) playerManager.enabled = false;
		if (!inputManager.enableKinect2) RUISKinect2Data.enabled = false;

        if (coordinateSystem == null)
        {
            coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
        }

		for (int x = 0; x < 3; x++) // Kinect 1, Kinect 2, Custom Tracker
		{
			for (int i = 0; i < 6; i++) 
			{
				skeletons [x, i] = new Skeleton ();

				// HACK  for filtering Kinect 2 arm rotations
				if(x == kinect2SensorID)
				{
					for(int k = 0; k < skeletons[x, i].filterRot.Length; ++k)
					{
						skeletons[x, i].filterRot[k] = new KalmanFilteredRotation();
						skeletons[x, i].filterRot[k].skipIdenticalMeasurements = true;
						skeletons[x, i].filterRot[k].rotationNoiseCovariance = skeletons[x, i].rotationNoiseCovariance;
						skeletons[x, i].previousRotation[k] = Quaternion.identity;
					}
				}
			}
		}
		
		isNewKinect2Frame = false;
		timeSinceLastKinect2Frame = 0;
    }
コード例 #45
0
 public static bool ImportInputManager(RUISInputManager inputManager, string filename, TextAsset xmlSchema)
 {
     return(true);
 }
コード例 #46
0
 void Awake()
 {
     inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
 }
	public RUISKinectToPSMoveCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) {
		
		
		this.inputDevice1 = RUISDevice.Kinect_1;
		this.inputDevice2 = RUISDevice.PS_Move;
		
		this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake;
		this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;
		
		
		kinectSelection = MonoBehaviour.FindObjectOfType(typeof(NIPlayerManagerCOMSelection)) as NIPlayerManagerCOMSelection;
		settingsManager = MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;
		psMoveWrapper = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
		inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
		coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;
		
		this.timeSinceScriptStart = 0;
		this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond;
		
		// Limit sample rate
		if(this.timeBetweenSamples < 0.1f) {
			this.timeBetweenSamples = 0.1f;
		}
		
		calibrationSpheres = new List<GameObject>();
		
		samples_PSMove = new List<Vector3>();
		samples_Kinect = new List<Vector3>();
		
		this.calibrationCube = calibrationSettings.calibrationCubePrefab;
		this.calibrationSphere = calibrationSettings.calibrationSpherePrefab;
		this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects;
		this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;
		
		this.deviceModelObjects = calibrationSettings.deviceModelObjects;
		this.depthViewObjects = calibrationSettings.depthViewObjects;
		this.iconObjects = calibrationSettings.iconObjects;
		
		this.PSMoveWandObject = GameObject.Find ("PSMoveWand");
				
		// Models
		this.psEyeModelObject = GameObject.Find ("PS Eye");
		this.kinect1ModelObject = GameObject.Find ("KinectCamera");
		
		// Depth view
		this.depthView = GameObject.Find ("KinectDepthView");
		
		// Icons
		this.psMoveIcon = GameObject.Find ("PS Move Icon");
		this.KinectIcon = GameObject.Find ("Kinect Icon");
		
		this.floorPlane = GameObject.Find ("Floor");
		
		foreach (Transform child in this.deviceModelObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.depthViewObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		foreach (Transform child in this.iconObjects.transform)
		{
			child.gameObject.SetActive(false);
		}
		
		if(this.psEyeModelObject)
			this.psEyeModelObject.SetActive(true);
		if(this.PSMoveWandObject)
			this.PSMoveWandObject.SetActive(true);
		if(this.kinect1ModelObject)
			this.kinect1ModelObject.SetActive(true);
		if(this.psMoveIcon)
			this.psMoveIcon.SetActive(true);
		if(this.KinectIcon)
			this.KinectIcon.SetActive(true);
		if(this.calibrationPhaseObjects)
			this.calibrationPhaseObjects.SetActive(true);
		if(this.calibrationResultPhaseObjects)
			this.calibrationResultPhaseObjects.SetActive(false);
		if(this.depthView)
			this.depthView.SetActive(true);
		this.xmlFilename = calibrationSettings.xmlFilename;
	}
コード例 #48
0
    public RUISKinectToPSMoveCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings)
    {
        this.inputDevice1 = RUISDevice.Kinect_1;
        this.inputDevice2 = RUISDevice.PS_Move;

        this.numberOfSamplesToTake    = calibrationSettings.numberOfSamplesToTake;
        this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond;


        kinectSelection  = MonoBehaviour.FindObjectOfType(typeof(NIPlayerManagerCOMSelection)) as NIPlayerManagerCOMSelection;
        settingsManager  = MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager;
        psMoveWrapper    = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper;
        inputManager     = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;
        coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem;

        this.timeSinceScriptStart = 0;
        this.timeBetweenSamples   = 1 / (float)numberOfSamplesPerSecond;

        // Limit sample rate
        if (this.timeBetweenSamples < 0.1f)
        {
            this.timeBetweenSamples = 0.1f;
        }

        calibrationSpheres = new List <GameObject>();

        samples_PSMove = new List <Vector3>();
        samples_Kinect = new List <Vector3>();

        this.calibrationCube               = calibrationSettings.calibrationCubePrefab;
        this.calibrationSphere             = calibrationSettings.calibrationSpherePrefab;
        this.calibrationPhaseObjects       = calibrationSettings.calibrationPhaseObjects;
        this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects;

        this.deviceModelObjects = calibrationSettings.deviceModelObjects;
        this.depthViewObjects   = calibrationSettings.depthViewObjects;
        this.iconObjects        = calibrationSettings.iconObjects;

        this.PSMoveWandObject = GameObject.Find("PSMoveWand");

        // Models
        this.psEyeModelObject   = GameObject.Find("PS Eye");
        this.kinect1ModelObject = GameObject.Find("KinectCamera");

        // Depth view
        this.depthView = GameObject.Find("KinectDepthView");

        // Icons
        this.psMoveIcon = GameObject.Find("PS Move Icon");
        this.KinectIcon = GameObject.Find("Kinect Icon");

        this.floorPlane = GameObject.Find("Floor");

        foreach (Transform child in this.deviceModelObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.depthViewObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        foreach (Transform child in this.iconObjects.transform)
        {
            child.gameObject.SetActive(false);
        }

        if (this.psEyeModelObject)
        {
            this.psEyeModelObject.SetActive(true);
        }
        if (this.PSMoveWandObject)
        {
            this.PSMoveWandObject.SetActive(true);
        }
        if (this.kinect1ModelObject)
        {
            this.kinect1ModelObject.SetActive(true);
        }
        if (this.psMoveIcon)
        {
            this.psMoveIcon.SetActive(true);
        }
        if (this.KinectIcon)
        {
            this.KinectIcon.SetActive(true);
        }
        if (this.calibrationPhaseObjects)
        {
            this.calibrationPhaseObjects.SetActive(true);
        }
        if (this.calibrationResultPhaseObjects)
        {
            this.calibrationResultPhaseObjects.SetActive(false);
        }
        if (this.depthView)
        {
            this.depthView.SetActive(true);
        }
        this.xmlFilename = calibrationSettings.xmlFilename;
    }
コード例 #49
0
    void Start()
    {
        inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager;

        if(useRazerHydra && inputManager && !inputManager.enableRazerHydra)
        {
            useRazerHydra = false;
            Debug.LogWarning(	"Your settings indicate that you want to use Razer Hydra for "
                             +	"character locomotion controls, but you have disabled Razer "
                             +	"Hydra from RUIS InputManager.");
        }

        if(usePSNavigationController && inputManager && !inputManager.enablePSMove)
        {
            usePSNavigationController = false;
            Debug.LogWarning(	"Your settings indicate that you want to use PS Navigation "
                             +	"controller for character locomotion controls, but you have "
                             +	"disabled PS Move from RUIS InputManager.");
        }
    }