Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- public class CubemanController : MonoBehaviour
- {
- public bool MoveVertically = false;
- public bool MirroredMovement = false;
- //public GameObject debugText;
- //public GameObject Hip_Center;
- //public GameObject Spine;
- //public GameObject Shoulder_Center;
- //public GameObject Head;
- //public GameObject Shoulder_Left;
- //public GameObject Elbow_Left;
- //public GameObject Wrist_Left;
- //public GameObject Hand_Left;
- //public GameObject Shoulder_Right;
- //public GameObject Elbow_Right;
- //public GameObject Wrist_Right;
- //public GameObject Hand_Right;
- //public GameObject Hip_Left;
- //public GameObject Knee_Left;
- //public GameObject Ankle_Left;
- //public GameObject Foot_Left;
- //public GameObject Hip_Right;
- //public GameObject Knee_Right;
- //public GameObject Ankle_Right;
- //public GameObject Foot_Right;
- public LineRenderer SkeletonLine;
- //private GameObject[] bones;
- private int[] parIdxs;
- private Vector3 initialPosition;
- private Quaternion initialRotation;
- private Vector3 initialPosOffset = Vector3.zero;
- private uint initialPosUserID = 0;
- Vector3 rightWristPOS = new Vector3();
- Vector3 leftWristPOS = new Vector3();
- void Start()
- {
- //store bones in a list for easier access
- //bones = new GameObject[] {
- // Hip_Center, Spine, Shoulder_Center, Head, // 0 - 3
- // Shoulder_Left, Elbow_Left, Wrist_Left, Hand_Left, // 4 - 7
- // Shoulder_Right, Elbow_Right, Wrist_Right, Hand_Right, // 8 - 11
- // Hip_Left, Knee_Left, Ankle_Left, Foot_Left, // 12 - 15
- // Hip_Right, Knee_Right, Ankle_Right, Foot_Right // 16 - 19
- //};
- parIdxs = new int[] {
- 0, 0, 1, 2,
- 2, 4, 5, 6,
- 2, 8, 9, 10,
- 0, 12, 13, 14,
- 0, 16, 17, 18
- };
- initialPosition = transform.position;
- initialRotation = transform.rotation;
- rightWristPOS = leftWristPOS = Vector3.zero;
- //transform.rotation = Quaternion.identity;
- }
- // Update is called once per frame
- void Update()
- {
- //Debug.Log("right wrist pos: "+bones[10].transform.position+" and left wrist pos: "+ bones[6].transform.position);
- //rightWristPOS = bones[10].transform.position;
- //leftWristPOS = bones[6].transform.position;
- if (rightWristPOS.z > leftWristPOS.z)
- {
- Debug.Log("right turn...");
- }
- else
- {
- Debug.Log("left turn...");
- }
- KinectManager manager = KinectManager.Instance;
- // get 1st player
- uint playerID = manager != null ? manager.GetPlayer1ID() : 0;
- if (playerID <= 0)
- {
- // reset the pointman position and rotation
- if (transform.position != initialPosition)
- {
- transform.position = initialPosition;
- }
- if (transform.rotation != initialRotation)
- {
- transform.rotation = initialRotation;
- }
- //for(int i = 0; i < bones.Length; i++)
- //{
- // bones[i].gameObject.SetActive(true);
- // bones[i].transform.localPosition = Vector3.zero;
- // bones[i].transform.localRotation = Quaternion.identity;
- //}
- return;
- }
- // set the user position in space
- Vector3 posPointMan = manager.GetUserPosition(playerID);
- posPointMan.z = !MirroredMovement ? -posPointMan.z : posPointMan.z;
- // store the initial position
- if (initialPosUserID != playerID)
- {
- initialPosUserID = playerID;
- initialPosOffset = transform.position - (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z));
- }
- transform.position = initialPosOffset + (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z));
- // update the local positions of the bones
- for (int i = 0; i < 20; i++) //for(int i = 0; i < bones.Length; i++)
- {
- //if(bones[i] != null)
- //{
- int joint = MirroredMovement ? KinectWrapper.GetSkeletonMirroredJoint(i) : i;
- if (manager.IsJointTracked(playerID, joint))
- {
- //bones[i].gameObject.SetActive(true);
- Vector3 posJoint = manager.GetJointPosition(playerID, joint);
- posJoint.z = !MirroredMovement ? -posJoint.z : posJoint.z;
- Quaternion rotJoint = manager.GetJointOrientation(playerID, joint, !MirroredMovement);
- rotJoint = initialRotation * rotJoint;
- posJoint -= posPointMan;
- if (MirroredMovement)
- {
- posJoint.x = -posJoint.x;
- posJoint.z = -posJoint.z;
- }
- //bones[i].transform.localPosition = posJoint;
- if (i == 6)
- {
- leftWristPOS = posJoint;
- }
- if (i == 10)
- {
- rightWristPOS = posJoint;
- }
- //bones[i].transform.rotation = rotJoint;
- }
- else
- {
- //bones[i].gameObject.SetActive(false);
- }
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement