t1 / TFDContents / Assets / KinectScripts / Samples / FollowUserRotation.cs @ 3
이력 | 보기 | 이력해설 | 다운로드 (1.26 KB)
| 1 | 3 | KTH | using UnityEngine; |
|---|---|---|---|
| 2 | using System.Collections; |
||
| 3 | |||
| 4 | public class FollowUserRotation : MonoBehaviour |
||
| 5 | {
|
||
| 6 | [Tooltip("Index of the player, tracked by this component. 0 means the 1st player, 1 - the 2nd one, 2 - the 3rd one, etc.")]
|
||
| 7 | public int playerIndex = 0; |
||
| 8 | |||
| 9 | void Update () |
||
| 10 | {
|
||
| 11 | KinectManager manager = KinectManager.Instance; |
||
| 12 | |||
| 13 | if(manager && manager.IsInitialized()) |
||
| 14 | {
|
||
| 15 | if(manager.IsUserDetected(playerIndex)) |
||
| 16 | {
|
||
| 17 | long userId = manager.GetUserIdByIndex(playerIndex); |
||
| 18 | |||
| 19 | if(manager.IsJointTracked(userId, (int)KinectInterop.JointType.ShoulderLeft) && |
||
| 20 | manager.IsJointTracked(userId, (int)KinectInterop.JointType.ShoulderRight)) |
||
| 21 | {
|
||
| 22 | Vector3 posLeftShoulder = manager.GetJointPosition(userId, (int)KinectInterop.JointType.ShoulderLeft); |
||
| 23 | Vector3 posRightShoulder = manager.GetJointPosition(userId, (int)KinectInterop.JointType.ShoulderRight); |
||
| 24 | |||
| 25 | posLeftShoulder.z = -posLeftShoulder.z; |
||
| 26 | posRightShoulder.z = -posRightShoulder.z; |
||
| 27 | |||
| 28 | Vector3 dirLeftRight = posRightShoulder - posLeftShoulder; |
||
| 29 | dirLeftRight -= Vector3.Project(dirLeftRight, Vector3.up); |
||
| 30 | |||
| 31 | Quaternion rotationShoulders = Quaternion.FromToRotation(Vector3.right, dirLeftRight); |
||
| 32 | |||
| 33 | transform.rotation = rotationShoulders; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |