private void TakeSample() { OpenNI.SkeletonJointPosition jointPosition; bool success = kinectSelection.GetPlayer(0).GetSkeletonJointPosition(OpenNI.SkeletonJoint.RightHand, out jointPosition); timeSinceLastSample += Time.deltaTime; //check if we should take sample if (!success || !psMoveWrapper.sphereVisible[calibratingPSMoveControllerId] || psMoveWrapper.handleVelocity[calibratingPSMoveControllerId].magnitude >= 10.0f || jointPosition.Confidence <= 0.5 || timeSinceLastSample < timeBetweenSamples) { return; } rawPSMoveSamples.Add(psMoveWrapper.handlePosition[calibratingPSMoveControllerId]); psMoveSamples.Add(coordinateSystem.ConvertMovePosition(psMoveWrapper.handlePosition[calibratingPSMoveControllerId])); kinectSamples.Add(coordinateSystem.ConvertKinectPosition(jointPosition.Position)); numberOfSamplesTaken++; timeSinceLastSample = 0; calibrationSpheres.Add(Instantiate(calibrationSphere, coordinateSystem.ConvertKinectPosition(jointPosition.Position), Quaternion.identity) as GameObject); }
private Vector3 getSample(RUISDevice device) { Vector3 sample = new Vector3(0, 0, 0); Vector3 tempSample; if (device == RUISDevice.Kinect_1) { OpenNI.SkeletonJointPosition jointPosition; bool success = kinectSelection.GetPlayer(0).GetSkeletonJointPosition(OpenNI.SkeletonJoint.RightHand, out jointPosition); if (success && jointPosition.Confidence >= 0.5) { tempSample = coordinateSystem.ConvertRawKinectLocation(jointPosition.Position); if (Vector3.Distance(tempSample, lastKinectSample) > 0.1) { sample = tempSample; lastKinectSample = sample; this.guiTextUpperLocal = ""; } else { this.guiTextUpperLocal = "Not enough hand movement."; } } } if (device == RUISDevice.Oculus_DK2) { Ovr.Posef headpose = RUISOVRManager.ovrHmd.GetTrackingState().HeadPose.ThePose; float px = headpose.Position.x; float py = headpose.Position.y; float pz = -headpose.Position.z; // This needs to be negated TODO: might change with future OVR version tempSample = new Vector3(px, py, pz); tempSample = coordinateSystem.ConvertRawOculusDK2Location(tempSample); if ((Vector3.Distance(tempSample, lastOculusDK2Sample) > 0.1) && (RUISOVRManager.ovrHmd.GetTrackingState().StatusFlags & (uint)StatusBits.PositionTracked) != 0) // Code from OVRManager.cs { sample = tempSample; lastOculusDK2Sample = sample; this.guiTextUpperLocal = ""; } else { this.guiTextUpperLocal = "Not enough hand movement."; } } return(sample); }
private Vector3 getSample(RUISDevice device) { Vector3 sample = new Vector3(0, 0, 0); Vector3 tempSample; if (device == RUISDevice.Kinect_1) { OpenNI.SkeletonJointPosition jointPosition; bool success = kinectSelection.GetPlayer(0).GetSkeletonJointPosition(OpenNI.SkeletonJoint.RightHand, out jointPosition); if (success && jointPosition.Confidence >= 0.5) { tempSample = coordinateSystem.ConvertRawKinectLocation(jointPosition.Position); if (Vector3.Distance(tempSample, lastKinectSample) > 0.1) { sample = tempSample; lastKinectSample = sample; this.guiTextUpperLocal = ""; } else { this.guiTextUpperLocal = "Not enough hand movement."; } } } if (device == RUISDevice.PS_Move) { if (psMoveWrapper.sphereVisible[calibratingPSMoveControllerId] && psMoveWrapper.handleVelocity[calibratingPSMoveControllerId].magnitude <= 10.0f) { tempSample = coordinateSystem.ConvertRawPSMoveLocation(psMoveWrapper.handlePosition[calibratingPSMoveControllerId]); if (Vector3.Distance(tempSample, lastPSMoveSample) > 0.1) { sample = tempSample; lastPSMoveSample = sample; this.guiTextUpperLocal = ""; } else { this.guiTextUpperLocal = "Not enough hand movement."; } } } return(sample); }
void DrawLineBetweenJoints(OpenNI.SkeletonJoint first, OpenNI.SkeletonJoint second) { NISelectedPlayer player = playerSelection.GetPlayer(0); OpenNI.SkeletonJointPosition firstJointPosition; player.GetSkeletonJointPosition(first, out firstJointPosition); OpenNI.SkeletonJointPosition secondJointPosition; player.GetSkeletonJointPosition(second, out secondJointPosition); if (firstJointPosition.Confidence <= 0.5 || secondJointPosition.Confidence <= 0.5) { return; } OpenNI.Point3D firstJointScreenPosition = depthGenerator.ConvertRealWorldToProjective(firstJointPosition.Position); OpenNI.Point3D secondJointScreenPosition = depthGenerator.ConvertRealWorldToProjective(secondJointPosition.Position); DrawLine.DrawSimpleLine(ref mapPixels, (int)(width - firstJointScreenPosition.X / factor), (int)(height - firstJointScreenPosition.Y / factor), (int)(width - secondJointScreenPosition.X / factor), (int)(height - secondJointScreenPosition.Y / factor), width, height, Color.white); }
private Vector3 getSample(RUISDevice device) { Vector3 sample = new Vector3(0, 0, 0); Vector3 tempSample; updateBodyData(); if (device == RUISDevice.Kinect_2) { Kinect.Body[] data = kinect2SourceManager.GetBodyData(); bool trackedBodyFound = false; int foundBodies = 0; foreach (var body in data) { foundBodies++; if (body.IsTracked) { if (trackingIDtoIndex[body.TrackingId] == 0) { trackedBodyFound = true; if (body.Joints[Kinect.JointType.HandRight].TrackingState == Kinect.TrackingState.Tracked) { tempSample = new Vector3(body.Joints[Kinect.JointType.HandRight].Position.X, body.Joints[Kinect.JointType.HandRight].Position.Y, body.Joints[Kinect.JointType.HandRight].Position.Z); tempSample = coordinateSystem.ConvertRawKinect2Location(tempSample); if (Vector3.Distance(tempSample, lastKinect2Sample) > 0.2) { sample = tempSample; lastKinect2Sample = sample; device1Error = false; if (!device2Error) { this.guiTextUpperLocal = ""; } } else { device1Error = true; this.guiTextUpperLocal = "Not enough hand movement."; } } } } } if (!trackedBodyFound && foundBodies > 1) { device1Error = true; this.guiTextUpperLocal = "Step out of the Kinect's\nview and come back."; } } if (device == RUISDevice.Kinect_1) { OpenNI.SkeletonJointPosition jointPosition; bool success = kinectSelection.GetPlayer(0).GetSkeletonJointPosition(OpenNI.SkeletonJoint.RightHand, out jointPosition); if (success && jointPosition.Confidence >= 0.5) { tempSample = coordinateSystem.ConvertRawKinectLocation(jointPosition.Position); if (Vector3.Distance(tempSample, lastKinectSample) > 0.2) { sample = tempSample; lastKinectSample = sample; device2Error = false; if (!device1Error) { this.guiTextUpperLocal = ""; } } else { device2Error = true; // this.guiTextUpperLocal = "Not enough hand movement."; } } else { device2Error = true; // this.guiTextUpperLocal = "Not enough hand movement."; } } return(sample); }