void UpdatePosition(ZigJointId joint, Vector3 position) { joint = mirror ? mirrorJoint(joint) : joint; // make sure something is hooked up to this joint if (!transforms[(int)joint]) { return; } if (UpdateJointPositions) { Vector3 dest = Vector3.Scale(position, doMirror(Scale)) - rootPosition; transforms[(int)joint].localPosition = Vector3.Lerp(transforms[(int)joint].localPosition, dest, Time.deltaTime * Damping); } SceneOneMove.LeftHandP = LeftWrist.position.x; SceneOneMove.LeftArmP = LeftShoulder.position.x; SceneOneMove.RightHandP = RightWrist.position.x; SceneOneMove.RightArmP = RightShoulder.position.x; SceneOneMove.HeadPY = Head.position.y; SceneOneMove.RightHandPY = RightWrist.position.y; SceneOneMove.LeftHandPY = LeftWrist.position.y; // print (LeftWrist.position.x.ToString ()); // print (LeftShoulder.position.x.ToString ()); }
protected void OnHandRaise(ZigJointId joint) { if (null != HandRaise) { HandRaise.Invoke(this, new HandRaiseEventArgs(joint)); } SendMessage("HandRaiseDetector_HandRaise", joint, SendMessageOptions.DontRequireReceiver); }
private void DrawBones(ZigInputJoint[] userSkeleton) { for (int t = 0; t < userSkeleton.Length; t++) { ZigJointId parentId = CinemaMocapHelper.ParentBoneJoint(userSkeleton[t].Id); ZigInputJoint parentJoint = null; for (int s = 0; s < userSkeleton.Length; s++) { if (userSkeleton[s].Id == parentId)// find parent and leave loop. { parentJoint = userSkeleton[s]; break; } } if (parentJoint != null && parentJoint.Id != ZigJointId.None && userSkeleton[t].GoodPosition && parentJoint.GoodPosition) { // parent and child joint coordinates int childX = textureSize.Width / 2 - (int)(userSkeleton[t].Position.x * 300 / userSkeleton[t].Position.z); int childY = textureSize.Height / 2 - (int)(userSkeleton[t].Position.y * 300 / userSkeleton[t].Position.z); int parentX = textureSize.Width / 2 - (int)(parentJoint.Position.x * 300 / parentJoint.Position.z); int parentY = textureSize.Height / 2 - (int)(parentJoint.Position.y * 300 / parentJoint.Position.z); // draw lines between joints Color color = (!userSkeleton[t].Inferred) ? Color.cyan : Color.red; CinemaMocapHelper.drawFastLine(outputPixels, textureSize.Width, textureSize.Height, childX, childY, parentX, parentY, color); } } }
ZigJointId mirrorJoint(ZigJointId joint) { switch (joint) { case ZigJointId.LeftCollar: return ZigJointId.RightCollar; case ZigJointId.LeftShoulder: return ZigJointId.RightShoulder; case ZigJointId.LeftElbow: return ZigJointId.RightElbow; case ZigJointId.LeftWrist: return ZigJointId.RightWrist; case ZigJointId.LeftHand: return ZigJointId.RightHand; case ZigJointId.LeftFingertip: return ZigJointId.RightFingertip; case ZigJointId.LeftHip: return ZigJointId.RightHip; case ZigJointId.LeftKnee: return ZigJointId.RightKnee; case ZigJointId.LeftAnkle: return ZigJointId.RightAnkle; case ZigJointId.LeftFoot: return ZigJointId.RightFoot; case ZigJointId.RightCollar: return ZigJointId.LeftCollar; case ZigJointId.RightShoulder: return ZigJointId.LeftShoulder; case ZigJointId.RightElbow: return ZigJointId.LeftElbow; case ZigJointId.RightWrist: return ZigJointId.LeftWrist; case ZigJointId.RightHand: return ZigJointId.LeftHand; case ZigJointId.RightFingertip: return ZigJointId.LeftFingertip; case ZigJointId.RightHip: return ZigJointId.LeftHip; case ZigJointId.RightKnee: return ZigJointId.LeftKnee; case ZigJointId.RightAnkle: return ZigJointId.LeftAnkle; case ZigJointId.RightFoot: return ZigJointId.LeftFoot; default: return joint; } }
void UpdatePosition(ZigJointId joint, Vector3 position) { joint = mirror ? mirrorJoint(joint) : joint; // make sure something is hooked up to this joint if (!transforms[(int)joint]) { return; } if (UpdateJointPositions) { Vector3 dest = Vector3.Scale(position, doMirror(Scale)) - rootPosition; transforms[(int)joint].localPosition = Vector3.Lerp(transforms[(int)joint].localPosition, dest, Time.deltaTime * Damping); } }
void UpdateRotation(ZigJointId joint, Quaternion orientation) { joint = mirror ? mirrorJoint(joint) : joint; // make sure something is hooked up to this joint if (!transforms[(int)joint]) { return; } if (UpdateOrientation) { Quaternion newRotation = transform.rotation * orientation * initialRotations[(int)joint]; if (mirror) { newRotation.y = -newRotation.y; newRotation.z = -newRotation.z; } transforms[(int)joint].rotation = Quaternion.Slerp(transforms[(int)joint].rotation, newRotation, Time.deltaTime * RotationDamping); } }
void CheckSessionStart(Vector3 point, ZigJointId joint) { if (InSession) { Debug.Log("CheckSessionStart when already in session, leaving"); return; } Vector3 boundsCenter = (RotateToUser) ? RotateHandPoint(trackedUser.Position) : trackedUser.Position; boundsCenter += SessionBoundsOffset; currentSessionBounds = new Bounds(boundsCenter, SessionBounds); Vector3 fp = (RotateToUser) ? RotateHandPoint(point) : point; if (currentSessionBounds.Contains(fp)) { focusPoint = fp; jointInSession = joint; InSession = true; OnSessionStart(fp); } }
ZigJointId mirrorJoint(ZigJointId joint) { switch (joint) { case ZigJointId.LeftCollar: return(ZigJointId.RightCollar); case ZigJointId.LeftShoulder: return(ZigJointId.RightShoulder); case ZigJointId.LeftElbow: return(ZigJointId.RightElbow); case ZigJointId.LeftWrist: return(ZigJointId.RightWrist); case ZigJointId.LeftHand: return(ZigJointId.RightHand); case ZigJointId.LeftFingertip: return(ZigJointId.RightFingertip); case ZigJointId.LeftHip: return(ZigJointId.RightHip); case ZigJointId.LeftKnee: return(ZigJointId.RightKnee); case ZigJointId.LeftAnkle: return(ZigJointId.RightAnkle); case ZigJointId.LeftFoot: return(ZigJointId.RightFoot); case ZigJointId.RightCollar: return(ZigJointId.LeftCollar); case ZigJointId.RightShoulder: return(ZigJointId.LeftShoulder); case ZigJointId.RightElbow: return(ZigJointId.LeftElbow); case ZigJointId.RightWrist: return(ZigJointId.LeftWrist); case ZigJointId.RightHand: return(ZigJointId.LeftHand); case ZigJointId.RightFingertip: return(ZigJointId.LeftFingertip); case ZigJointId.RightHip: return(ZigJointId.LeftHip); case ZigJointId.RightKnee: return(ZigJointId.LeftKnee); case ZigJointId.RightAnkle: return(ZigJointId.LeftAnkle); case ZigJointId.RightFoot: return(ZigJointId.LeftFoot); default: return(joint); } }
public HandRaiseEventArgs(ZigJointId joint) { Joint = joint; }
// Use this for initialization void Start() { // Instantiate objects // Load ZigFu game object. This game object has 4 Zig related script Components. Use this object // to instances of these script's classes in order to access event information :) zigfu = GameObject.Find ("ZigFu"); sampler = new JointSampler (); zig_control = zigfu.GetComponent <Zig>(); // This script is attached to Carl so GetComponent can be called directly skeleton = GetComponent <ZigSkeleton>(); l_shoulder_angles = new Vector3(); r_shoulder_angles = new Vector3(); db_control = new dbAccess (); user_id = PlayerPrefs.GetInt ("ActiveUser", 1); // DEBUG: Access some application run-time data. Compare this output to where the scene was loaded from //Debug.Log ("isEditor: " + Application.isEditor + "\nisLoadinglevel: " + Application.isLoadingLevel + "\nLoadedLevelName: " + Application.loadedLevelName + // "\nplatform: " + Application.platform + "\nGenuine: " + Application.genuine + "\ngenuineCheckAvailable: " + Application.genuineCheckAvailable + // "\nbackgroundLoadingPriority: " + Application.backgroundLoadingPriority); // Calculate max and min y-axis rotations to allow abduction measurements max_y_rotation = degrees_freedom; min_y_rotation = -degrees_freedom; // Get zig joint identification numbers for each shoulder R_shoulder_id = ZigJointId.RightShoulder; L_shoulder_id = ZigJointId.LeftShoulder; currentExercise = 0; exercise = "Press Next To Start"; style = new GUIStyle(); instructions = " "; time_hold = 0; inPosition = true; }
/* Given a ZigJointId return a Vector3 of the corresponding joint world position */ public Vector3 GetJointWorldPosition(ZigJointId id) { return transforms[(int)id].position; }
/* Given a ZigJointId return a Vector3 of the corresponding local euler angles */ public Vector3 GetJointLocalEulerAngles(ZigJointId id) { return transforms[(int) id].localEulerAngles; }
void UpdateRotation(ZigJointId joint, Quaternion orientation) { joint = mirror ? mirrorJoint(joint) : joint; // make sure something is hooked up to this joint if (!transforms[(int)joint]) { return; } if (UpdateOrientation) { if(count>102) { if((int)joint==(int)ZigJointId.RightElbow || (int)joint==(int)ZigJointId.LeftElbow) orientation= DoubleExSmooth(joint,orientation,alphaElbow,betaElbow); else if((int)joint==(int)ZigJointId.LeftHip || (int)joint==(int)ZigJointId.RightHip) orientation= DoubleExSmooth(joint,orientation,alphaHip,betaHip); else if((int)joint==(int)ZigJointId.RightKnee || (int)joint==(int)ZigJointId.LeftKnee) orientation= DoubleExSmooth(joint,orientation,alphaKnee,betaKnee); else if((int)joint==(int)ZigJointId.RightAnkle || (int)joint==(int)ZigJointId.LeftAnkle) orientation= DoubleExSmooth(joint,orientation,alphaAnkle,betaAnkle); else if((int)joint==(int)ZigJointId.RightFoot || (int)joint==(int)ZigJointId.LeftFoot) orientation= DoubleExSmooth(joint,orientation,alphaFoot,betaFoot); else if((int)joint==(int)ZigJointId.RightShoulder || (int)joint==(int)ZigJointId.LeftShoulder) orientation= DoubleExSmooth(joint,orientation,alphaShoulder,betaShoulder); else if((int)joint==(int)ZigJointId.RightWrist || (int)joint==(int)ZigJointId.LeftWrist) orientation= DoubleExSmooth(joint,orientation,alphaWrist,betaWrist); else if((int)joint==(int)ZigJointId.RightHand || (int)joint==(int)ZigJointId.LeftHand) orientation= DoubleExSmooth(joint,orientation,alphaHand,betaHand); else if((int)joint==(int)ZigJointId.Torso ) orientation= DoubleExSmooth(joint,orientation,alphaSpine,betaSpine); else if((int)joint==(int)ZigJointId.Neck ) orientation= DoubleExSmooth(joint,orientation,alphaNeck,betaNeck); else if((int)joint==(int)ZigJointId.Head ) orientation= DoubleExSmooth(joint,orientation,alphaHead,betaHead); } Quaternion newRotation = transform.rotation * orientation * initialRotations[(int)joint]; if (mirror) { newRotation.y = -newRotation.y; newRotation.z = -newRotation.z; } // CALLING THE SMOOTHNING FUNCTION transforms[(int)joint].rotation = Quaternion.Slerp(transforms[(int)joint].rotation, newRotation, Time.deltaTime * RotationDamping); //Debug.Log("rotaion updated " + transforms[(int)joint].rotation.ToString("F4"));// , transforms[(int)joint].rotation.y,transforms[(int)joint].rotation.z ); Debug.Log ("Outputing"); Debug.Log ("joingID: " + joint.ToString()); if((int)joint ==TrackedRightElbow) { Debug.Log ("Outputing"); System.IO.File.AppendAllText("C:/Users/prp/Desktop/TrackedRightElbow.txt",transforms[(int)joint].rotation.ToString("F4")+"\n"); //System.IO.File.AppendAllText("C:/Users/prp/Desktop/a.txt","\n"); } if((int)joint ==TrackedLeftHip) { Debug.Log ("Outputing"); System.IO.File.AppendAllText("C:/Users/prp/Desktop/TrackedLeftFoot.txt",transforms[(int)joint].rotation.ToString("F4")+"\n"); //System.IO.File.AppendAllText("C:/Users/prp/Desktop/a.txt","\n"); } } }
public static ZigJointId ParentBoneJoint(ZigJointId joint) { return(ZigJointParents[(int)joint]); }
/// <summary> /// Maps a given ZigJointId to it's NUIJointType counterpart /// </summary> /// <param name="zigJointId">A ZigJointId</param> /// <returns>The corresponding NUIJointType</returns> public static NUIJointType ZigToNUIJointMapping(ZigJointId zigJointId) { switch (zigJointId) { case ZigJointId.Waist: return(NUIJointType.SpineBase); case ZigJointId.Torso: return(NUIJointType.SpineMid); case ZigJointId.Neck: return(NUIJointType.Neck); case ZigJointId.Head: return(NUIJointType.Head); case ZigJointId.RightHip: return(NUIJointType.HipRight); case ZigJointId.RightKnee: return(NUIJointType.KneeRight); case ZigJointId.RightAnkle: return(NUIJointType.AnkleRight); case ZigJointId.RightFoot: return(NUIJointType.FootRight); case ZigJointId.LeftHip: return(NUIJointType.HipLeft); case ZigJointId.LeftKnee: return(NUIJointType.KneeLeft); case ZigJointId.LeftAnkle: return(NUIJointType.AnkleLeft); case ZigJointId.LeftFoot: return(NUIJointType.FootLeft); case ZigJointId.RightShoulder: return(NUIJointType.ShoulderRight); case ZigJointId.RightElbow: return(NUIJointType.ElbowRight); case ZigJointId.RightWrist: return(NUIJointType.WristRight); case ZigJointId.RightHand: return(NUIJointType.HandRight); case ZigJointId.LeftShoulder: return(NUIJointType.ShoulderLeft); case ZigJointId.LeftElbow: return(NUIJointType.ElbowLeft); case ZigJointId.LeftWrist: return(NUIJointType.WristLeft); case ZigJointId.LeftHand: return(NUIJointType.HandLeft); default: return(NUIJointType.Unspecified); } }
public Transform getTransform(ZigJointId joint, bool mirror) { if(mirror) joint = mirrorJoint(joint); return transforms[(int)joint]; }
Quaternion DoubleExSmooth(ZigJointId joint,Quaternion CurrentRotation,float alpha,float beta) { //Quaternion ForeCastedRotation ; if (count==103){ //fOR THE SMOOTH ROTATION PART currentSmoothedValue[(int)joint].x = alpha*CurrentRotation.x+(1-alpha)*(previousSmoothedValue[(int)joint].x+previousTrendValue[(int)joint].x); currentSmoothedValue[(int)joint].y = alpha*CurrentRotation.y+(1-alpha)*(previousSmoothedValue[(int)joint].y+previousTrendValue[(int)joint].y); currentSmoothedValue[(int)joint].z = alpha*CurrentRotation.z+(1-alpha)*(previousSmoothedValue[(int)joint].z+previousTrendValue[(int)joint].z); //FOR TREND ROTATION PART currentTrendValue[(int)joint].x = beta*(currentSmoothedValue[(int)joint].x-previousSmoothedValue[(int)joint].x)+(1-beta)*previousTrendValue[(int)joint].x; currentTrendValue[(int)joint].y = beta*(currentSmoothedValue[(int)joint].y-previousSmoothedValue[(int)joint].y)+(1-beta)*previousTrendValue[(int)joint].y; currentTrendValue[(int)joint].z = beta*(currentSmoothedValue[(int)joint].z-previousSmoothedValue[(int)joint].z)+(1-beta)*previousTrendValue[(int)joint].z; // Next ForeCasted rotation ForeCastedRotation.x =currentSmoothedValue[(int)joint].x+currentTrendValue[(int)joint].x; ForeCastedRotation.y =currentSmoothedValue[(int)joint].y+currentTrendValue[(int)joint].y; ForeCastedRotation.z =currentSmoothedValue[(int)joint].z+currentTrendValue[(int)joint].z; //ForeCastedRotation.x =currentSmoothedValue[(int)joint].x; //ForeCastedRotation.y =currentSmoothedValue[(int)joint].y; //ForeCastedRotation.z =currentSmoothedValue[(int)joint].z; previousSmoothedValue[(int)joint]=currentSmoothedValue[(int)joint]; previousTrendValue[(int)joint]=currentTrendValue[(int)joint]; return (ForeCastedRotation); } }