/// @brief Gets a reference joint position and orientation on the joint. /// /// This method gets the reference joint information for the joint. The reference /// is the joint position and transformation at the time when the user was chosen AND /// started tracking. /// @param joint The joint we want information on. /// @param referenceTransform [out] The reference Transform. /// @return True on success and false on failure (e.g. an illegal joint or the user is not tracking). public bool GetReferenceSkeletonJointTransform(SkeletonJoint joint, out SkeletonJointTransformation referenceTransform) { referenceTransform=NIPlayerCandidateObject.m_InitializedZero; if(!Valid) return false; return m_user.GetReferenceSkeletonJointTransform(joint, out referenceTransform); }
Vector3 getJointVector3(uint user, SkeletonJoint joint) { SkeletonJointPosition pos = new SkeletonJointPosition (); skeletonCapability.GetSkeletonJointPosition (user, joint, ref pos); Vector3 v3pos = new Vector3 (-pos.position.X, pos.position.Y, pos.position.Z); return v3pos / scale + bias; }
void MoveTransform( uint userId, SkeletonJoint joint, Transform dest) { SkeletonJointPosition pos = new SkeletonJointPosition(); this.skeletonCapbility.GetSkeletonJointPosition(userId, joint, ref pos); Vector3 v3pos = new Vector3(pos.position.X, pos.position.Y, pos.position.Z); dest.position = (v3pos / scale) + bias; }
private void IterateHierarchyForSkeletonRecursive(SceneGraph curNode, List<SkeletonJoint> jointList, int parentId) { switch (curNode.NodeType) { case J3DFormat.HierarchyDataTypes.NewNode: parentId = jointList.Count - 1; break; case J3DFormat.HierarchyDataTypes.Joint: J3DFormat.Joint j3dJoint = _file.Joints.GetJoint(curNode.DataIndex); SkeletonJoint joint = new SkeletonJoint(); joint.Name = _file.Joints.GetString(_file.Joints.GetStringTableEntry(_file.Joints.GetStringIndex(curNode.DataIndex))); //Todo: You have got to be kidding me. Vector3 jointAngles = j3dJoint.GetRotation().ToDegrees(); joint.Rotation = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(jointAngles.X)) * Matrix4.CreateRotationY(MathHelper.DegreesToRadians(jointAngles.Y)) * Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(jointAngles.Z)); //joint.Rotation.Normalize(); joint.Position = j3dJoint.GetTranslation(); joint.ParentId = parentId; joint.Scale = j3dJoint.GetScale(); Console.WriteLine("{0} - Pos: {1} Rot: {2}", joint, joint.Position, jointAngles); jointList.Add(joint); break; } foreach (SceneGraph child in curNode.Children) { IterateHierarchyForSkeletonRecursive(child, jointList, parentId); } }
/// @brief Gets a reference joint position and orientation on the joint. /// /// This method gets the reference joint information for the joint. The reference /// is the joint position and transformation at the time when the user was chosen AND /// started tracking. /// @param joint The joint we want information on. /// @param referenceTransform [out] The reference Transform. /// @return True on success and false on failure (e.g. an illegal joint or the user is not tracking). public bool GetReferenceSkeletonJointTransform(SkeletonJoint joint, out SkeletonJointTransformation referenceTransform) { referenceTransform = m_InitializedZero; if (m_playerStatus != UserStatus.Tracking || m_openNIUserID <= 0) return false; referenceTransform = m_referenceSkeletonJointTransform[joint]; return true; }
/// @brief Utility method to update JointInfo for the joint /// /// @param joint the joint we want to update the info for /// @param jointPos the position of the joint /// @param posConf the confidence of the position of the joint /// @param jointRot the quaternion rotation of the joint /// @param rotConf the confidence of the rotation of the joint public virtual void UpdateJointInfoForJoint(SkeletonJoint joint, Vector3 jointPos, float posConf, Quaternion jointRot, float rotConf) { if (m_jointsInfo[(int)joint] == null) return; // irrelevant joint m_jointsInfo[(int)joint].m_jointPos = jointPos; m_jointsInfo[(int)joint].m_posConfidence = posConf; m_jointsInfo[(int)joint].m_rotation = jointRot; m_jointsInfo[(int)joint].m_rotConfidence = rotConf; }
SkeletonJointPosition GetJointPosition(uint user, SkeletonJoint joint) { SkeletonJointPosition pos = new SkeletonJointPosition(); this.skeletonCapbility.GetSkeletonJointPosition(user, joint, ref pos); if (pos.position.Z == 0) { pos.fConfidence = 0; } else { pos.position = this.depth.ConvertRealWorldToProjective(pos.position); } return pos; }
// 骨格の線を引く void DrawLine(int player, SkeletonJoint eJoint1, SkeletonJoint eJoint2) { // 各箇所の座標を取得する SkeletonJointPosition joint1 = skelton.GetSkeletonJointPosition(player, eJoint1); SkeletonJointPosition joint2 = skelton.GetSkeletonJointPosition(player, eJoint2); if (joint1.Confidence < 0.5 || joint2.Confidence < 0.5) { return; } // 現実の座標から画面の座標に変換する Point3D[] pt = new Point3D[] { joint1.Position, joint2.Position }; pt = depth.ConvertRealWorldToProjective(pt); Graphics g = Graphics.FromImage(bitmap); g.DrawLine(pen, pt[0].X, pt[0].Y, pt[1].X, pt[1].Y); }
/// @brief Gets the current joint transformation for a specific joint /// /// @param joint The joint we want the transformation to. /// @param curTransform [out] The current joint transformation /// @return True on success and false on failure (e.g. the user is not tracking). /// @note An exception might occur if there is an error (e.g. an illegal joint is used). public bool GetSkeletonJoint(SkeletonJoint joint, out SkeletonJointTransformation curTransform) { curTransform = NIPlayerCandidateObject.m_InitializedZero; if (!Tracking) return false; if (m_user.Skeleton == null) return false; try { curTransform = m_user.Skeleton.GetSkeletonJoint(m_user.OpenNIUserID, joint); } catch { return false; } return true; }
public void DrawOrientation(ref WriteableBitmap image, int id, UserGenerator userGenerator, SkeletonJoint joint, Point3D corner) { SkeletonJointOrientation orientation = new SkeletonJointOrientation(); SkeletonJointPosition position = new SkeletonJointPosition(); position = userGenerator.SkeletonCapability.GetSkeletonJointPosition(id, joint); orientation = userGenerator.SkeletonCapability.GetSkeletonJointOrientation(id, joint); if (position.Confidence != 1 && orientation.Confidence != 1) { return; } SkeletonJointPosition v1 = new SkeletonJointPosition(); SkeletonJointPosition v2 = new SkeletonJointPosition(); v1.Confidence = v2.Confidence = 1; v1.Position = position.Position; v2.Position = new Point3D(v1.Position.X + 100 * orientation.X1, v1.Position.Y + 100 * orientation.Y1, v1.Position.Z + 100 * orientation.Z1); DrawTheLine(ref image, ref v1, ref v2); v1.Position = position.Position; v2.Position = new Point3D(v1.Position.X + 100 * orientation.X2, v1.Position.Y + 100 * orientation.Y2, v1.Position.Z + 100 * orientation.Z2); DrawTheLine(ref image, ref v1, ref v2); v1.Position = position.Position; v2.Position = new Point3D(v1.Position.X + 100 * orientation.X3, v1.Position.Y + 100 * orientation.Y3, v1.Position.Z + 100 * orientation.Z3); DrawTheLine(ref image, ref v1, ref v2); }
/// @brief Gets the current joint position for a specific joint /// /// @param joint The joint we want the position to. /// @param curPos [out] The current joint rotation /// @return True on success and false on failure (e.g. the user is not tracking). /// @note An exception might occur if there is an error (e.g. an illegal joint is used). public bool GetSkeletonJointPosition(SkeletonJoint joint, out SkeletonJointPosition curPos) { curPos = NIPlayerCandidateObject.m_InitializedZero.Position; if (!Tracking) return false; if (m_user.Skeleton == null) return false; try { curPos = m_user.Skeleton.GetSkeletonJointPosition(m_user.OpenNIUserID, joint); } catch { return false; } return true; }
/// @brief a utility method to update joint position /// /// This utility method receives a joint and unscaled position (x,y,z) and moves the joint there. /// it makes sure the joint has been attached and that scale is applied. /// @param joint The joint to update (the method makes sure it is legal) /// @param xPos The unscaled position along the x axis (scale will be applied) /// @param yPos The unscaled position along the y axis (scale will be applied) /// @param zPos The unscaled position along the z axis (scale will be applied) protected void UpdateJointPosition(SkeletonJoint joint, float xPos, float yPos, float zPos) { if(((int)joint)>=m_jointTransforms.Length || m_jointTransforms[(int)joint] == null) return; // an illegal joint Vector3 tmpPos = Vector3.zero; tmpPos.x = xPos; tmpPos.y = yPos; tmpPos.z = zPos; tmpPos *= m_scale; m_jointTransforms[(int)joint].localPosition = tmpPos; }
/// @brief updates a single joint /// /// This method updates a single joint. The decision of what to update (orientation, position) /// depends on m_updateOrientation and m_updateJointPositions. Only joints with high confidence /// are updated. @note it is possible to update only position or only orientation even though both /// are expected if the confidence of one is low. /// @param centerOffset the new central position /// @param joint the joint we want to update /// @param skelTrans the new transformation of the joint protected void UpdateJoint(SkeletonJoint joint, SkeletonJointTransformation skelTrans, SkeletonJointPosition centerOffset) { // make sure something is hooked up to this joint if ((int)joint >= m_jointTransforms.Length || !m_jointTransforms[(int)joint]) { return; } // if we have debug lines to draw we need to collect the data. if (m_linesDebugger!=null) { Vector3 pos = CalcJointPosition(joint, ref skelTrans, ref centerOffset) + transform.position; float posConf = skelTrans.Position.Confidence; Quaternion rot = CalcRotationForJoint(joint, ref skelTrans, ref centerOffset); float rotConf = skelTrans.Orientation.Confidence; m_linesDebugger.UpdateJointInfoForJoint(joint, pos, posConf, rot, rotConf); } // modify orientation (if needed and confidence is high enough) if (m_updateOrientation && skelTrans.Orientation.Confidence >= 0.5) { m_jointTransforms[(int)joint].rotation=CalcRotationForJoint(joint, ref skelTrans, ref centerOffset); } // modify position (if needed, and confidence is high enough) if (m_updateJointPositions && skelTrans.Position.Confidence>=0.5f) { m_jointTransforms[(int)joint].localPosition = CalcJointPosition(joint, ref skelTrans, ref centerOffset); } }
/// @brief Utility method to calculate the rotation of a joint /// /// This method receives joint information and calculates the rotation of the joint in Unity /// coordinate system. /// @param centerOffset the new central position /// @param joint the joint we want to calculate the rotation for /// @param skelTrans the new transformation of the joint /// @return the rotation of the joint in Unity coordinate system protected Quaternion CalcRotationForJoint(SkeletonJoint joint,ref SkeletonJointTransformation skelTrans, ref SkeletonJointPosition centerOffset) { // In order to convert the skeleton's orientation to Unity orientation we will // use the Quaternion.LookRotation method to create the relevant rotation Quaternion. // for Quaternion.LookRotation to work it needs a "forward" vector and an "upward" vector. // These are generally the "Z" and "Y" axes respectively in the sensor's coordinate // system. The orientation received from the skeleton holds these values in their // appropriate members. // Get the forward axis from "z". Point3D sensorForward = Point3D.ZeroPoint; sensorForward.X = skelTrans.Orientation.Z1; sensorForward.Y = skelTrans.Orientation.Z2; sensorForward.Z = skelTrans.Orientation.Z3; // convert it to Unity Vector3 worldForward = NIConvertCoordinates.ConvertPos(sensorForward); worldForward *= -1.0f; // because the Unity "forward" axis is opposite to the world's "z" axis. if (worldForward.magnitude == 0) return Quaternion.identity; // we don't have a good point to work with. // Get the upward axis from "Y". Point3D sensorUpward = Point3D.ZeroPoint; sensorUpward.X = skelTrans.Orientation.Y1; sensorUpward.Y = skelTrans.Orientation.Y2; sensorUpward.Z = skelTrans.Orientation.Y3; // convert it to Unity Vector3 worldUpwards = NIConvertCoordinates.ConvertPos(sensorUpward); if (worldUpwards.magnitude == 0) return Quaternion.identity; // we don't have a good point to work with. Quaternion jointRotation = Quaternion.LookRotation(worldForward, worldUpwards); Quaternion newRotation = transform.rotation * jointRotation * m_jointsInitialRotations[(int)joint]; // we try to limit the speed of the change. return Quaternion.Slerp(m_jointTransforms[(int)joint].rotation, newRotation, Time.deltaTime * m_rotationDampening); }
/** * \brief Get a string representing the joint name for a specific joint id */ public static string getJointName(SkeletonJoint id) { switch (id) { case SkeletonJoint.HEAD: return("head"); case SkeletonJoint.NECK: return("neck"); case SkeletonJoint.TORSO: return("torso"); case SkeletonJoint.WAIST: return("waist"); case SkeletonJoint.LEFT_SHOULDER: return("leftShoulder"); case SkeletonJoint.LEFT_ELBOW: return("leftElbow"); case SkeletonJoint.LEFT_WRIST: return("leftWrist"); case SkeletonJoint.LEFT_HAND: return("leftHand"); case SkeletonJoint.RIGHT_SHOULDER: return("rightShoulder"); case SkeletonJoint.RIGHT_ELBOW: return("rightElbow"); case SkeletonJoint.RIGHT_WRIST: return("rightWrist"); case SkeletonJoint.RIGHT_HAND: return("rightHand"); case SkeletonJoint.LEFT_HIP: return("leftHip"); case SkeletonJoint.LEFT_KNEE: return("leftKnee"); case SkeletonJoint.LEFT_ANKLE: return("leftAnkle"); case SkeletonJoint.LEFT_FOOT: return("leftFoot"); case SkeletonJoint.RIGHT_HIP: return("rightHip"); case SkeletonJoint.RIGHT_KNEE: return("rightKnee"); case SkeletonJoint.RIGHT_ANKLE: return("rightAnkle"); case SkeletonJoint.RIGHT_FOOT: return("rightFoot"); case SkeletonJoint.FACE_CHIN: return("faceChin"); case SkeletonJoint.FACE_FOREHEAD: return("faceForeHead"); case SkeletonJoint.FACE_LEFT_EAR: return("faceLeftEar"); case SkeletonJoint.FACE_NOSE: return("faceNose"); case SkeletonJoint.FACE_RIGHT_EAR: return("faceRightEar"); default: return(""); } }
private void DrawLine(Graphics g, Color color, Dictionary<SkeletonJoint, SkeletonJointPosition> dict, SkeletonJoint j1, SkeletonJoint j2) { Point3D pos1 = dict[j1].Position; Point3D pos2 = dict[j2].Position; if (dict[j1].Confidence == 0 || dict[j2].Confidence == 0) return; g.DrawLine(new Pen(color), new Point((int)pos1.X, (int)pos1.Y), new Point((int)pos2.X, (int)pos2.Y)); }
public bool IsJointAvailable(SkeletonJoint joint) { return SafeNativeMethods.xnIsJointAvailable(this.InternalObject, joint); }
/// <summary> /// Loads the 3D data for a specific skeleton joint. /// </summary> private void GetJoint3D(SkeletonCapability source, int user, SkeletonJoint joint, JointDictionary target) { SkeletonJointPosition pos; if (joint == SkeletonJoint.Waist) { // Calculate the joint position as arithmetic mean of right // and left hip joints, as it is not possible to poll it // directly. pos = new SkeletonJointPosition(); SkeletonJointPosition posLeft = source.GetSkeletonJointPosition(user, SkeletonJoint.LeftHip); SkeletonJointPosition posRight = source.GetSkeletonJointPosition(user, SkeletonJoint.RightHip); if (posLeft.Position.Z == 0 || posRight.Position.Z == 0) { pos.Confidence = 0; pos.Position = new Point3D( (posLeft.Position.X + posRight.Position.X) / 2, (posLeft.Position.Y + posRight.Position.Y) / 2, 0); } else { pos.Confidence = Math.Min(posLeft.Confidence, posRight.Confidence); pos.Position = new Point3D( (posLeft.Position.X + posRight.Position.X) / 2, (posLeft.Position.Y + posRight.Position.Y) / 2, (posLeft.Position.Z + posRight.Position.Z) / 2); } } else { pos = source.GetSkeletonJointPosition(user, joint); if (pos.Position.Z == 0) { pos.Confidence = 0; } } target[joint] = pos; }
/// @brief Initializes the joint /// /// @note a line containing a joint not initialized will not be drawn. This means that it is /// possible to use a debugger with lots of lines and connect it to a skeleton controller with few /// joints. The skeleton controller is responsible for setting the joints and therefore irrelevant /// joints will simply not be used. /// @param joint the joint to initialize. public virtual void InitJoint(SkeletonJoint joint) { m_jointsInfo[(int)joint] = new JointInfo(); }
public SkeletonJoint m_target; ///< the target joint of the line #endregion Fields #region Constructors /// constructor /// @param source the source joint of the line /// @param target the target joint of the line public DebugLineDef(SkeletonJoint source, SkeletonJoint target) { m_source = source; m_target = target; }
public bool IsJointAvailable(SkeletonJoint joint) { return(SafeNativeMethods.xnIsJointAvailable(this.InternalObject, joint)); }
/// constructor. Sets the source and target to invalid. public DebugLineDef() { m_source = SkeletonJoint.Invalid; m_target = SkeletonJoint.Invalid; }
private void DrawLine(byte[] fullmap, Color color, Dictionary<SkeletonJoint, SkeletonJointPosition> dict, SkeletonJoint j1, SkeletonJoint j2) { OpenNI.Point3D pos1 = this.depthGenerator.ConvertRealWorldToProjective(dict[j1].Position); OpenNI.Point3D pos2 = this.depthGenerator.ConvertRealWorldToProjective(dict[j2].Position); if (dict[j1].Confidence == 0 || dict[j2].Confidence == 0) return; float deltaX = pos2.X - pos1.X; float deltaY = pos2.Y - pos1.Y; float maxDelta = Math.Max(deltaX, deltaY); float curX = pos1.X; float curY = pos1.Y; for (int i = 0; i < maxDelta; i++) { int index = (int)(curX * 3 + curY * 640 * 3); fullmap[index] = color.R; fullmap[index + 1] = color.G; fullmap[index + 2] = color.B; curX += deltaX / maxDelta; curY += deltaY / maxDelta; } }
private void GetJoint(int user, SkeletonJoint joint) { SkeletonJointPosition pos = this.skeletonCapability.GetSkeletonJointPosition(user, joint); if (pos.Position.Z == 0) { pos.Confidence = 0; } else { //pos.position = this.depthGenerator.ConvertRealWorldToProjective(pos.position); } lock (joints) { try { if (!this.joints.ContainsKey(user)) { this.joints.Add(user, new Dictionary<SkeletonJoint, SkeletonJointPosition>()); } else if (!this.joints[user].ContainsKey(joint)) { this.joints[user].Add(joint, pos); } else { this.joints[user][joint] = pos; } } catch (NullReferenceException) { //eat it } } }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="joint"></param> /// <param name="jointRef"></param> /// <param name="screenPlaneZoffset"></param> /// <returns>true if touched </returns> private void DetectVirtualRelativeTouch(User user, uint hand, SkeletonJoint jointRef, int screenPlaneZoffset) { SkeletonJoint jointHand; if (hand == 0) { jointHand = SkeletonJoint.LeftHand; } else { jointHand = SkeletonJoint.RightHand; } Point3D pos = user.Joints[jointHand].Position; Point3D posRef = user.Joints[jointRef].Position; InputStatus status; //hand not probably tracked return if (user.Joints[jointHand].Confidence < 0.6) { sendContact(user.updateHand(hand, InputStatus.UNKNOWN)); return; } //if the reference is not valid, only cursor mode will be reliable else if (user.Joints[jointRef].Confidence < 0.6) { status = InputStatus.CURSOR; } else { //both joints are well tracked, touch detection is executed if (pos.Z > (posRef.Z - screenPlaneZoffset)) {//No Touch status = InputStatus.CURSOR; } else {//Touch status = InputStatus.TOUCHED; } } //convert kinectcoordinates to screencoordinates pos.X = virtualScreenXStart + virtualScreenConvertFactorX * (pos.X - kinectXCrop); pos.Y = virtualScreenYStart + virtualScreenConvertFactorY * (pos.Y - kinectYCrop); HandContact contact = user.updateHand(pos, hand, status); sendContact(contact); }
/// <summary> /// Connects the to provided joints with each other. /// </summary> private void DrawLine(Graphics g, Color color, Dictionary<SkeletonJoint, SkeletonJointPosition> dict, SkeletonJoint j1, SkeletonJoint j2, double confidenceThreshold) { if (!(dict.ContainsKey(j1) && dict.ContainsKey(j2))) return; Point3D pos1 = dict[j1].Position; Point3D pos2 = dict[j2].Position; int marker_rect_half_width = 3; int marker_rect_half_height = 3; bool draw_line = true; Brush marker_brush; // Draw the threshold markers if (!(pos1.X.Equals(float.NaN) || pos1.Y.Equals(float.NaN))) { if (dict[j1].Confidence < confidenceThreshold) marker_brush = Brushes.Red; else marker_brush = Brushes.Green; g.FillEllipse(marker_brush, new Rectangle((int)pos1.X - marker_rect_half_width, (int)pos1.Y - marker_rect_half_height, marker_rect_half_width * 2 + 1, marker_rect_half_height * 2 + 1)); } else draw_line = false; if (!(pos2.X.Equals(float.NaN) || pos2.Y.Equals(float.NaN))) { if (dict[j2].Confidence < confidenceThreshold) marker_brush = Brushes.Red; else marker_brush = Brushes.Green; g.FillEllipse(marker_brush, new Rectangle((int)pos2.X - marker_rect_half_width, (int)pos2.Y - marker_rect_half_height, marker_rect_half_width * 2 + 1, marker_rect_half_height * 2 + 1)); } else draw_line = false; if (draw_line) { using (Pen pen = new Pen(color)) { g.DrawLine(pen, new Point((int)pos1.X, (int)pos1.Y), new Point((int)pos2.X, (int)pos2.Y)); } } }
public RecognitionCorrectionHint(SkeletonJoint joint = SkeletonJoint.NUM_JOINTS, float dirX = 0, float dirY = 0, float dirZ = 0, bool isAngle = false, ChangeType changeType = ChangeType.SPEED, ChangeDirection changeDir = ChangeDirection.DIFFERENT, int failedState = -1) { m_joint = joint; m_dirX = dirX; m_dirY = dirY; m_dirZ = dirZ; m_isAngle = isAngle; m_changeType = changeType; m_changeDirection = changeDir; m_failedState = failedState; }
public SkeletonJointPosition GetSkeletonJointPosition(UserID user, SkeletonJoint joint) { SkeletonJointPosition position = new SkeletonJointPosition(); int status = SafeNativeMethods.xnGetSkeletonJointPosition(this.InternalObject, user, joint, ref position); WrapperUtils.ThrowOnError(status); return position; }
public static extern bool GetJointTransformation(uint userID, SkeletonJoint joint, ref SkeletonJointTransformation pTransformation);
public void SetJointActive(SkeletonJoint joint, bool state) { int status = SafeNativeMethods.xnSetJointActive(this.InternalObject, joint, state); WrapperUtils.ThrowOnError(status); }
/// @brief Utility method to calculate the @b LOCAL position of a joint /// /// This method receives joint information and calculates the @b LOCAL position rotation of the joint /// (compare to its parent transform) in Unity coordinate system. /// @param centerOffset the new central position /// @param joint the joint we want to calculate the position for /// @param skelTrans the new transformation of the joint /// @return the @b LOCAL position rotation of the joint (compare to its parent transform) in /// Unity coordinate system protected Vector3 CalcJointPosition(SkeletonJoint joint, ref SkeletonJointTransformation skelTrans, ref SkeletonJointPosition centerOffset) { Vector3 v3pos=NIConvertCoordinates.ConvertPos(skelTrans.Position.Position); Vector3 v3Center = NIConvertCoordinates.ConvertPos(centerOffset.Position); v3pos -= v3Center; return v3pos*m_scale; }
private void GetJoint(int user, SkeletonJoint joint) { SkeletonJointPosition pos = this.skeletonCapbility.GetSkeletonJointPosition(user, joint); if (pos.Position.Z == 0) { pos.Confidence = 0; } else { pos.Position = this.depth.ConvertRealWorldToProjective(pos.Position); } this.joints[user][joint] = pos; }