You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Kinect = Windows.Kinect;
|
|
|
|
public class SimpleVisualizer : MonoBehaviour {
|
|
private Dictionary<Kinect.JointType, GameObject> jointCubes = new Dictionary<Kinect.JointType, GameObject>();
|
|
|
|
private SkeletonData _skeletonData = null;
|
|
public SkeletonData skeletonData { set { _skeletonData = value; GenerateCubes(value); } }
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
//TODO if skeletonData.isDead == true, destroy self
|
|
|
|
if(jointCubes.Count != 0)
|
|
{
|
|
foreach(GameObject obj in jointCubes.Values)
|
|
{
|
|
obj.GetComponent<MeshRenderer>().enabled = SimpleCalibrator.EnableBones;
|
|
}
|
|
}
|
|
if (_skeletonData.isDead)
|
|
DestroyImmediate(gameObject);
|
|
|
|
UpdateCubes();
|
|
}
|
|
|
|
void UpdateCubes()
|
|
{
|
|
foreach (Kinect.JointType jointType in _skeletonData.joints.Keys)
|
|
{
|
|
if (jointCubes[jointType] != null)
|
|
{
|
|
jointCubes[jointType].transform.position = _skeletonData.joints[jointType].position;
|
|
jointCubes[jointType].transform.rotation = _skeletonData.joints[jointType].rotation;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void GenerateCubes(SkeletonData data)
|
|
{
|
|
if(jointCubes.Count!=0)
|
|
foreach (GameObject obj in jointCubes.Values)
|
|
{
|
|
DestroyImmediate(obj);
|
|
}
|
|
jointCubes.Clear();
|
|
//TODO
|
|
foreach (Kinect.JointType jointType in data.joints.Keys)
|
|
{
|
|
jointCubes.Add(jointType, DrawBones.CreateObj(PrimitiveType.Cube, jointType, _skeletonData.joints[jointType],transform));
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|