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);
    }
Ejemplo n.º 3
0
    private void updateKinect2FloorData()
    {
        Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager;

        bool canAccessKinect2 = false;

        try
        {
            if (coordinateSystem != null && kinect2SourceManager != null &&
                kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen&& kinect2SourceManager.GetSensor().IsAvailable)
            {
                canAccessKinect2 = true;
            }
        }
        catch {}

        if (canAccessKinect2)
        {
            if (coordinateSystem.rootDevice == RUISDevice.Kinect_2)
            {
                coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_2);
                coordinateSystem.ResetDistanceFromFloor(RUISDevice.Kinect_2);
            }


            Windows.Kinect.Vector4 kinect2FloorPlane = kinect2SourceManager.GetFlootClipPlane();

            //print (kinect2FloorPlane.X + " " + kinect2FloorPlane.Y + " " + kinect2FloorPlane.Z  + " " +  kinect2FloorPlane.W);

            Vector3 kinect2FloorNormal = new Vector3(kinect2FloorPlane.X, kinect2FloorPlane.Y, kinect2FloorPlane.Z);
            kinect2FloorNormal.Normalize();

            float kinect2DistanceFromFloor = kinect2FloorPlane.W / Mathf.Sqrt(kinect2FloorNormal.sqrMagnitude);

            if (float.IsNaN(kinect2DistanceFromFloor))
            {
                kinect2DistanceFromFloor = 0;
            }
            if (float.IsNaN(kinect2FloorNormal.x) || kinect2FloorNormal.sqrMagnitude < 0.1f)
            {
                kinect2FloorNormal = Vector3.up;
            }

            if (coordinateSystem.rootDevice == RUISDevice.Kinect_2)
            {
                coordinateSystem.SetFloorNormal(kinect2FloorNormal, RUISDevice.Kinect_2);
                coordinateSystem.SetDistanceFromFloor(kinect2DistanceFromFloor, RUISDevice.Kinect_2);
            }
            Debug.Log("Updated Kinect 2 floor normal " + kinect2FloorNormal + " and floor distance (" + kinect2DistanceFromFloor + ")");
        }
    }