t1 / TFDContents / Assets / KinectScripts / Samples / JointOrientationView.cs @ 9
이력 | 보기 | 이력해설 | 다운로드 (1.84 KB)
| 1 | 3 | KTH | using UnityEngine;  | 
      
|---|---|---|---|
| 2 | using System.Collections;  | 
      ||
| 3 | //using Windows.Kinect;  | 
      ||
| 4 | |||
| 5 | |||
| 6 | public class JointOrientationView : MonoBehaviour  | 
      ||
| 7 | {
 | 
      ||
| 8 | 	[Tooltip("Index of the player, tracked by this component. 0 means the 1st player, 1 - the 2nd one, 2 - the 3rd one, etc.")]
 | 
      ||
| 9 | public int playerIndex = 0;  | 
      ||
| 10 | |||
| 11 | 	[Tooltip("The Kinect joint we want to track.")]
 | 
      ||
| 12 | public KinectInterop.JointType trackedJoint = KinectInterop.JointType.SpineBase;  | 
      ||
| 13 | |||
| 14 | 	[Tooltip("Whether the joint view is mirrored or not.")]
 | 
      ||
| 15 | public bool mirroredView = false;  | 
      ||
| 16 | |||
| 17 | 	[Tooltip("Smooth factor used for the joint orientation smoothing.")]
 | 
      ||
| 18 | public float smoothFactor = 5f;  | 
      ||
| 19 | |||
| 20 | 	[Tooltip("GUI-Text to display the current joint rotation.")]
 | 
      ||
| 21 | public GUIText debugText;  | 
      ||
| 22 | |||
| 23 | private Quaternion initialRotation = Quaternion.identity;  | 
      ||
| 24 | |||
| 25 | |||
| 26 | void Start()  | 
      ||
| 27 | 	{
 | 
      ||
| 28 | initialRotation = transform.rotation;  | 
      ||
| 29 | //transform.rotation = Quaternion.identity;  | 
      ||
| 30 | }  | 
      ||
| 31 | |||
| 32 | void Update ()  | 
      ||
| 33 | 	{
 | 
      ||
| 34 | KinectManager manager = KinectManager.Instance;  | 
      ||
| 35 | |||
| 36 | if(manager && manager.IsInitialized())  | 
      ||
| 37 | 		{
 | 
      ||
| 38 | int iJointIndex = (int)trackedJoint;  | 
      ||
| 39 | |||
| 40 | if(manager.IsUserDetected(playerIndex))  | 
      ||
| 41 | 			{
 | 
      ||
| 42 | long userId = manager.GetUserIdByIndex(playerIndex);  | 
      ||
| 43 | |||
| 44 | if(manager.IsJointTracked(userId, iJointIndex))  | 
      ||
| 45 | 				{
 | 
      ||
| 46 | Quaternion qRotObject = manager.GetJointOrientation(userId, iJointIndex, !mirroredView);  | 
      ||
| 47 | qRotObject = initialRotation * qRotObject;  | 
      ||
| 48 | |||
| 49 | if(debugText)  | 
      ||
| 50 | 					{
 | 
      ||
| 51 | Vector3 vRotAngles = qRotObject.eulerAngles;  | 
      ||
| 52 | 						debugText.text = string.Format("{0} - R({1:000}, {2:000}, {3:000})", trackedJoint,
 | 
      ||
| 53 | vRotAngles.x, vRotAngles.y, vRotAngles.z);  | 
      ||
| 54 | }  | 
      ||
| 55 | |||
| 56 | if(smoothFactor != 0f)  | 
      ||
| 57 | transform.rotation = Quaternion.Slerp(transform.rotation, qRotObject, smoothFactor * Time.deltaTime);  | 
      ||
| 58 | else  | 
      ||
| 59 | transform.rotation = qRotObject;  | 
      ||
| 60 | }  | 
      ||
| 61 | |||
| 62 | }  | 
      ||
| 63 | |||
| 64 | }  | 
      ||
| 65 | }  | 
      ||
| 66 | }  |