forked from nuwud/Unity_Kinect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKinectCursor.cs
More file actions
49 lines (42 loc) · 1.17 KB
/
Copy pathKinectCursor.cs
File metadata and controls
49 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using System.Collections;
using Windows.Kinect;
public class KinectCursor : MonoBehaviour
{
public JointType jointId = JointType.HandLeft;
public float easing = 0.03f;
private Transform tr;
// Use this for initialization
void Start ()
{
// get local component
tr = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
if (BodySourceView.bodyTracked)
{
// fetch joint positions
Vector3 joint = BodySourceView.jointObjs[(int)jointId].position;
// easing towards X
float targetX = joint.x;
float posX = tr.position.x;
float dx = targetX - posX;
if (Mathf.Abs(dx) > 1)
{
posX += dx * easing;
}
// easing towards Y
float targetY = joint.y;
float posY = tr.position.y;
float dy = targetY - posY;
if (Mathf.Abs(dy) > 1)
{
posY += dy * easing;
}
// update cursor position
tr.position = new Vector3(posX, posY, tr.position.z);
}
}
}