private void updateKinectFloorData() { if (coordinateSystem) { if (coordinateSystem.rootDevice == RUISDevice.Kinect_1) { coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_1); coordinateSystem.ResetDistanceFromFloor(RUISDevice.Kinect_1); } OpenNI.Plane3D floor; try { floor = sceneAnalyzer.Floor; } catch (System.Exception e) { Debug.LogError(e.TargetSite + ": Failed to get OpenNI.SceneAnalyzer.Floor."); return; } Vector3 newFloorNormal = new Vector3(floor.Normal.X, floor.Normal.Y, floor.Normal.Z).normalized; Vector3 newFloorPosition = (new Vector3(floor.Point.X, floor.Point.Y, floor.Point.Z)) * RUISCoordinateSystem.kinectToUnityScale; //Vector3 newFloorPosition = coordinateSystem.ConvertKinectPosition(floor.Point); //Project the position of the kinect camera onto the floor //http://en.wikipedia.org/wiki/Point_on_plane_closest_to_origin //http://en.wikipedia.org/wiki/Plane_(geometry) float d = newFloorNormal.x * newFloorPosition.x + newFloorNormal.y * newFloorPosition.y + newFloorNormal.z * newFloorPosition.z; Vector3 closestFloorPointToKinect = new Vector3(newFloorNormal.x, newFloorNormal.y, newFloorNormal.z); closestFloorPointToKinect = (closestFloorPointToKinect * d) / closestFloorPointToKinect.sqrMagnitude; //floorPlane.transform.position = closestFloorPointToKinect; Quaternion kinectFloorRotator = Quaternion.FromToRotation(newFloorNormal, Vector3.up); //transform the point from Kinect's coordinate system rotation to Unity's rotation closestFloorPointToKinect = kinectFloorRotator * closestFloorPointToKinect; if (float.IsNaN(closestFloorPointToKinect.magnitude)) { closestFloorPointToKinect = Vector3.zero; } if (newFloorNormal.sqrMagnitude < 0.1f) { newFloorNormal = Vector3.up; } if (coordinateSystem.rootDevice == RUISDevice.Kinect_1) { coordinateSystem.SetFloorNormal(newFloorNormal, RUISDevice.Kinect_1); coordinateSystem.SetDistanceFromFloor(closestFloorPointToKinect.magnitude, RUISDevice.Kinect_1); } Debug.Log("Updated Kinect floor normal " + newFloorNormal + " and floor distance (" + closestFloorPointToKinect.magnitude + ")"); } }
private void UpdateFloorNormalAndDistance() { coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_2); Windows.Kinect.Vector4 kinect2FloorPlane = kinect2SourceManager.GetFlootClipPlane(); kinect2FloorNormal = new Vector3(kinect2FloorPlane.X, kinect2FloorPlane.Y, kinect2FloorPlane.Z); kinect2FloorNormal.Normalize(); if (kinect2FloorNormal.sqrMagnitude < 0.1f) { kinect2FloorNormal = Vector3.up; } kinect2DistanceFromFloor = kinect2FloorPlane.W / Mathf.Sqrt(kinect2FloorNormal.sqrMagnitude); if (float.IsNaN(kinect2DistanceFromFloor)) { kinect2DistanceFromFloor = 0; } Quaternion kinect2FloorRotator = Quaternion.FromToRotation(kinect2FloorNormal, Vector3.up); kinect2PitchRotation = Quaternion.Inverse(kinect2FloorRotator); coordinateSystem.SetDistanceFromFloor(kinect2DistanceFromFloor, RUISDevice.Kinect_2); coordinateSystem.SetFloorNormal(kinect2FloorNormal, RUISDevice.Kinect_2); }
private void UpdateFloorNormalAndDistance() { coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_2); Windows.Kinect.Vector4 kinect2FloorPlane = kinect2SourceManager.GetFlootClipPlane(); kinect2FloorNormal = new Vector3(kinect2FloorPlane.X, kinect2FloorPlane.Y, kinect2FloorPlane.Z); kinect2FloorNormal.Normalize(); if (kinect2FloorNormal.sqrMagnitude < 0.1f) { kinect2FloorNormal = Vector3.up; } kinect2DistanceFromFloor = kinect2FloorPlane.W / Mathf.Sqrt(kinect2FloorNormal.sqrMagnitude); if (float.IsNaN(kinect2DistanceFromFloor)) { kinect2DistanceFromFloor = 0; } // Quaternion kinect2FloorRotator = Quaternion.FromToRotation(kinect2FloorNormal, Vector3.up); // kinect2PitchRotation = Quaternion.Inverse (kinect2FloorRotator); coordinateSystem.SetDistanceFromFloor(kinect2DistanceFromFloor, RUISDevice.Kinect_2); coordinateSystem.SetFloorNormal(kinect2FloorNormal, RUISDevice.Kinect_2); OpenNI.Plane3D floor; try{ floor = sceneAnalyzer.Floor; } catch (System.Exception e) { Debug.LogError(e.TargetSite + ": Failed to get OpenNI.SceneAnalyzer.Floor."); return; //throw e; } Quaternion kinectFloorRotator = Quaternion.identity; kinect1FloorNormal = new Vector3(floor.Normal.X, floor.Normal.Y, floor.Normal.Z); if (kinect1FloorNormal.sqrMagnitude < 0.1f) { kinect1FloorNormal = Vector3.up; } Vector3 floorPoint = new Vector3(floor.Point.X, floor.Point.Y, floor.Point.Z); kinectFloorRotator = Quaternion.FromToRotation(kinect1FloorNormal, Vector3.up); kinect1DistanceFromFloor = closestDistanceFromFloor(kinect1FloorNormal, floorPoint, RUISCoordinateSystem.kinectToUnityScale); kinect1PitchRotation = Quaternion.Inverse(kinectFloorRotator); }
void Start() { coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; Quaternion dictionaryFloorNormal = coordinateSystem.RUISCalibrationResultsFloorPitchRotation[coordinateSystem.rootDevice]; float dictionaryDistanceFromFloor = coordinateSystem.RUISCalibrationResultsDistanceFromFloor[coordinateSystem.rootDevice]; Vector3 normalVector = dictionaryFloorNormal * Vector3.up; coordinateSystem.SetFloorNormal(normalVector, coordinateSystem.rootDevice); coordinateSystem.SetDistanceFromFloor(dictionaryDistanceFromFloor, coordinateSystem.rootDevice); //check whether the kinect camera is actually connected if (enableKinect) { OpenNISettingsManager settingsManager = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; if (settingsManager.UserGenrator == null || !settingsManager.UserGenrator.Valid) { Debug.LogError("Could not start OpenNI! Check your Kinect connection."); GetComponentInChildren <RUISKinectDisabler>().KinectNotAvailable(); } } if (!enableKinect2) { Debug.Log("Kinect 2 is disabled from RUISInputManager."); BodySourceManager kinect2Manager = GetComponentInChildren <BodySourceManager>(); if (kinect2Manager) { kinect2Manager.gameObject.SetActive(false); } } if ((enableKinect && kinectFloorDetection) || (enableKinect2 && kinect2FloorDetection)) { StartFloorDetection(); } if (enablePSMove) { RUISPSMoveWand[] controllers = GetComponentsInChildren <RUISPSMoveWand>(); moveControllers = new RUISPSMoveWand[controllers.Length]; foreach (RUISPSMoveWand controller in controllers) { moveControllers[controller.controllerId] = controller; } } }
private void UpdateFloorNormalAndDistance() { coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_1); OpenNI.Plane3D floor; try{ floor = sceneAnalyzer.Floor; } catch (System.Exception e) { Debug.LogError(e.TargetSite + ": Failed to get OpenNI.SceneAnalyzer.Floor."); kinectError = true; return; //throw e; } // Quaternion kinectFloorRotator = Quaternion.identity; normalVector = new Vector3(floor.Normal.X, floor.Normal.Y, floor.Normal.Z); if (normalVector.sqrMagnitude < 0.1f) { normalVector = Vector3.up; } Vector3 floorPoint = new Vector3(floor.Point.X, floor.Point.Y, floor.Point.Z); // kinectFloorRotator = Quaternion.FromToRotation(normalVector, Vector3.up); kinect1DistanceFromFloor = closestDistanceFromFloor(normalVector, floorPoint, RUISCoordinateSystem.kinectToUnityScale); // kinect1PitchRotation = Quaternion.Inverse (kinectFloorRotator); if (float.IsNaN(kinect1DistanceFromFloor)) { kinect1DistanceFromFloor = 0; } coordinateSystem.SetDistanceFromFloor(kinect1DistanceFromFloor, RUISDevice.Kinect_1); coordinateSystem.SetFloorNormal(normalVector, RUISDevice.Kinect_1); }
void Start() { coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; Quaternion dictionaryFloorNormal = coordinateSystem.RUISCalibrationResultsFloorPitchRotation[coordinateSystem.rootDevice]; float dictionaryDistanceFromFloor = coordinateSystem.RUISCalibrationResultsDistanceFromFloor[coordinateSystem.rootDevice]; Vector3 normalVector = dictionaryFloorNormal * Vector3.up; coordinateSystem.SetFloorNormal(normalVector, coordinateSystem.rootDevice); coordinateSystem.SetDistanceFromFloor(dictionaryDistanceFromFloor, coordinateSystem.rootDevice); //check whether the kinect camera is actually connected if (enableKinect) { OpenNISettingsManager settingsManager = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; if (settingsManager.UserGenrator == null || !settingsManager.UserGenrator.Valid) { Debug.LogError("Could not start OpenNI! Check your Kinect connection."); GetComponentInChildren<RUISKinectDisabler>().KinectNotAvailable(); } } if (!enableKinect2) { Debug.Log("Kinect 2 is disabled from RUISInputManager."); BodySourceManager kinect2Manager = GetComponentInChildren<BodySourceManager>(); if(kinect2Manager) kinect2Manager.gameObject.SetActive(false); } if((enableKinect && kinectFloorDetection) || (enableKinect2 && kinect2FloorDetection)) StartFloorDetection(); if (enablePSMove) { RUISPSMoveWand[] controllers = GetComponentsInChildren<RUISPSMoveWand>(); moveControllers = new RUISPSMoveWand[controllers.Length]; foreach (RUISPSMoveWand controller in controllers) { moveControllers[controller.controllerId] = controller; } } }
void Start() { Quaternion dictionaryFloorNormal = coordinateSystem.RUISCalibrationResultsFloorPitchRotation[coordinateSystem.rootDevice]; float dictionaryDistanceFromFloor = coordinateSystem.RUISCalibrationResultsDistanceFromFloor[coordinateSystem.rootDevice]; Vector3 normalVector = dictionaryFloorNormal * Vector3.up; coordinateSystem.SetFloorNormal(normalVector, coordinateSystem.rootDevice); coordinateSystem.SetDistanceFromFloor(dictionaryDistanceFromFloor, coordinateSystem.rootDevice); //check whether the kinect camera is actually connected if (enableKinect) { OpenNISettingsManager settingsManager = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; if (settingsManager.UserGenrator == null || !settingsManager.UserGenrator.Valid) { Debug.LogError("Could not start OpenNI! Check your Kinect connection."); GetComponentInChildren <RUISKinectDisabler>().KinectNotAvailable(); } } if (!enableKinect2) { Debug.Log("Kinect 2 is disabled from RUISInputManager."); BodySourceManager kinect2Manager = GetComponentInChildren <BodySourceManager>(); if (kinect2Manager) { kinect2Manager.gameObject.SetActive(false); } } else { bool kinect2FoundBySystem = false; 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; } else { Debug.LogError("Kinect 2 was NOT detected by the system. Disabling Kinect 2 in RUISInputManager."); } } catch (System.Exception e) { Debug.LogError("Kinect 2 was NOT detected by the system. Disabling Kinect 2 in RUISInputManager.\n" + e.Message); } if (!kinect2FoundBySystem) { enableKinect2 = false; } } if ((enableKinect && kinectFloorDetection) || (enableKinect2 && kinect2FloorDetection)) { StartFloorDetection(); } //if (enablePSMove) // { // RUISPSMoveWand[] controllers = GetComponentsInChildren<RUISPSMoveWand>(); // moveControllers = new RUISPSMoveWand[controllers.Length]; // foreach (RUISPSMoveWand controller in controllers) // { // moveControllers[controller.controllerId] = controller; // } // } }