本文整理汇总了C#中Windows.Kinect类的典型用法代码示例。如果您正苦于以下问题:C# Windows.Kinect类的具体用法?C# Windows.Kinect怎么用?C# Windows.Kinect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Windows.Kinect类属于命名空间,在下文中一共展示了Windows.Kinect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RotateAvatarJoints
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);
}
示例2: RefreshBodyObject
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");
}
示例3: GetVector3FromJoint
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);
}
示例4: RefreshBodyObject
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);
}
}
示例5: RotateBone
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));
}
示例6: IsInRange
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;
}
示例7: createJoint
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;
}
示例8: GetColorForState
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;
}
}
示例9: GetColorForState
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;
//}
}
示例10: addBone
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;
}
示例11: RefreshBodyObject
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);
}
}
示例12: GetVector3FromJoint
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);
}
}
示例13: RefreshBodyObject
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;
}
}
}
示例14: FindClosestBody
/// <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;
}
示例15: RefreshBodyObject
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;
}
}
}