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(); } }
private void UpdateFloorNormal() { coordinateSystem.ResetKinectFloorNormal(); 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); /*OpenNI.SkeletonJointPosition torsoPosition; * bool torsoSuccess = kinectSelection.GetPlayer(0).GetSkeletonJointPosition(OpenNI.SkeletonJoint.Torso, out torsoPosition); * * * OpenNI.Point3D positionDifference = new OpenNI.Point3D(torsoPosition.Position.X - footPosition.Position.X, * torsoPosition.Position.Y - footPosition.Position.Y, * torsoPosition.Position.Z - footPosition.Position.Z); * skeleton.transform.position = coordinateSystem.ConvertKinectPosition(floor.Point) + coordinateSystem.ConvertKinectPosition(positionDifference); */ //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; //closestFloorPointToKinect = new Vector3(0, closestFloorPointToKinect.magnitude, 0); floorPlane.transform.position = closestFloorPointToKinect; //show the tilt of the kinect camera on the kinect model kinectModelObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, newFloorNormal); coordinateSystem.SetKinectFloorNormal(newFloorNormal); floorNormal = newFloorNormal.normalized; coordinateSystem.SetKinectDistanceFromFloor(closestFloorPointToKinect.magnitude); }