RigControl.cs
1.62 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
50
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RootSystem = System;
using System;
public class RigControl : MonoBehaviour
{
//[RootSystem.Runtime.InteropServices.DllImport("NtKinectDll")]
[DllImport("NtKinectDll", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
public static extern System.IntPtr getKinect();
[DllImport("NtKinectDll", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
public static extern int setSkeleton(System.IntPtr kinect, System.IntPtr data, System.IntPtr state, System.IntPtr id);
int bodyCount = 6;
int jointCount = 25;
private System.IntPtr kinect;
public GameObject humanoid;
public bool mirror = true;
public bool move = true;
CharacterSkeleton skeleton;
void Start()
{
kinect = getKinect();
skeleton = new CharacterSkeleton(humanoid);
}
void Update()
{
float[] data = new float[bodyCount * jointCount * 3];
int[] state = new int[bodyCount * jointCount];
int[] id = new int[bodyCount];
GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
GCHandle gch2 = GCHandle.Alloc(state, GCHandleType.Pinned);
GCHandle gch3 = GCHandle.Alloc(id, GCHandleType.Pinned);
int n = setSkeleton(kinect, gch.AddrOfPinnedObject(), gch2.AddrOfPinnedObject(), gch3.AddrOfPinnedObject());
gch.Free();
gch2.Free();
gch3.Free();
if (n > 0)
{
skeleton.set(data, state, 0, mirror, move);
}
}
}