protected double getAngle(JointObject j1, JointObject j2, JointObject j3) { Vector3D v1 = new Vector3D(j2.x - j1.x, j2.y - j1.y, j2.z - j1.z); Vector3D v2 = new Vector3D(j2.x - j3.x, j2.y - j3.y, j2.z - j3.z); return(Vector3D.AngleBetween(v1, v2)); }
Vector3 generateVector(JointObject joint) { Vector3 vector = new Vector3(); vector.Set( joint.x * xMultiplier + xBias, joint.y * yMultiplier + yBias, (joint.z * zMultiplier + zBias) * -1); return(vector); }
public void Render() { var movement = Time.deltaTime * SPEED; var headPos = processJoint(Skeleton.GetJoint(Skeleton.HEAD)); if (headObject == null) { headObject = Instantiate(HeadObjectPrefab) as GameObject; headObject.transform.SetParent(this.transform, false); headObject.transform.localPosition = headPos; } var headMove = Vector3.Lerp(headObject.transform.localPosition, headPos, movement); headObject.transform.localPosition = headMove; foreach (var jArray in SkeletonUtils.GetOrderedJointPairs(Skeleton)) { try{ JointObject jointObject = null; var key = String.Format("{0}-{1}-{2}", Skeleton.SkeletonID, jArray[0].Item1, jArray[1].Item1); jointMap.TryGetValue(key, out jointObject); var v1 = processJoint(jArray[0].Item2); var v2 = processJoint(jArray[1].Item2); if (jointObject == null) { jointObject = new JointObject() { Start = v1, End = v2, GameObject = Instantiate(JointConnectionPrefab) }; drawLine(jointObject.GameObject, v1, v2, movement); jointObject.GameObject.name = key; jointMap.Add(key, jointObject); jointObject.GameObject.transform.SetParent(this.transform, false); } else { var v1Lerp = Vector3.Lerp(jointObject.Start, v1, movement); var v2Lerp = Vector3.Lerp(jointObject.End, v2, movement); drawLine(jointObject.GameObject, v1Lerp, v2Lerp, movement); jointObject.Start = v1; jointObject.End = v2; jointMap.Add(key, jointObject); } } catch (Exception ex) { Debug.LogWarning(ex.ToString()); } } foreach (var joint in Skeleton.Joints) { try{ GameObject jointPoint = null; partMap.TryGetValue(joint.Key, out jointPoint); var lerp = true; if (jointPoint == null) { lerp = false; if (joint.Key == Skeleton.L_HAND || joint.Key == Skeleton.R_HAND || joint.Key == Skeleton.L_FOOT || joint.Key == Skeleton.R_FOOT) { jointPoint = Instantiate(HandPrefab) as GameObject; } else if (joint.Key != Skeleton.L_WRIST && joint.Key != Skeleton.R_WRIST) { jointPoint = Instantiate(JointPrefab) as GameObject; } jointPoint.name = joint.Key; partMap.Add(joint.Key, jointPoint); jointPoint.transform.SetParent(this.transform, false); } if (lerp) { var jointMove = Vector3.Lerp(jointPoint.transform.localPosition, processJoint(joint.Value), movement * 2.5f); jointPoint.transform.localPosition = jointMove; } else { jointPoint.transform.localPosition = processJoint(joint.Value); } } catch (Exception ex) { } } }
/// <summary> /// Gets the joint of given joint type and joint side. /// </summary> /// <param name="jointType">The type of the joint </param> /// <param name="jointSide">The side on wich the joint should be located</param> /// <param name="transforms">The bones to search among</param> /// <returns>Null if no match, otherwise the first hit</returns> public static Transform[] GetTypeAndSide(JointObject jointType, BodySide jointSide, Transform[] transforms) { return GetJointsOfSide(jointSide, GetBonesOfType(jointType, transforms)); }
/// <summary> /// Returns only the bones with the specified JointObject. /// </summary> public static Transform[] GetBonesOfType(JointObject type, Transform[] bones) { return bones.Where(b => (b != null && GetType(b.name) == type)).ToArray(); }
/// <summary> /// Returns a tranform from a given JointType /// </summary> /// <param name="transforms">The transform to be searched</param> /// <param name="jointType">The type of the joint to be returned</param> /// <param name="jointSide">The side of which the joint is located</param> /// <param name="namings">The Names of the joints</param> /// <returns>The transform of the first result</returns> public static Transform GetBone(Transform[] transforms, JointObject jointType, BodySide jointSide = BodySide.Center, params string[][] namings) { return GetMatch(GetTypeAndSide(jointType, jointSide, transforms), namings); }
/// <summary> /// Returns only the bones with the specified JointObject. /// </summary> public static Transform[] GetBonesOfType(JointObject type, Transform[] bones) { return(bones.Where(b => (b != null && GetType(b.name) == type)).ToArray()); }
/// <summary> /// Returns a tranform from a given JointType /// </summary> /// <param name="transforms">The transform to be searched</param> /// <param name="jointType">The type of the joint to be returned</param> /// <param name="jointSide">The side of which the joint is located</param> /// <param name="namings">The Names of the joints</param> /// <returns>The transform of the first result</returns> public static Transform GetBone(Transform[] transforms, JointObject jointType, BodySide jointSide = BodySide.Center, params string[][] namings) { return(GetMatch(GetTypeAndSide(jointType, jointSide, transforms), namings)); }
/// <summary> /// Gets the joint of given joint type and joint side. /// </summary> /// <param name="jointType">The type of the joint </param> /// <param name="jointSide">The side on wich the joint should be located</param> /// <param name="transforms">The bones to search among</param> /// <returns>Null if no match, otherwise the first hit</returns> public static Transform[] GetTypeAndSide(JointObject jointType, BodySide jointSide, Transform[] transforms) { return(GetJointsOfSide(jointSide, GetBonesOfType(jointType, transforms))); }