Example #1
0
    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);
    }
Example #4
0
    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);
    }