Example #1
0
    private void updateKinectFloorData()
    {
        if (coordinateSystem)
        {
            coordinateSystem.ResetKinectFloorNormal();
            coordinateSystem.ResetKinectDistanceFromFloor();

            OpenNI.Plane3D floor            = sceneAnalyzer.Floor;
            Vector3        newFloorNormal   = new Vector3(floor.Normal.X, floor.Normal.Y, floor.Normal.Z).normalized;
            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;

            //transform the point from Kinect's coordinate system rotation to Unity's rotation
            closestFloorPointToKinect = Quaternion.FromToRotation(newFloorNormal, Vector3.up) * closestFloorPointToKinect;

            //floorPlane.transform.position = closestFloorPointToKinect;


            coordinateSystem.SetKinectFloorNormal(newFloorNormal);
            //floorNormal = newFloorNormal.normalized;
            coordinateSystem.SetKinectDistanceFromFloor(closestFloorPointToKinect.magnitude);

            //if(!usingExistingSceneAnalyzer)
            //	sceneAnalyzer.StopGenerating();
        }
    }