private void RotateAvatarJoints(Kinect.Body body, GameObject bodyObject)
 {
     RotateBone (bodyObject, Kinect.JointType.ShoulderRight, Kinect.JointType.ElbowRight);
     RotateBone (bodyObject, Kinect.JointType.ShoulderLeft, Kinect.JointType.ElbowLeft);
     RotateBone (bodyObject, Kinect.JointType.ElbowRight, Kinect.JointType.WristRight);
     RotateBone (bodyObject, Kinect.JointType.ElbowLeft, Kinect.JointType.WristLeft);
 }
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        filter.UpdateFilter (ref body);
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.HandRight; jt++) {
            //Kinect.Joint sourceJoint = body.Joints [jt];
            GameObject avatarSpineBase = GameObject.FindGameObjectsWithTag (Kinect.JointType.SpineBase.ToString ()) [0];
            Transform jointObj = bodyObject.transform.FindChild (jt.ToString ());
            Kinect.CameraSpacePoint jointPosition = filter.FilteredJoints [jt].Position;
            jointPosition.Z = -jointPosition.Z;

            //jointDataRecorder.Append (string.Format ("{0},{1},{2},{3}", System.DateTime.Now, jointPosition.X, jointPosition.Y, jointPosition.Z));

            if (jt == Kinect.JointType.SpineBase) {
                transformDistance = new Vector3 (jointPosition.X - avatarSpineBase.transform.position.x,
                                                 jointPosition.Y - avatarSpineBase.transform.position.y,
                                                 jointPosition.Z - avatarSpineBase.transform.position.z);

            }

            jointObj.position = new Vector3 ((jointPosition.X - transformDistance.x),
                                             (jointPosition.Y - transformDistance.y),
                                             (jointPosition.Z - transformDistance.z));
            if (jt <= Kinect.JointType.ShoulderLeft || jt == Kinect.JointType.ShoulderRight) {
                GameObject avatarJoint = GameObject.FindGameObjectsWithTag (jt.ToString ()) [0];
                avatarJoint.transform.position = jointObj.transform.position;
            }

        }
        //jointDataRecorder.Append ("\n");
    }
Exemplo n.º 3
0
 private static Vector3 GetVector3FromJoint(Kinect.Joint joint)
 {
     int scaleFactor = 1000;
     int zScaleFactor = -scaleFactor;
     int zShiftFactor = 1100;
     return new Vector3(joint.Position.X * scaleFactor,
                        joint.Position.Y * scaleFactor,
                        joint.Position.Z * zScaleFactor + zShiftFactor);
 }
Exemplo n.º 4
0
 private void RefreshBodyObject(Kinect.Body body)
 {
     for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) {
         Kinect.Joint sourceJoint = body.Joints[jt];
         Transform jointObj = bodyView.transform.FindChild(jt.ToString());
         if (jointObj == null) continue;
         jointObj.localPosition = GetVector3FromJoint(sourceJoint);
     }
 }
    private void RotateBone(GameObject bodyObject, Kinect.JointType startBone, Kinect.JointType endBone)
    {
        GameObject avatarJoint = GameObject.FindGameObjectsWithTag (startBone.ToString ()) [0];
        Transform jointObj = bodyObject.transform.FindChild (startBone.ToString ());
        Transform targetJointObj = bodyObject.transform.FindChild (endBone.ToString ());

        Quaternion avatarRotaion = Quaternion.LookRotation ((targetJointObj.transform.position - jointObj.transform.position).normalized);
        avatarJoint.transform.rotation = Quaternion.Slerp (avatarJoint.transform.rotation, avatarRotaion, Time.deltaTime * 2000);
        avatarJoint.transform.Rotate (new Vector3 (90, 0, 0));
    }
    private bool IsInRange(WindowsKinect.Body skeleton)
    {
        const float ftToMeter = 0.3048f;
        const float minDistance = 4.5f * ftToMeter;
        const float maxDistance = 6.5f * ftToMeter;

        Vector3 spineBasePosition = skeleton.GetPosition(WindowsKinect.JointType.SpineBase);
        return spineBasePosition.z >= minDistance &&
            spineBasePosition.z <= maxDistance &&
            Mathf.Abs(spineBasePosition.x) < 1.5f;
    }
Exemplo n.º 7
0
    public Vector3 createJoint(MySkeleton skel, int firstJoint, int secondJoint, Kinect.JointType jointToMove, int index)
    {
        float Xtrans = translateX(skel, firstJoint, secondJoint, index);
        float Ytrans = translateY(skel, firstJoint, secondJoint, index);
        float Ztrans = translateZ(skel, firstJoint, secondJoint, index);
        //		Debug.Log ("x transition: " + Xtrans+" ytansitiion: "+ Ytrans+" z transition: "+Ztrans);

        Vector3 Position = new Vector3 ((float)(skel.Position[(int)jointToMove].x - Xtrans), (float)(skel.Position[(int)jointToMove].y - Ytrans),
                                        (float)(skel.Position[(int)jointToMove].z - Ztrans));
        return Position;
    }
Exemplo n.º 8
0
    private static Color GetColorForState(Kinect.TrackingState state)
    {
        switch (state) {
        case Kinect.TrackingState.Tracked:
            return Color.green;

        case Kinect.TrackingState.Inferred:
            return Color.red;

        default:
            return Color.black;
        }
    }
    private static Color GetColorForState(Kinect.TrackingState state)
    {
        //switch (state)
        //{
        //case Kinect.TrackingState.Tracked:
        //    return Color.green;

        //case Kinect.TrackingState.Inferred:
            return Color.red;

        //default:
        //    return Color.black;
        //}
    }
Exemplo n.º 10
0
 private GameObject addBone(string name, float radius, GameObject prefab, Transform body, Kinect.JointType joint1, Kinect.JointType? joint2 = null)
 {
     GameObject bone = (GameObject) Instantiate(prefab, Vector3.zero, Quaternion.identity);
     bone.name = name; bone.transform.parent = body;
     BoneScript script = bone.GetComponent("BoneScript") as BoneScript;
     script.radius = radius;
     script.joint1 = body.FindChild (joint1.ToString ()).gameObject;
     if (joint2 != null)
         script.joint2 = body.FindChild (((Kinect.JointType) joint2).ToString ()).gameObject;
     else if (_BoneMap.ContainsKey (joint1))
         script.joint2 = body.FindChild (_BoneMap [joint1].ToString ()).gameObject;
     else
         Debug.LogError ("BAD JOINT: " + joint1);
     return bone;
 }
Exemplo n.º 11
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        // kinect is active
        kinectActive = true;

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint? targetJoint = null;

            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints[_BoneMap[jt]];
            }

            Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);
        }
    }
Exemplo n.º 12
0
 public static Vector3 GetVector3FromJoint(Kinect.Joint joint)
 {
     // variations added by GesTherapy to contract/lift skeleton on unity screen
     if (Application.loadedLevelName == "Calibration" || Application.loadedLevelName == "Visualizer")
     {
         return new Vector3(joint.Position.X * 5.5f, (joint.Position.Y * 5.5f) + 1.5f, joint.Position.Z * 5.5f);
     }
     else
     {
         // if upper half of body
         if ( (joint.JointType >= Kinect.JointType.SpineMid && joint.JointType <= Kinect.JointType.HandRight)
             || (joint.JointType >= Kinect.JointType.SpineShoulder && joint.JointType <= Kinect.JointType.ThumbRight) )
             return new Vector3(joint.Position.X * 5.5f, (joint.Position.Y * 5.5f) + 1.5f + Calibration.upperShift, joint.Position.Z * 5.5f);
         // else if lower half of body
         else if ( (joint.JointType >= Kinect.JointType.KneeLeft && joint.JointType <= Kinect.JointType.FootLeft)
                  || (joint.JointType >= Kinect.JointType.KneeRight && joint.JointType <= Kinect.JointType.FootRight) )
             return new Vector3(joint.Position.X * 5.5f, (joint.Position.Y * 5.5f) + 1.5f + Calibration.lowerShift, joint.Position.Z * 5.5f);
         // else hips or spine base
         else
             return new Vector3(joint.Position.X * 5.5f, (joint.Position.Y * 5.5f) + 1.5f, joint.Position.Z * 5.5f);
     }
 }
Exemplo n.º 13
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint? targetJoint = null;

            if (_BoneMap.ContainsKey(jt)) {
                targetJoint = body.Joints[_BoneMap[jt]];
            }

            Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);

            LineRenderer lr = jointObj.GetComponent<LineRenderer>();
            if (targetJoint.HasValue) {
                lr.SetPosition(0, jointObj.localPosition);
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            } else {
                lr.enabled = false;
            }
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// Finds the closest body from the sensor if any
    /// </summary>
    /// <param name="bodyFrame">A body frame</param>
    /// <returns>Closest body, null of none</returns>
    private static Kinect.Body FindClosestBody(Kinect.Body[] bodies)
    {
        Kinect.Body result = null;
        double closestBodyDistance = double.MaxValue;

        foreach (var body in bodies)
        {
            if (body.IsTracked)
            {
                var currentLocation = body.Joints[Kinect.JointType.SpineBase].Position;

                var currentDistance = VectorLength(currentLocation);

                if (result == null || currentDistance < closestBodyDistance)
                {
                    result = body;
                    closestBodyDistance = currentDistance;
                }
            }
        }

        return result;
    }
Exemplo n.º 15
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint? targetJoint = null;

            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints[_BoneMap[jt]];
            }

            Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);

            // reference left hand position
            if (jt == joint)
            {
                hand = jointObj.position;
                handState = body.HandLeftState;
            }
        }
    }
Exemplo n.º 16
0
 void GetRemoveBackground(KinectOneLabelMap labelmap, KinectOneImage image, Kinect.ColorSpacePoint[] colorSpaces)
 {
     byte[] data = labelmap.GetData();
     Color32[] _image = image.GetColorTexture().GetPixels32();
     int imageWidth = image.Sensor.ColorFrameSource.FrameDescription.Width;
     for (int i = 0; i < outputPixels.Length; i++)
     {
         byte indexValue = data[i];
         if (IsValidFloatValue(colorSpaces[i].X) || IsValidFloatValue(colorSpaces[i].Y) || indexValue == 255)
         {
             outputPixels[i] = new Color32(0, 0, 0, 0);
         }
         else
         {
             float x=colorSpaces[i].X, y=colorSpaces[i].Y;
             int colorIndex = (int)y * imageWidth + (int)x;
             outputPixels[i] = (indexValue > 0) ? ((indexValue <= labelToColor.Length) ? labelToColor[indexValue - 1] : defaultColor) : bgColor;
             if (indexValue == m_engageuser.engagedTrackedUser.Id && colorIndex < _image.Length && colorIndex > 0)
             {
                 outputPixels[i] = _image[colorIndex];
             }
         }
     }
 }
Exemplo n.º 17
0
	// TODO: Add method that return joints by ID, assign proper jointID in the first line: ... = new JointData(Joint.None);
	public JointData GetKinect2JointData(Kinect.Joint jointPosition, Kinect.JointOrientation jointRotation) 
	{
		JointData jointData = new JointData(Joint.None); // Temporary variable used to pass values, jointID can be none
		jointData.rotation = new Quaternion(jointRotation.Orientation.X,jointRotation.Orientation.Y,jointRotation.Orientation.Z,jointRotation.Orientation.W);
		jointData.position = new Vector3(jointPosition.Position.X, jointPosition.Position.Y, jointPosition.Position.Z);

		if(jointPosition.TrackingState == Kinect.TrackingState.Tracked)  {
			jointData.positionConfidence = 1.0f;
			jointData.rotationConfidence = 1.0f;
		}
		else if(jointPosition.TrackingState == Kinect.TrackingState.Inferred)  {
			jointData.positionConfidence = 0.5f;
			jointData.rotationConfidence = 0.5f;
		}
		else if(jointPosition.TrackingState == Kinect.TrackingState.NotTracked)  {
			jointData.positionConfidence = 0.0f;
			jointData.rotationConfidence = 0.0f;
		}
		else {
			jointData.positionConfidence = 0.0f;
			jointData.rotationConfidence = 0.0f;
		}
		jointData.TrackingState = jointPosition.TrackingState;

		return jointData;
	}
Exemplo n.º 18
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        string[] save = new string[25];
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);
            if (jt == Kinect.JointType.Head)
            {
                Camera.main.transform.localRotation = Quaternion.identity;
                Camera.main.transform.Rotate(new Vector3(0, 180, 0));
                Camera.main.transform.position = (Vector3)jointObj.transform.position;
            }

            float xval = (int) ((jointObj.position.x)* 10000)/10000f;
            float yval = (int) ((jointObj.position.y) * 10000)/10000f;
            float zval = (int) ((jointObj.position.z) * 10000)/10000f;
            save[(int) jt] += xval.ToString() + " " + yval.ToString() + " " + zval.ToString() + " ";
        }
        message = save [3] + save [20] + save [8] + save [4]  + save [9] + save [5] +
            save [0] + save [10] + save [6] + save [16] + save [12] + save [17] + save [13] +
                save [18] + save [14] + body.HandLeftState.ToString () + " " + body.HandRightState.ToString ();
    }
Exemplo n.º 19
0
    public Skeleton(Kinect.Body body)
    {
        _start();
        Message = ""
            + BodyPropertiesTypes.UID.ToString() + MessageSeparators.SET + body.TrackingId
            + MessageSeparators.L2 + BodyPropertiesTypes.Confidence.ToString() + MessageSeparators.SET + BodyConfidence(body)
            + MessageSeparators.L2 + BodyPropertiesTypes.HandLeftState.ToString() + MessageSeparators.SET + body.HandLeftState
            + MessageSeparators.L2 + BodyPropertiesTypes.HandLeftConfidence.ToString() + MessageSeparators.SET + body.HandLeftConfidence
            + MessageSeparators.L2 + BodyPropertiesTypes.HandRightState.ToString() + MessageSeparators.SET + body.HandRightState
            + MessageSeparators.L2 + BodyPropertiesTypes.HandRightConfidence.ToString() + MessageSeparators.SET + body.HandRightConfidence;

        foreach (Kinect.JointType j in Enum.GetValues(typeof(Kinect.JointType)))
        {
            Message += "" + MessageSeparators.L2 + j.ToString() + MessageSeparators.SET + CommonUtils.convertVectorToStringRPC(body.Joints[j].Position);
        }
    }
Exemplo n.º 20
0
 private void updatePalm(Transform jointTransform, Transform thumbTransform, Kinect.HandState handState)
 {
     jointTransform.LookAt(thumbTransform);
     GameObject jointObj = jointTransform.gameObject;
     HandPalmAttribute hpa = jointObj.GetComponent<HandPalmAttribute>();
     hpa.UpdateState(handState);
     jointObj.GetComponent<Renderer>().material.color = hpa.GetStateColor();
 }
Exemplo n.º 21
0
 //更新所有骨架物件的位置與關節之間的連線。
 private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
 {
     //以迴圈的方式將所有的骨骼一個一個的去計算。
     for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
     {
         //抓取到來源關節,以及重置目標關節為空物件。
         Kinect.Joint sourceJoint = body.Joints[jt];
         Kinect.Joint? targetJoint = null;
         //運用Key和Velue的關係讀取目標關節。
         if(_BoneMap.ContainsKey(jt))
         {
             targetJoint = body.Joints[_BoneMap[jt]];
         }
         //讀取出骨頭線段的出發點,也就是目前關節的位置。
         Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
         jointObj.localPosition = GetVector3FromJoint(sourceJoint);
         //讀取關節的LineRenderer,如果有目標關節的話,賦予其座標0和座標1的位置,同時設定骨頭線段的顏色。
         LineRenderer lr = jointObj.GetComponent<LineRenderer>();
         if(targetJoint.HasValue)
         {
             lr.SetPosition(0, jointObj.localPosition);
             lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
             lr.SetColors(GetColorForState (sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
         }
         //如果沒有目標關節的話,代表此為末端關節,不需要LineRenderer,將其關閉。
         else
         {
             lr.enabled = false;
         }
     }
 }
Exemplo n.º 22
0
 private static Vector3 GetVector3FromJoint(Kinect.Joint joint)
 {
     return new Vector3(joint.Position.X * 10, joint.Position.Y * 10, joint.Position.Z * 10);
 }
Exemplo n.º 23
0
    private double calculateHeight(MySkeleton skeleton,
	                               Kinect.JointType jointType1, Kinect.JointType jointType2)
    {
        double length = Math.Round(Math.Sqrt(
            (Math.Pow(skeleton.Position[(int)jointType1].x - skeleton.Position[(int)jointType2].x, 2)) +
            (Math.Pow(skeleton.Position[(int)jointType1].y - skeleton.Position[(int)jointType2].y, 2)) +
            (Math.Pow(skeleton.Position[(int)jointType1].z - skeleton.Position[(int)jointType2].z, 2))), 3);
        return length;
    }
	void RotateJoint(Kinect2.Body body, int bone) {
		//if blendWeight is 0 there is no need to compute the rotations
		if( blendWeight <= 0 ){ return; }
		Vector3 upDir = new Vector3();
		Vector3 rightDir = new Vector3();
		
		if(bone == (int)Kinect2.JointType.SpineMid)
		{
			upDir = ((HipLeft.transform.position + HipRight.transform.position) / 2.0f) - HipOverride.transform.position;
			rightDir = HipRight.transform.position - HipLeft.transform.position;
		}

		//if the model is not animated, reset rotations to fix twisted joints
		if(!animated){_bones[bone].transform.localRotation = _baseRotation[bone];}
		//if the required bone data from the kinect isn't available, return
		Kinect2.Joint? boneJoint = body.Joints[(Kinect2.JointType)bone];
		if( !boneJoint.HasValue )
		{
			return;
		}
		//get the target direction of the bone in world space
		//for the majority of bone it's bone - 1 to bone, but Hip_Override and the outside
		//shoulders are determined differently.
		
		Vector3 dir = _boneDir[bone];
		Vector3 target;
		
		//if bone % 4 == 0 then it is either an outside shoulder or the hip override
		if(bone % 4 == 0)
		{
			//hip override is at Hip_Left
			if(bone == (int)Kinect2.JointType.HipLeft)
			{
				//target = vector from hip_center to average of hips left and right
				target = ((GetVector3FromJoint(body.Joints[Kinect2.JointType.HipLeft]) + GetVector3FromJoint(body.Joints[Kinect2.JointType.HipRight])) / 2.0f) - GetVector3FromJoint(body.Joints[Kinect2.JointType.SpineMid]);
			}
			//otherwise it is one of the shoulders
			else
			{
				//target = vector from shoulder_center to bone
				target = GetVector3FromJoint(body.Joints[(Kinect2.JointType)bone]) - GetVector3FromJoint(body.Joints[Kinect2.JointType.SpineShoulder]);
			}
		}
		else
		{
			//target = vector from previous bone to bone
			target = GetVector3FromJoint(body.Joints[(Kinect2.JointType)bone]) - GetVector3FromJoint(body.Joints[(Kinect2.JointType)bone-1]);
		}
		//transform it into bone-local space (independant of the transform of the controller)
		target = transform.TransformDirection(target);
		target = _bones[bone].transform.InverseTransformDirection(target);
		//create a rotation that rotates dir into target
		Quaternion quat = Quaternion.FromToRotation(dir,target);
		//if bone is the spine, add in the rotation along the spine
		if(bone == (int)Kinect2.JointType.SpineMid)
		{
			//rotate the chest so that it faces forward (determined by the shoulders)
			dir = _chestRight;
			target = GetVector3FromJoint(body.Joints[Kinect2.JointType.ShoulderRight]) - GetVector3FromJoint(body.Joints[Kinect2.JointType.ShoulderLeft]);
			
			target = transform.TransformDirection(target);
			target = _bones[bone].transform.InverseTransformDirection(target);
			target -= Vector3.Project(target,_boneDir[bone]);

			quat *= Quaternion.FromToRotation(dir,target);

			_vecbones[bone] = GetVector3FromJoint(body.Joints[Kinect2.JointType.SpineMid]);
		}
		//if bone is the hip override, add in the rotation along the hips
		else if(bone == (int)Kinect2.JointType.HipLeft)
		{
			//rotate the hips so they face forward (determined by the hips)
			dir = _hipRight;
			target = GetVector3FromJoint(body.Joints[Kinect2.JointType.HipRight]) - GetVector3FromJoint(body.Joints[Kinect2.JointType.HipLeft]);
			
			target = transform.TransformDirection(target);
			target = _bones[bone].transform.InverseTransformDirection(target);
			target -= Vector3.Project(target,_boneDir[bone]);
			
			quat *= Quaternion.FromToRotation(dir,target);
		}
		
		//reduce the effect of the rotation using the blend parameter
		Quaternion quat2 = Quaternion.Lerp(Quaternion.identity, quat, blendWeight);
		//apply the rotation to the local rotation of the bone
		_qbones[bone] = _bones[bone].transform.localRotation * quat2;

		if(bone == (int)Kinect2.JointType.SpineMid)
		{
			restoreBone(_bones[(int)Kinect2.JointType.HipLeft],_boneDir[(int)Kinect2.JointType.HipLeft],upDir);
			restoreBone(_bones[(int)Kinect2.JointType.HipLeft],_hipRight,rightDir);
		}
		
		return;
	}
	void Reader_MultiSourceFrameArrived(object sender, Kinect2.MultiSourceFrameArrivedEventArgs e)
	{
		var reference = e.FrameReference.AcquireFrame();
		using (var frame = reference.BodyFrameReference.AcquireFrame()) {
			if (frame != null) {
				_Bodies = new Kinect2.Body[frame.BodyFrameSource.BodyCount];
				
				frame.GetAndRefreshBodyData (_Bodies);
				foreach(Kinect2.Body body in _Bodies)
				{
					if(body.IsTracked)
					{
                        if (sAutoMotionCaptureDevicesSelecter != null)
                        {
                            sAutoMotionCaptureDevicesSelecter.bMoveTransform = true;
                        }
                        fFBXRecStart -= Time.deltaTime;
						if (fFBXRecStart <= 0.0) {
                            if (sFBXExporterForUnity != null)
                            {
                                sFBXExporterForUnity.bOutAnimation = true;
                            }
						}
						_Body = body;
						for( int ii = 0; ii < (int)Kinect2.JointType.ThumbRight - 4; ii++)
						{
							if( ((uint)Mask & (uint)(1 << ii) ) > 0 && (_nullMask & (uint)(1 << ii)) <= 0 )
							{
								RotateJoint(body, ii);
							}
						}
					}
				}
				frame.Dispose();
			}
		}
	}
Exemplo n.º 26
0
    private int BodyConfidence(Kinect.Body body)
    {
        int confidence = 0;

        foreach (Kinect.Joint j in body.Joints.Values)
        {
            if (j.TrackingState == Windows.Kinect.TrackingState.Tracked)
                confidence += 1;
        }

        return confidence;
    }
Exemplo n.º 27
0
 private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
 {
     for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
     {
         Kinect.Joint sourceJoint = body.Joints[jt];
         Kinect.Joint? targetJoint = null;
         
         if(_BoneMap.ContainsKey(jt))
         {
             targetJoint = body.Joints[_BoneMap[jt]];
         }
         
         // JW - capture active joint positions
         jointObjs[(int)jt] = bodyObject.transform.FindChild(jt.ToString());
         jointObjs[(int)jt].localPosition = GetVector3FromJoint(sourceJoint);
     }
 }
 public static Vector3 GetPosition(this WindowsKinect.Body body, WindowsKinect.JointType jointType)
 {
     var position = body.Joints[jointType].Position;
     return new Vector3(position.X, position.Y, position.Z);
 }
	private static Vector3 GetVector3FromJoint(Kinect2.Joint joint)
	{
		return new Vector3(joint.Position.X, joint.Position.Y + 1.0f, -joint.Position.Z + 2.0f);
	}
Exemplo n.º 30
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        foreach (Kinect.JointType jt in Joints) {
            Kinect.Joint sourceJoint = body.Joints[jt];

            Transform jointTransform = bodyObject.transform.FindChild(jt.ToString());
            Vector3 vector = GetVector3FromJoint(sourceJoint);
            jointTransform.localPosition = vector;

            if (jt == Kinect.JointType.HandLeft) {
                Transform thumbTransform = bodyObject.transform.FindChild(Kinect.JointType.HandTipLeft.ToString());
                updatePalm(jointTransform, thumbTransform, body.HandLeftState);
            } else if (jt == Kinect.JointType.HandRight) {
                Transform thumbTransform = bodyObject.transform.FindChild(Kinect.JointType.HandTipRight.ToString());
                updatePalm(jointTransform, thumbTransform, body.HandRightState);
            }
        }
    }