// Update is called once per frame
    void Update () {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Windows.Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                CameraSpacePoint cameraSpacePoint = body.Joints[Windows.Kinect.JointType.HandLeft].Position;
                colorSpacePoint = kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(cameraSpacePoint);
            }
        }
    }
Exemple #2
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            Debug.Log("Forgot to attach BodySourceManager to this script/object in Inspector");
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            Debug.Log("Forgot to attach BodySourceManager script to BodyManager object");
            return;
        }

        Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            jointsXY = "NONE";
            //Debug.Log("no body");
            return;
        }

        // If the body is being tracked, then send data
        if(data[0].IsTracked)
        {
            // let BodySourceView take care of jointsXY
        }
        // Else send error data
        else
        {
            //jointsXY = "NONE";
            //Debug.Log("not tracked");
        }
    }
    // Update is called once per frame
    void Update()
    {
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        Kinect.Body body = data [0];
        if (!body.IsTracked)
            return;

        transform.localPosition = GetVector3FromJoint(body.Joints[Kinect.JointType.Head]); // 形状位置を更新
        Vector3 centerpoint;
        Vector3 wr = GetVector3FromJoint (body.Joints [Kinect.JointType.WristRight]);
        Vector3 er = GetVector3FromJoint (body.Joints [Kinect.JointType.ElbowRight]);
        centerpoint = (wr + er) / 2;
        Vector3 front = wr - er;

        rightarm.transform.rotation = Quaternion.LookRotation (front) * r;

        rightarm.transform.position = centerpoint;
    }
    void Update () 
    {
        if (BodySourceManager == null) {
            return;
        }
        
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null) {
            return;
        }
        
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null) {
            return;
        }
        
        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data) {
            if (body == null) {
            	continue;
          	}
                
            if(body.IsTracked) {
                trackedIds.Add (body.TrackingId);
            }
        }
        
        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);
        
        // First delete untracked bodies
        foreach(ulong trackingId in knownIds) {
            if(!trackedIds.Contains(trackingId)) {
				GameObject bodyObject = _Bodies[trackingId];

				foreach(GameObject tracker in _TrackerMap[bodyObject].TrackerMap.Values) {
					Destroy(tracker);
				}
				_TrackerMap.Remove(bodyObject);


				Destroy(bodyObject);
                _Bodies.Remove(trackingId);
            }
        }

        foreach(var body in data) {
            if (body == null) {
                continue;
            }
            
            if(body.IsTracked) {
                if(!_Bodies.ContainsKey(body.TrackingId)) {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }
                
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
 private WindowsKinect.Body[] GetAllSkeletonsInTheScreen(BodySourceManager bodyManager)
 {
     WindowsKinect.Body[] bodyManagerData = bodyManager.GetData();
     WindowsKinect.Body[] trackedBodies = bodyManagerData == null
         ? new WindowsKinect.Body[0]
         : System.Array.FindAll(bodyManagerData, body => body.IsTracked && IsInRange(body));
     return trackedBodies.Length == 0 ? new WindowsKinect.Body[0] : trackedBodies;
 }
    void Update()
    {
        if (_bodySourceManager == null)
        {
            return;
        }

        _bodyManager = _bodySourceManager.GetComponent<BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        foreach (var body in data) {

            if (body != null) {
                if (body.IsTracked) {

                    /*
                    if(visited == false){
                        trackId = (int)body.TrackingId;
                        visited = true;
                    }

                    if(newBody == false){
                        if((int)body.TrackingId != trackId){
                            newBody = true;
                            trackId2 = (int)body.TrackingId;
                            //l_one.clone();
                            //r_one.clone();
                            Debug.Log("cloning : "+running);
                        }
                    }
                    */
                    var pos = body.Joints [_jointType].Position;
                    rb.transform.position = new Vector3 (pos.X * 10, pos.Y * 10, pos.Z * 10);
                }
            }
        }
    }
	// Update is called once per frame
	void Update () {
		if (BodySourceManager == null)
		{
			return;
		}
		
		_BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
		if (_BodyManager == null)
		{
			return;
		}

		Kinect.Body[] data = _BodyManager.GetData();
		if (data == null)
		{
			return;
		}

		List<ulong> trackedIds = new List<ulong>();
		foreach(var body in data)
		{
			if (body == null)
			{
				continue;
			}
			
			if(body.IsTracked)
			{
				trackedIds.Add (body.TrackingId);
				trackedBody = body;
				break;
			}
		}

		// just get the first tracked id
		if (trackedIds.Count == 0) {
			Debug.Log ("没有追踪到目标用户");
		} else {
			Debug.Log("追踪到了目标用户");
			// analysis the action of user
			analysisUserAction();
		}
	}
    // Update is called once per frame
    void Update()
    {
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        Kinect.Body body = data [0];
        if (!body.IsTracked)
            return;

        transform.localPosition = GetVector3FromJoint(body.Joints[Kinect.JointType.ElbowLeft ]);  // 形状位置を更新
    }
    void Update()
    {
        if (BodySourceManager == null) {
            return;
        }
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null) {
            return;
        }
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null) {
            return;
        }
        List<ulong> trackedIds = new List<ulong>();

        if (!HasBody()) {
            foreach (var body in data) {
                if (body == null) {
                    continue;
                }
                if (body.IsTracked) {
                    trackedIds.Add(body.TrackingId);
                }
            }
        }
        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);
        // First delete untracked bodies
        foreach (ulong trackingId in knownIds) {
            if (!trackedIds.Contains(trackingId)) {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        foreach (var body in data) {
            if (body == null) {
                continue;
            }
            if (body.IsTracked) {
                RefreshBodyObject(body);
            }
        }
    }
Exemple #10
0
 // Check Body Manager, grab first valid body
 protected virtual void FindValidBody()
 {
     if (_BodySource != null)
     {
         Body[] bodies = _BodySource.GetData();
         if (bodies != null)
         {
             foreach (Body body in bodies)
             {
                 if (body.IsTracked)
                 {
                     isPlayerDetected = true;
                     SetBody(body.TrackingId);
                     break;
                 }
                 else
                 {
                     isPlayerDetected = false;
                 }
             }
         }
     }
 }
	void Update () 
    {
        if (_bodySourceManager == null)
        {
            return;
        }

        _bodyManager = _bodySourceManager.GetComponent<BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

		//get available bodies
        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

		//process each body
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
				//change object position
                var pos = body.Joints[_jointType].Position;
				this.gameObject.transform.position = new Vector3(pos.X*5, pos.Y*5, pos.Z*5);
                break;
            }
        }
	}
Exemple #12
0
    void FixedUpdate()
    {
        if (BodySrcManager == null)
        {
            return;
        }

        bodies = bodyManager.GetData();

        if (bodies == null)
        {
            return;
        }

        foreach (var body in bodies)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                var pos = body.Joints[TrackedJoint].Position;
                //gameObject.transform.position = new Vector3(pos.X*speed, pos.Y*speed);

                GetComponent <Rigidbody>().MovePosition(new Vector3
                                                        (
                                                            Mathf.Clamp(pos.X * speed, xMin, xMax),
                                                            Mathf.Clamp(pos.Y * speed, yMin, yMax),
                                                            0.0f
                                                        ));

                //GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
            }
        }
    }
    void Update()
    {
        if (_bodySourceManager == null)
        {
            return;
        }

        _bodyManager = _bodySourceManager.GetComponent <BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

        //get available bodies
        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        //process each body
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                //change object position
                var pos = body.Joints[_jointType].Position;
                this.gameObject.transform.position = new Vector3(pos.X * 5, pos.Y * 5, pos.Z * 5);
                break;
            }
        }
    }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        if (_bodySourceManager == null)
        {
            return;
        }

        _bodyManager = _bodySourceManager.GetComponent <BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        // get the first tracked body...
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                //this.gameObject.transform.position = new Vector3
                // this.gameObject.transform.localPosition =  body.Joints[_jointType].Position;
                var pos = body.Joints[_jointType].Position;
                this.gameObject.transform.position = new Vector3(pos.X, pos.Y, pos.Z);
                break;
            }
        }
    }
Exemple #15
0
    // Update is called once per frame
    void Update()
    {
        if (bodyManager == null)
        {
            Debug.Log("BodyManager is not available");
            return;
        }
        else
        {
            pilots = bodyManager.GetData();

            if (pilots == null)
            {
                return;
            }
            else
            {
                foreach (var pilot in pilots)
                {
                    if (pilot == null)
                    {
                        continue;
                    }
                    else
                    {
                        if (pilot.IsTracked)
                        {
                            //Debug.Log("Tracking now" + pilot.Joints[TrackedJoint].Position.X);
                            var pos = pilot.Joints[TrackedJoint].Position;
                            gameObject.transform.position = new Vector3(pos.X * multiplier, (pos.Y * multiplier), pos.Z * multiplier);
                        }
                    }
                }
            }
        }
    }
Exemple #16
0
 // Update is called once per frame
 void Update()
 {
     if (bodyManager == null)
     {
         return;
     }
     bodies = bodyManager.GetData();
     if (bodies == null)
     {
         return;
     }
     foreach (var body in bodies)
     {
         if (body == null)
         {
             continue;
         }
         if (body.IsTracked)
         {
             var pos = body.Joints[Trackhead].Position;
             gameObject.transform.position = new Vector3(pos.X * 10f, pos.Y * 10f);
         }
     }
 }
Exemple #17
0
    // Update is called once per frame
    void Update()
    {
        if (bodyManager == null)
        {
            return;
        }
        bodies = bodyManager.GetData();

        if (bodies == null)
        {
            return;
        }
        var body = this.bodies[0];

        if (body.IsTracked)
        {
            var pos = body.Joints[RightHand].Position;
            gameObject.transform.position = new Vector3(multiplier * pos.X, multiplier * pos.Y);
            if (body.Joints[LeftHand].Position.Y > body.Joints[LeftElbow].Position.Y)
            {
                Debug.Log("OnHealRequest()");
            }
        }
    }
    public void disableRendering()
    {
        rendering = false;
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Windows.Kinect.Body[] data = _BodyManager.GetData();
        foreach (var body in data) {
                        if (body == null) {
                                continue;
                        }

            if (body.IsTracked) {
                Destroy(_Bodies[body.TrackingId]);
                _Bodies.Remove(body.TrackingId);
                        }
                }

        foreach(KeyValuePair<Windows.Kinect.JointType, GameObject> k in rot)
        {
            k.Value.SetActive(false);
            // do something with entry.Value or entry.Key
        }
    }
Exemple #19
0
    // Update is called once per frame
    void Update()
    {
        if (!CanWork || !isServer)
        {
            return;
        }

        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        int i = 0;

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                RefreshBodyObject(body);
            }
            i++;
        }
    }
    // Update is called once per frame
    void Update()
    {
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null) {
            return;
        }
        else{
            for(int i=0;i<data.Length;i++){
                Vector3 nearbody=GetVector3FromJoint(data[i].Joints[Kinect.JointType.Head]);
                if(nearbody.z<beforebody.z)
                {
                    beforebody=nearbody;
                    Player=i;
                }
            }
        }
        Kinect.Body body = data [Player];
        if (!body.IsTracked)
            return;

        transform.localPosition = GetVector3FromJoint(body.Joints[Kinect.JointType.Head]);
        // ͠гɊӵðΘі
        Vector3 sb = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineBase]);
        Vector3 hr = GetVector3FromJoint (body.Joints [Kinect.JointType.HipRight]);
        Vector3 hl = GetVector3FromJoint (body.Joints [Kinect.JointType.HipLeft]);
        Vector3 sm = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineMid]);
        Vector3 frontbelt = sb - sm;
        Vector3 backbelt = hl - sm;
        Vector3 yjkbelt = Vector3.Cross(frontbelt, backbelt);

        belt.transform.rotation = Quaternion.LookRotation (frontbelt,yjkbelt) * beltr;
        belt.transform.position = sb;

        //
        Vector3 sl = GetVector3FromJoint (body.Joints [Kinect.JointType.ShoulderLeft]);
        Vector3 sr = GetVector3FromJoint (body.Joints [Kinect.JointType.ShoulderRight]);
        //Vector3 sm = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineMid]);
        Vector3 frontbodyc = sl - sr;
        bodyc.transform.rotation = Quaternion.LookRotation (frontbodyc) * bodyr;
        bodyc.transform.position = sm;
        //
        Vector3 centerpointra;
        Vector3 wr = GetVector3FromJoint (body.Joints [Kinect.JointType.WristRight]);//手首を取得
        Vector3 er = GetVector3FromJoint (body.Joints [Kinect.JointType.ElbowRight]);//肘を取得
        centerpointra = (wr + er) / 2;//肘と手首の中点を求める
        Vector3 frontra = wr - er;//肘→手首のベクトルを求める
        Vector3 backra = sr - er;//外積を求めるために肘→肩のベクトルを求める
        Vector3 yjkra = Vector3.Cross(frontra, backra);
        Vector3 gskra = Vector3.Cross (yjkra, frontra);

        rightarm.transform.rotation = Quaternion.LookRotation (frontra,gskra) * rar;
        rightarm.transform.position = centerpointra;
        //
        Vector3 centerpointla;
        Vector3 wl = GetVector3FromJoint (body.Joints [Kinect.JointType.WristLeft]);
        Vector3 el = GetVector3FromJoint (body.Joints [Kinect.JointType.ElbowLeft]);

        centerpointla = (wl + el) / 2;
        Vector3 frontla = wl - el;
        Vector3 backla = sl - el;
        Vector3 yjkla = Vector3.Cross(frontla, backla);
        Vector3 gskla = Vector3.Cross (yjkla, frontla);

        leftarm.transform.rotation = Quaternion.LookRotation (frontla,gskla) * lar;
        leftarm.transform.position = centerpointla;
        //
        Vector3 centerpointrf;
        Vector3 kr = GetVector3FromJoint (body.Joints [Kinect.JointType.KneeRight]);
        Vector3 ar = GetVector3FromJoint (body.Joints [Kinect.JointType.AnkleRight]);
        Vector3 hpr = GetVector3FromJoint (body.Joints [Kinect.JointType.HipRight]);
        centerpointrf = (kr + ar) / 2;
        Vector3 frontrf = ar - kr;
        Vector3 backrf = hpr - kr;
        Vector3 yjkrf = Vector3.Cross(frontrf, backrf);
        Vector3 gskrf = Vector3.Cross (yjkrf, frontrf);
        rightfoot.transform.rotation = Quaternion.LookRotation (frontrf,gskrf) * rfr;
        rightfoot.transform.position = centerpointrf;

        //
        Vector3 centerpointlf;
        Vector3 kl = GetVector3FromJoint (body.Joints [Kinect.JointType.KneeLeft]);
        Vector3 al = GetVector3FromJoint (body.Joints [Kinect.JointType.AnkleLeft]);
        Vector3 hpl = GetVector3FromJoint (body.Joints [Kinect.JointType.HipLeft]);
        centerpointlf = (kl + al) / 2;
        Vector3 frontlf = al - kl;
        Vector3 backlf = hpl - kl;
        Vector3 yjklf = Vector3.Cross(frontlf, backlf);
        Vector3 gsklf = Vector3.Cross (yjklf, frontlf);
        leftfoot.transform.rotation = Quaternion.LookRotation (frontlf,gsklf) * lfr;
        leftfoot.transform.position = centerpointlf;
        //
        Vector3 centerpointrb;
        //Vector3 wr = GetVector3FromJoint (body.Joints [Kinect.JointType.WristRight]);
        Vector3 hdr = GetVector3FromJoint (body.Joints [Kinect.JointType.HandRight]);
        centerpointrb = (wr + hdr) / 2;
        Vector3 frontrb = hdr - wr;
        Vector3 backrb = er - wr;
        Vector3 yjkrb = Vector3.Cross(frontrb, backrb);
        Vector3 gskrb = Vector3.Cross (yjkrb, frontrb);
        rightbuster.transform.rotation = Quaternion.LookRotation (frontrb,gskrb) * rbr;
        rightbuster.transform.position = hdr;
        //
        Vector3 centerpointlb;
        //Vector3 wl = GetVector3FromJoint (body.Joints [Kinect.JointType.WristLeft]);
        Vector3 hdl = GetVector3FromJoint (body.Joints [Kinect.JointType.HandLeft]);
        centerpointlb = (wl + hdl) / 2;
        Vector3 frontlb = hdl - wl;
        Vector3 backlb = el - wl;
        Vector3 yjklb = Vector3.Cross(frontlb, backlb);
        Vector3 gsklb = Vector3.Cross (yjklb, frontlb);
        leftbuster.transform.rotation = Quaternion.LookRotation (frontlb,gsklb) * lbr;
        leftbuster.transform.position = hdl;
        //
        Vector3 ss = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineShoulder]);
        Vector3 frontrs = ss - sr;
        Vector3 backrs = er - sr;
        Vector3 yjkrs = Vector3.Cross(frontrs, backrs);
        Vector3 gskrs = Vector3.Cross(yjkrs, backrs);
        rightshoulder.transform.position = sr;
        rightshoulder.transform.Translate (new Vector3 (0, 0, -2));
        rightshoulder.transform.rotation = Quaternion.LookRotation (frontrs,gskrs) * rsr;
        //
        leftshoulder.transform.position = sl;
        Vector3 frontls = ss - sl;
        Vector3 backls = el - sl;
        Vector3 yjkls = Vector3.Cross(frontls, backls);
        Vector3 gskls = Vector3.Cross(yjkls, backls);
        leftshoulder.transform.position = sl;
        leftshoulder.transform.Translate (new Vector3 (0, 0, -2));
        leftshoulder.transform.rotation = Quaternion.LookRotation (frontls,gskls) * lsr;
    }
Exemple #21
0
    // Get body data from the body manager and track the joint for the active body
    void Update()
    {
        if (_bodyManager == null)
        {
            return;
        }

        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        // Use for actual multi-player environments!
        if ((data.Length >= ActiveBodyNumber) && (data[ActiveBodyNumber] != null) && (data[ActiveBodyNumber].IsTracked))
        {
            GetComponent <Rigidbody>().isKinematic = true;

            m_jointFilter.UpdateFilter(data[ActiveBodyNumber]);
            var Joints = m_jointFilter.GetFilteredJoints();

            m_leftHandState  = data[ActiveBodyNumber].HandLeftState;
            m_rightHandState = data[ActiveBodyNumber].HandRightState;

            // Grab the mid spine position, we'll use this to make all other joint movement relative to the spine (this way we can limit the Y position of the character)
            var midSpinePosition = Joints[(int)JointType.SpineMid];
            var jointPos         = Joints[(int)JointToUse];
            //jointPos.X -= midSpinePosition.X;
            //jointPos.Y -= midSpinePosition.Y;
            jointPos.Z -= midSpinePosition.Z;

            float zValue = (useZValue == true) ? jointPos.Z : 0f;


            Vector3 targetPosition = new Vector3((midSpinePosition.X + jointPos.X) * scale, ((yOffset + jointPos.Y) * scale), zValue);

            if (m_startingTime > 0f)
            {
                m_startingTime         -= 1.0f * Time.deltaTime;
                this.transform.position = Vector3.Lerp(this.transform.position, targetPosition, 0.7f * Time.deltaTime);
            }
            else
            {
                if (offsetObject != null)
                {
                    targetPosition.y += offsetObject.transform.position.y;
                }
                this.transform.position = targetPosition;
            }
        }
        else
        {
            // Hide the object by moving it far away from the camera.
            this.transform.position = new Vector3(Random.Range(-9f, 9f), -11f, 100.0f);

            m_startingTime = 4.0f;

            // Attempt to find the active body number by iterating through the current bodies, finding a relevant body, and then assigning the active body. Once we have one
            // the user will be reacting to it from that point forward.
            int bodyIndex = 0;
            foreach (Body body in data)
            {
                if ((body != null) && (body.IsTracked))
                {
                    ActiveBodyNumber = bodyIndex;
                    break;
                }
                bodyIndex++;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        for (int i=0; i<data.Length; i++) {

            //foreach(var body in data)
            //{
            if (data [i] == null) {
                continue;
            }

            if (data [i].IsTracked) {
                if(ctr==0){
                    initialPosition = data[i].Joints[JointType.SpineBase].Position
                }
                RefreshBodyObjectOrientation(data[i]);
                ctr++;
            }
        }
    }
Exemple #23
0
    // Update is called once per frame
    void Update()
    {
        clip         = Resources.Load("Materials/lasrhit2", typeof(AudioClip)) as AudioClip;
        source1.clip = clip;
        float _X  = ((float)_xFinal / 256.0f) - 1.0f;
        float _Y  = ((float)_yFinal / -424.0f) + 0.55f;
        float _X2 = ((float)_xFinal2 / 256.0f) - 1.0f;
        float _Y2 = ((float)_yFinal2 / -424.0f) + 0.55f;

        float _Z  = (prof2 / 1500.0f) - 1.0f;
        float _Z2 = (prof1 / 1500.0f) - 1.0f;

        //float _rootX1 = ((float)rootX1 / 256.0f) - 1.0f;
        //float _rootY1 = ((float)rootY1 / -424.0f) + 0.55f;

        float _rootX2 = ((float)rootX2 / 256.0f) - 1.0f;
        float _rootY2 = ((float)rootY2 / -424.0f) + 0.55f;

        //gameObject.transform.position = new Vector3 ((float)_xFinal * multiplier, (float)_yFinal * multiplier);
        //gameObject.transform.position = new Vector3 (_X * multiplier, _Y * multiplier);
        ///***Debug.Log(string.Format("_x{0},_y{1},_xX{2},_yY{3},rootX{4},rootY{5}", _X, _Y, _X2, _Y2, _rootX1, _rootY1));
        //start = new Vector3 (_X * multiplier, _Y * multiplier);
        //end = new Vector3(_X2 * multiplier, _Y2 * multiplier);
        if (prof1 == 0 || prof2 == 0)
        {
            start = new Vector3(_X * multiplier, _Y * multiplier, 0.0f * multiplier);
            end   = new Vector3(_X2 * multiplier, _Y2 * multiplier, 0.0f * multiplier);
        }
        else
        {
            start = new Vector3(_X * multiplier, _Y * multiplier, _Z * multiplier);
            end   = new Vector3(_X2 * multiplier, _Y2 * multiplier, _Z2 * multiplier);
            //Debug.Log(string.Format("SwordstartX: {0},SwordStartY: {1}", start.x, start.y));
            // Debug.Log(string.Format("SwordendX: {0},SwordendY: {1}", end.x, end.y));
        }

        //gameObject.transform.position = new Vector3(_rootX2*multiplier, _rootY2*multiplier, _Z2 * multiplier);

        setPosLineRenderer(line, start, end);

        if (profLaser1 < -0.4)
        {
            //laser1.material = null;
            laser1.material = sword1;

            //profLaser1 = UnityEngine.Random.Range(0.5f, 1.0f);
            profLaser1    = 0.9f;
            profLaser1end = profLaser1 + 0.2f;
            laser1x       = UnityEngine.Random.Range(-0.5f, 0.5f) * multiplier;
            laser1y       = UnityEngine.Random.Range(-0.1f, 0.3f) * multiplier;
        }
        else
        {
            profLaser1    = profLaser1 - factor;
            profLaser1end = profLaser1end - factor;
            startLaser1.Set(laser1x, laser1y, profLaser1 * multiplier);
            endLaser1.Set(laser1x, laser1y, profLaser1end * multiplier);
        }

        if (profLaser2 < -0.6)
        {
            profLaser2    = 0.9f;
            profLaser2end = profLaser2 + 0.2f;
            //laser2.material = null;
            laser2.material = sword1;
        }
        else
        {
            profLaser2    = profLaser2 - factor;
            profLaser2end = profLaser2end - factor;
            startLaser2.Set(0.25f * multiplier, 0.25f * multiplier, profLaser2 * multiplier);
            endLaser2.Set(0.26f * multiplier, 0.26f * multiplier, profLaser2end * multiplier);
        }

        if (profLaser3 < -0.6)
        {
            profLaser3    = 0.7f;
            profLaser3end = profLaser3 + 0.2f;
            //laser3.material = null;
            laser3.material = sword1;
        }
        else
        {
            profLaser3    = profLaser3 - (factor / 2);       //(factor+ UnityEngine.Random.Range(-0.1f,0.1f)) ;
            profLaser3end = profLaser3end - (factor / 2);    //(factor+ UnityEngine.Random.Range(-0.1f,0.1f));
            startLaser3.Set(-0.10f * multiplier, 0.10f * multiplier, profLaser3 * multiplier);
            endLaser3.Set(-0.11f * multiplier, 0.11f * multiplier, profLaser3end * multiplier);
        }
        setPosLineRenderer(laser1, startLaser1, endLaser1);
        setPosLineRenderer(laser2, startLaser2, endLaser2);
        setPosLineRenderer(laser3, startLaser3, endLaser3);

        isCollide = false;
        //Debug.Log(string.Format("prof1:{0},prof2:{1}", profLaser1, profLaser2));

        startLaser3v2 = new Vector2(startLaser3.x, startLaser3.y);
        endLaser3v2   = new Vector2(endLaser3.x, endLaser3.y);


        avg3Z = profLaser3end * multiplier;
        //avg3Z = ((profLaser3 * multiplier) + (profLaser3end * multiplier)) / 2.0f;
        avgZ = ((_Z * multiplier) + (_Z2 * multiplier)) / 2.0f;

        //Debug.Log(string.Format("z2:{0},z3:{1}",  avg2Z, avg3Z));
        //if (Math.Abs(avg2Z - avgZ) < 0.01f)
        if (Math.Abs(avg3Z - avgZ) < 0.3f)
        {
            Vector2 result = GetIntersectionPointCoordinates(startLaser3v2, endLaser3v2, start, end);
            avgX = (endLaser3v2.x + startLaser3v2.x) / 2;
            avgY = (endLaser3v2.y + startLaser3v2.y) / 2;
            if (Math.Abs(result.x - avgX) < 0.5f && Math.Abs(result.y - avgY) < 0.5f)
            {
                Debug.Log(string.Format("col"));
                source1.Play();
                laser3.material = sword;
                count           = count + 1;
            }
        }
        isCollide     = false;
        startLaser2v2 = new Vector2(startLaser2.x, startLaser2.y);
        endLaser2v2   = new Vector2(endLaser2.x, endLaser2.y);
        avg2Z         = profLaser2end * multiplier;
        if (Math.Abs(avg2Z - avgZ) < 0.3f)
        {
            Vector2 result = GetIntersectionPointCoordinates(startLaser2v2, endLaser2v2, start, end);
            ///Vector2 result = GetIntersectionPointCoordinates(startLaser2v2, endLaser2v2, startLaser3v2, endLaser3v2);
            //Debug.Log(string.Format("z2:{0},z:{1},puntox:{2}, puntoy:{3} ", avg2Z, avgZ,result.x,result.y));
            //1 Debug.Log(string.Format("SwordstartX: {0},SwordStartY: {1}", start.x, start.y));
            // Debug.Log(string.Format("SwordendX: {0},SwordendY: {1}", end.x, end.y));

            /*Debug.Log(result.x <= endLaser2v2.x && result.x >= startLaser2v2.x);//Para saber si pertenece a los 2 segmentos
             * Debug.Log(result.x <= endLaser3v2.x && result.x >= startLaser2v2.x );
             * Debug.Log( result.y <= endLaser2v2.y);
             * Debug.Log(result.y >= startLaser2v2.y);
             * Debug.Log(result.y);
             * Debug.Log(startLaser2v2.y);
             * Debug.Log(result.y <= startLaser3v2.y && result.y >= endLaser3v2.y);*/

            //if (result.x <=endLaser2v2.x && result.x >= startLaser2v2.x && result.x <= endLaser3v2.x && result.x >= startLaser3v2.x && result.y <= endLaser2v2.y && result.y >= startLaser2v2.y && result.y <= startLaser3v2.y && result.y >= endLaser3v2.y)
            //{

            /*if(isCollide){
             *  Debug.Log(string.Format("col"));
             *  laser2.material = sword;
             * }*/
            //}

            //if (result.x <= endLaser2v2.x && result.x >= startLaser2v2.x && result.x <= end.x && result.x >= start.x && result.y <= endLaser2v2.y && result.y >= startLaser2v2.y && result.y <= start.y && result.y >= end.y)
            avgX = (endLaser2v2.x + startLaser2v2.x) / 2;
            avgY = (endLaser2v2.y + startLaser2v2.y) / 2;

            //if (result.x <= endLaser2v2.x && result.x >= startLaser2v2.x && result.y <= endLaser2v2.y && result.y >= startLaser2v2.y) {

            /*if (result.x >= endLaser2v2.x && result.x <= startLaser2v2.x && result.y >= endLaser2v2.y && result.y <= startLaser2v2.y) {
             *      laser2.material = sword;
             *      count = count + 1;
             * }*/
            //if(isCollide)
            if (Math.Abs(result.x - avgX) < 0.5f && Math.Abs(result.y - avgY) < 0.5f)
            {
                Debug.Log(string.Format("col"));
                source1.Play();
                laser2.material = sword;
                count           = count + 1;
            }
        }


        isCollide     = false;
        avg1Z         = profLaser1end * multiplier;
        startLaser1v2 = new Vector2(startLaser1.x, startLaser1.y);
        endLaser1v2   = new Vector2(endLaser1.x, endLaser1.y);
        avgZ          = ((_Z * multiplier) + (_Z2 * multiplier)) / 2.0f;

        //Debug.Log(string.Format("z2:{0},z3:{1}",  avg2Z, avg3Z));
        //if (Math.Abs(avg2Z - avgZ) < 0.01f)
        if (Math.Abs(avg1Z - avgZ) < 0.1f)
        {
            Vector2 result = GetIntersectionPointCoordinates(startLaser1v2, endLaser1v2, start, end);
            ///Vector2 result = GetIntersectionPointCoordinates(startLaser2v2, endLaser2v2, startLaser3v2, endLaser3v2);
            //Debug.Log(string.Format("z2:{0},z:{1},puntox:{2}, puntoy:{3} ", avg1Z, avgZ, result.x, result.y));
            //1 Debug.Log(string.Format("SwordstartX: {0},SwordStartY: {1}", start.x, start.y));
            Debug.Log(string.Format("SwordendX: {0},SwordendY: {1}", end.x, end.y));
            avgX = (endLaser1v2.x + startLaser1v2.x) / 2;
            avgY = (endLaser1v2.y + startLaser1v2.y) / 2;

            if (Math.Abs(result.x - avgX) < 0.3f && Math.Abs(result.y - avgY) < 0.3f)
            {
                Debug.Log(string.Format("colision laser 1"));
                source1.Play();
                laser1.material = sword;
                count           = count + 1;
            }
        }
        if (bodyManager == null)
        {
            return;
        }
        bodies = bodyManager.GetData();
        if (bodies == null)
        {
            return;
        }

        foreach (var body in bodies)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                var pos = body.Joints [TrackedJoint].Position;
                //gameObject.transform.position = new Vector3 (pos.X * multiplier, pos.Y * multiplier,pos.Z*multiplier-1.0f) ;
                //gameObject.transform.position = new Vector3(pos.X * multiplier, pos.Y * multiplier, 0.0f * multiplier);
                //Debug.Log(string.Format("x: {0}, y:{1},z: {2}", pos.X, pos.Y, pos.Z));
            }
        }
    }
    void FixedUpdate()
    {
        bodySourceGameObject = GameObject.Find("BodyManager");

        if (bodySourceGameObject == null) {
            Debug.Log("Couldn't find body manager object");
            return;
        }

        bodySourceManager = bodySourceGameObject.GetComponent<BodySourceManager>();
        if (bodySourceManager == null) {
            Debug.Log("Couldn't find BodySourceManager");
            return;
        }

        bodies = bodySourceManager.GetData();

        if (bodies == null) {
            return;
        }

        updateClosestPlayer();
    }
Exemple #25
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
                if (!Player1.IsTracked)
                {
                    Player1.Id        = body.TrackingId;
                    Player1.IsTracked = true;
                    Player1.Body      = body;
                }
                else
                if (!Player2.IsTracked && body.TrackingId != Player1.Id)
                {
                    Player2.Id        = body.TrackingId;
                    Player2.IsTracked = true;
                    Player2.Body      = body;
                }
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                if (Player1.Id == trackingId)
                {
                    Player1.SendMessage("LogLoss");
                    Player1.Id        = 0;
                    Player1.IsTracked = false;
                    Player1.Body      = null;
                    Player1.GetRandomAvatar();
                }
                else if (Player2.Id == trackingId)
                {
                    Player2.SendMessage("LogLoss");
                    Player2.Id        = 0;
                    Player2.IsTracked = false;
                    Player2.Body      = null;
                    Player2.GetRandomAvatar();
                }
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    void Update () 
    {
        //TrackingIdText.text = "---\n\n";
        TrackingIdText.text = "";

        if (BodySourceManager == null)
        {
            return;
        }
        
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }
        
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        //TrackingIdText.text += "body in data\n";
        
        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }
                
            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
                //TrackingIdText.text += string.Format("{0} . {1}\n", (int)body.TrackingId, body.TrackingId);
                const float mtoft = 100f / 30.48f;
                Kinect.CameraSpacePoint headPos = body.Joints[Kinect.JointType.Head].Position;
                float distHead = headPos.Z * mtoft;

                //Kinect.CameraSpacePoint spineBasePos = body.Joints[Kinect.JointType.SpineBase].Position;
                //float distSpineBase = spineBasePos.Z * mtoft;
                //TrackingIdText.text += string.Format("{0}\n{1}\n\n{2}\n{3}\n",
                //    distHead.ToString("0.0"), distSpineBase.ToString("0.0"),
                //    headPos.Z.ToString("0.0"), spineBasePos.Z.ToString("0.0"));
                TrackingIdText.text += string.Format("{0}\n", body.TrackingId);
            }
        }
        
        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);
        
        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        //TrackingIdText.text += "contains key\n";

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }
            
            if(body.IsTracked)
            {
                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                    //TrackingIdText.text += string.Format("{0}\n", body.TrackingId);
                }
                //TrackingIdText.text += string.Format("{0} . {1}\n", (int)body.TrackingId, body.TrackingId);
                
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager> ();
        if (_BodyManager == null) {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData ();
        if (data == null) {
            return;
        } else {
            beforebody = new Vector3 (0, 0, 1000);
            for (int i=0; i<data.Length; i++) {
                Vector3 nearbody = GetVector3FromJoint (data [i].Joints [Kinect.JointType.Head]);
                if (nearbody.z < beforebody.z && nearbody.z != 0) {
                    beforebody = nearbody;
                    Player = i;
                }
            }
        }
        Kinect.Body body = data [Player];
        //トラッキング出来てなかったら・・・メッシュレンダラーを切る
        if (!body.IsTracked)
            return;

        //transform.localPosition = GetVector3FromJoint (body.Joints [Kinect.JointType.Head]);
        Vector3 Head = GetVector3FromJoint (body.Joints [Kinect.JointType.Head]);
        Vector3 Neck = GetVector3FromJoint (body.Joints [Kinect.JointType.Neck]);
        Vector3 ss = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineShoulder]);
        Vector3 sr = GetVector3FromJoint (body.Joints [Kinect.JointType.ShoulderRight]);
        Vector3 fronthead = Head - ss;
        Vector3 backhead = sr - ss;
        Vector3 yjkhead = Vector3.Cross (fronthead, backhead);

        mask.transform.rotation = Quaternion.LookRotation (fronthead, yjkhead) * maskr;
        mask.transform.position = Head;
        // マスクを移動

        Vector3 frontneckc = ss - Neck;
        neckc.transform.rotation = Quaternion.LookRotation (frontneckc) * maskr;
        neckc.transform.position = Neck;
        //首を移動
        Vector3 centerpointbelt;
        Vector3 sb = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineBase]);
        Vector3 hr = GetVector3FromJoint (body.Joints [Kinect.JointType.HipRight]);
        Vector3 hl = GetVector3FromJoint (body.Joints [Kinect.JointType.HipLeft]);
        Vector3 sm = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineMid]);
        centerpointbelt = (sb + sm) / 2;
        Vector3 frontbelt = sb - sm;
        Vector3 backbelt = hl - sm;
        Vector3 yjkbelt = Vector3.Cross (frontbelt, backbelt);

        belt.transform.rotation = Quaternion.LookRotation (frontbelt, yjkbelt) * beltr;
        belt.transform.position = centerpointbelt;
        //ベルトを移動

        Vector3 centerpointbodyc;
        Vector3 sl = GetVector3FromJoint (body.Joints [Kinect.JointType.ShoulderLeft]);
        //Vector3 sm = GetVector3FromJoint (body.Joints [Kinect.JointType.SpineMid]);
        centerpointbodyc = (sm + ss) / 2;
        Vector3 frontbodyc = sm - ss;
        Vector3 backbodyc = sl - ss;
        Vector3 yjkbodyc = Vector3.Cross (frontbodyc, backbodyc);
        bodyc.transform.rotation = Quaternion.LookRotation (frontbodyc,yjkbodyc) * bodyr;
        bodyc.transform.position = centerpointbodyc;
        //ボディーを移動

        back.transform.position = sm;
        back.transform.rotation = Quaternion.LookRotation (frontbodyc) * backr;
        //

        Vector3 centerpointra;
        Vector3 wr = GetVector3FromJoint (body.Joints [Kinect.JointType.WristRight]);//手首を取得
        Vector3 er = GetVector3FromJoint (body.Joints [Kinect.JointType.ElbowRight]);//肘を取得
        centerpointra = (wr + er) / 2;//肘と手首の中点を求める
        Vector3 frontra = wr - er;//肘→手首のベクトルを求める
        Vector3 backra = sr - er;//外積を求めるために肘→肩のベクトルを求める
        Vector3 yjkra = Vector3.Cross (frontra, backra);
        Vector3 gskra = Vector3.Cross (yjkra, frontra);

        rightarm.transform.rotation = Quaternion.LookRotation (frontra,gskra) * rar;
        rightarm.transform.position = centerpointra;
        //右腕を移動

        Vector3 centerpointrua;
        Vector3 el = GetVector3FromJoint (body.Joints [Kinect.JointType.ElbowLeft]);
        centerpointrua = (sr + er) / 2;
        Vector3 frontrua = er - sr;
        rightupperarm.transform.rotation = Quaternion.LookRotation (frontrua) * ruar;
        rightupperarm.transform.position = centerpointrua;
        //右二の腕を移動

        Vector3 centerpointla;
        Vector3 wl = GetVector3FromJoint (body.Joints [Kinect.JointType.WristLeft]);

        centerpointla = (wl + el) / 2;
        Vector3 frontla = wl - el;
        Vector3 backla = sl - el;
        Vector3 yjkla = Vector3.Cross (frontla, backla);
        Vector3 gskla = Vector3.Cross (yjkla, frontla);
        leftarm.transform.rotation = Quaternion.LookRotation (frontla, gskla) * lar;
        leftarm.transform.position = centerpointla;
        //左腕を移動

        Vector3 centerpointlua;
        centerpointlua = (sl + el) / 2;
        Vector3 frontlua = el - sl;
        leftupperarm.transform.rotation = Quaternion.LookRotation (frontlua) * luar;
        leftupperarm.transform.position = centerpointlua;
        //左二の腕を移動

        Vector3 centerpointrf;
        Vector3 kr = GetVector3FromJoint (body.Joints [Kinect.JointType.KneeRight]);
        Vector3 ar = GetVector3FromJoint (body.Joints [Kinect.JointType.AnkleRight]);
        Vector3 hpr = GetVector3FromJoint (body.Joints [Kinect.JointType.HipRight]);
        centerpointrf = (kr + ar) / 2;
        Vector3 frontrf = ar - kr;
        Vector3 backrf = hpr - kr;
        Vector3 yjkrf = Vector3.Cross (frontrf, backrf);
        Vector3 gskrf = Vector3.Cross (yjkrf, frontrf);
        rightfoot.transform.rotation = Quaternion.LookRotation (frontrf, gskrf) * rfr;
        rightfoot.transform.position = centerpointrf;
        //右膝下を移動

        Vector3 centerpointrt;
        centerpointrt = (hpr + kr) / 2;
        Vector3 frontrt = kr - hpr;
        rightthigh.transform.rotation = Quaternion.LookRotation (frontrt) * rtr;
        rightthigh.transform.position = centerpointrt;
        //右膝上を移動

        Vector3 centerpointlf;
        Vector3 kl = GetVector3FromJoint (body.Joints [Kinect.JointType.KneeLeft]);
        Vector3 al = GetVector3FromJoint (body.Joints [Kinect.JointType.AnkleLeft]);
        Vector3 hpl = GetVector3FromJoint (body.Joints [Kinect.JointType.HipLeft]);
        centerpointlf = (kl + al) / 2;
        Vector3 frontlf = al - kl;
        Vector3 backlf = hpl - kl;
        Vector3 yjklf = Vector3.Cross (frontlf, backlf);
        Vector3 gsklf = Vector3.Cross (yjklf, frontlf);
        leftfoot.transform.rotation = Quaternion.LookRotation (frontlf, gsklf) * lfr;
        leftfoot.transform.position = centerpointlf;
        //左膝下を移動

        Vector3 centerpointlt;
        centerpointlt = (hpl + kl) / 2;
        Vector3 frontlt = kl - hpl;
        leftthigh.transform.rotation = Quaternion.LookRotation (frontlt) * ltr;
        leftthigh.transform.position = centerpointlt;
        //左膝上を移動

        Vector3 fr = GetVector3FromJoint (body.Joints [Kinect.JointType.FootRight]);
        Vector3 centerpointrlg;
        centerpointrlg = (fr + ar) / 2;
        Vector3 frontrlg = fr - ar;
        Vector3 backrlg = kr - ar;
        rightleg.transform.rotation = Quaternion.LookRotation (frontrlg,backrlg) * rlgr;
        rightleg.transform.position = centerpointrlg;
        //右靴部分を移動

        Vector3 fl = GetVector3FromJoint (body.Joints [Kinect.JointType.FootLeft]);
        Vector3 centerpointllg;
        centerpointllg = (fl + al) / 2;
        Vector3 frontllg = fl - al;
        Vector3 backllg = kl - al;
        leftleg.transform.rotation = Quaternion.LookRotation (frontllg,backllg) * llgr;
        leftleg.transform.position = centerpointllg;
        //左靴部分を移動

        rightknee.transform.position = kr;
        //右ひざ部分を移動

        leftknee.transform.position = kl;
        //左ひざ部分を移動

        Vector3 centerpointrb;
        //Vector3 wr = GetVector3FromJoint (body.Joints [Kinect.JointType.WristRight]);
        Vector3 hdr = GetVector3FromJoint (body.Joints [Kinect.JointType.HandRight]);
        centerpointrb = (wr + hdr) / 2;
        Vector3 frontrb = hdr - wr;
        Vector3 backrb = er - wr;
        Vector3 yjkrb = Vector3.Cross (frontrb, backrb);
        Vector3 gskrb = Vector3.Cross (yjkrb, frontrb);
        rightbuster.transform.rotation = Quaternion.LookRotation (frontrb, gskrb) * rbr;
        rightbuster.transform.position = hdr;
        //右バスターを移動

        Vector3 centerpointlb;
        //Vector3 wl = GetVector3FromJoint (body.Joints [Kinect.JointType.WristLeft]);
        Vector3 hdl = GetVector3FromJoint (body.Joints [Kinect.JointType.HandLeft]);
        centerpointlb = (wl + hdl) / 2;
        Vector3 frontlb = hdl - wl;
        Vector3 backlb = el - wl;
        Vector3 yjklb = Vector3.Cross (frontlb, backlb);
        Vector3 gsklb = Vector3.Cross (yjklb, frontlb);
        leftbuster.transform.rotation = Quaternion.LookRotation (frontlb, gsklb) * lbr;
        leftbuster.transform.position = hdl;
        //左バスターを移動

        Vector3 frontrs = ss - sr;
        Vector3 backrs = er - sr;
        Vector3 yjkrs = Vector3.Cross (frontrs, backrs);
        Vector3 gskrs = Vector3.Cross (yjkrs, backrs);
        rightshoulder.transform.position = sr;
        //rightshoulder.transform.Translate (new Vector3 (0, 0, -2));
        rightshoulder.transform.rotation = Quaternion.LookRotation (frontrs, yjkrs) * rsr;
        //右肩を移動

        Vector3 frontls = ss - sl;
        Vector3 backls = el - sl;
        Vector3 yjkls = Vector3.Cross (frontls, backls);
        Vector3 gskls = Vector3.Cross (yjkls, backls);
        leftshoulder.transform.position = sl;
        //leftshoulder.transform.Translate (new Vector3 (0, 0, -2));
        leftshoulder.transform.rotation = Quaternion.LookRotation (frontls, yjkls) * lsr;
        //左肩を移動

        Vector3 fronthip = sb - sm;
        hip.transform.position = centerpointbelt;
        hip.transform.rotation = Quaternion.LookRotation (fronthip) * hipr;
        //腎部を移動

        changeeffect.transform.position = sb;
        changeeffect.transform.Translate (new Vector3 (0, 1, -4));
        chargeeffect.transform.position = hdr;
        //エフェクトを移動

        attackV.x=(hdr.x-sr.x)*1.2f;
        attackV.y=(hdr.y-sr.y)*1.2f;
        attackV.z=(hdr.z-sr.z);
        //attackに肩の座標から手の座標に向かう方向を求めて入れる
        bulleteffect.transform.position=this.transform.position+attackV;
        bulleteffect.transform.rotation=Quaternion.LookRotation(attackV);
        //現在の位置にattackVを足して肘から手に向かう延長線上に弾が飛んでいくようにする

        //henshinpose
        //Head head
        //SpineShoulder ss
        //ShoulderLeft sl
        //ShoulderRight sr
        //ElbowRight er
        //HandRight hdr
        //Neck Neck

        switch (henshin) {
        //変身一段階目
        case 0:
            if (sl.x <= hdr.x && ss.x >= hdr.x &&//左肩から肩中央に右手がある状態
                //sm.x <= er.x &&
                Head.y >= hdr.y && ss.y <= hdr.y && //頭から肩中央に右手がある状態
                sr.y >= er.y) //右肘が右肩より下にある状態
          	 	{
                htimer += Time.deltaTime;
                    Debug.Log("変身認識開始");
                }
            if (htimer >= 0.3){
                change1_se.Play();
                belt.GetComponent<MeshRenderer>().enabled = true;
                Debug.Log ("変身1段階目!");
                henshin = 1;
                htimer = 0;
            }
            break;
        //変身二段階目
        case 1:
            ktimer += Time.deltaTime;
            if (ktimer >= 10)
            {
                belt.GetComponent<MeshRenderer>().enabled = false;
                Debug.Log ("変身解除");
                henshin = 0;
                ktimer = 0;
                //一定時間放置してたら変身解除
            }
            if (sr.x <= hdr.x && sr.x <= er.x && hdr.x <= er.x + 1 && //右手が右肩と右肘の間にある状態
                    er.y <= sr.y && er.y <= hdr.y) //肘が手と右肩より下にある状態
            {
                htimer += Time.deltaTime;
            }
            if (htimer >= 1)
            {
                change1_se.Play();
                Debug.Log ("変身2段階目!!");
                henshin = 2;
                htimer = 0;
                ktimer = 0;
            }
            break;
        //変身三段階目
        case 2:
            ktimer += Time.deltaTime;
            if (ktimer >= 10)
            {
                belt.GetComponent<MeshRenderer>().enabled = true;
                Debug.Log ("変身解除");
                henshin = 0;
                ktimer = 0;
                //一定時間放置してたら変身解除
            }
            if(sr.x<=hdl.x&&//右肩より左手が外側にある状態
               Neck.y<=hdl.y&&sm.y<=el.y//左手が首と右肩より上にある状態
               ){
                change3_se.Play();
                //変身用項目(検索用)
                //falce(off)になっていたオブジェクトの描画をtrue(on)にして表示
                changeeffect.GetComponent<Renderer>().enabled=true;
                changeeffect.transform.FindChild("Particle System 1").gameObject.GetComponent<Renderer>().enabled=true;
                mask.GetComponent<MeshRenderer>().enabled = true;
                neckc.GetComponent<MeshRenderer>().enabled = true;
                rightarm.GetComponent<MeshRenderer>().enabled = true;
                rightupperarm.GetComponent<MeshRenderer>().enabled = true;
                leftarm.GetComponent<MeshRenderer>().enabled = true;
                leftupperarm.GetComponent<MeshRenderer>().enabled = true;
                rightfoot.GetComponent<MeshRenderer>().enabled = true;
                rightthigh.GetComponent<MeshRenderer>().enabled = true;
                leftfoot.GetComponent<MeshRenderer>().enabled = true;
                leftthigh.GetComponent<MeshRenderer>().enabled = true;
                rightleg.GetComponent<MeshRenderer>().enabled = true;
                leftleg.GetComponent<MeshRenderer>().enabled = true;
                rightknee.GetComponent<MeshRenderer>().enabled = true;
                leftknee.GetComponent<MeshRenderer>().enabled = true;
                bodyc.GetComponent<Renderer>().enabled=true;
                back.GetComponent<Renderer>().enabled=true;
                rightbuster.GetComponent<MeshRenderer>().enabled = true;
                leftbuster.GetComponent<MeshRenderer>().enabled = true;
                rightshoulder.GetComponent<MeshRenderer>().enabled=true;
                leftshoulder.GetComponent<MeshRenderer>().enabled=true;
                hip.GetComponent<MeshRenderer>().enabled=true;
                //this.transform.FindChild("default").gameObject.GetComponent<MeshRenderer>().enabled=true;
                //3段階目のポーズを検知したら変身
                Debug.Log("変身完了ッ!!!");
                henshin = 3;
                htimer = 0;
                ktimer = 0;
                attacktimer = 0;
            }
            break;
        case 3:
            //変身完了してたら・・・
            etimer += Time.deltaTime;//timer変数にdeltaTimeを足していく
            ktimer += Time.deltaTime;
            //タイマーが2以上なら・・・
            if (etimer >= 2)
            {
                changeeffect.GetComponent<Renderer> ().enabled = false;
                changeeffect.transform.FindChild ("Particle System 1").gameObject.GetComponent<Renderer> ().enabled = false;
                //変身して2秒経ったら変身を解除
            }
            if (hdr.y>sb.y&&sm.y>=hdr.y&&sl.x <= hdr.x )
            {
                Debug.Log("攻撃チャージ開始!");
                attacktimer += Time.deltaTime;
                //貯めポーズをしたらチャージ開始
            }
            else
            {
                //attacktimer = 0;
            }

            if (attacktimer >= 4)
            {
                chargeeffect.GetComponent<Renderer>().enabled=true;
                chargeeffect.transform.FindChild("Particle System 1").gameObject.GetComponent<Renderer>().enabled=true;
                Debug.Log("チャージ完了!");
                //チャージ完了したらエフェクト発生
                if (hdr.y>=sr.y)
                {
                    Debug.Log("攻撃!");
                    attacktimer = 0;
                    chargeeffect.GetComponent<Renderer>().enabled = false;
                    chargeeffect.transform.FindChild("Particle System 1").gameObject.GetComponent<Renderer>().enabled = false;
                    bulleteffect.GetComponent<Renderer>().enabled = true;
                    //チャージ完了後に攻撃ポーズをしたら攻撃
                }
            }
            if (hdr.y<=sr.y&&attacktimer == 0)
            {
                bulleteffect.GetComponent<Renderer>().enabled = false;
                Debug.Log("攻撃終了");
                //攻撃ポーズをやめたらエフェクト消滅
            }

            if (ktimer >= 160) {
                attacktimer = 0;
                //変身用項目(検索用)
                mask.GetComponent<MeshRenderer>().enabled = false;
                neckc.GetComponent<MeshRenderer>().enabled = false;
                rightarm.GetComponent<MeshRenderer>().enabled = false;
                rightupperarm.GetComponent<MeshRenderer>().enabled = false;
                leftarm.GetComponent<MeshRenderer>().enabled = false;
                leftupperarm.GetComponent<MeshRenderer>().enabled = false;
                rightfoot.GetComponent<MeshRenderer>().enabled = false;
                rightthigh.GetComponent<MeshRenderer>().enabled = false;
                leftfoot.GetComponent<MeshRenderer>().enabled = false;
                leftthigh.GetComponent<MeshRenderer>().enabled = false;
                rightleg.GetComponent<MeshRenderer>().enabled = false;
                leftleg.GetComponent<MeshRenderer>().enabled = false;
                rightknee.GetComponent<MeshRenderer>().enabled = false;
                leftknee.GetComponent<MeshRenderer>().enabled = false;
                belt.GetComponent<MeshRenderer>().enabled = false;
                bodyc.GetComponent<Renderer>().enabled=false;
                back.GetComponent<Renderer>().enabled=false;
                rightbuster.GetComponent<MeshRenderer>().enabled = false;
                leftbuster.GetComponent<MeshRenderer>().enabled = false;
                rightshoulder.GetComponent<MeshRenderer>().enabled=false;
                leftshoulder.GetComponent<MeshRenderer>().enabled=false;
                hip.GetComponent<MeshRenderer>().enabled=false;
                //this.transform.FindChild("default").gameObject.GetComponent<MeshRenderer>().enabled=false;
                changeeffect.GetComponent<Renderer>().enabled=false;
                changeeffect.transform.FindChild("Particle System 1").gameObject.GetComponent<Renderer>().enabled = false;
                chargeeffect.GetComponent<Renderer>().enabled=false;
                chargeeffect.transform.FindChild("Particle System 1").gameObject.GetComponent<Renderer>().enabled = false;
                bulleteffect.GetComponent<Renderer>().enabled = false;
                Debug.Log ("変身解除");
                henshin = 0;
                htimer = 0;
                ktimer = 0;
                //変身してしばらく経ったら全て初期状態に
            }
            break;
        }
    }
    /*** Update with every frame *****/
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                //Debug.Log("Null Body");
                continue;
              }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                main_camera.transform.parent = null;
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);

                if(IDToFirstBody == trackingId)
                {

                    IsFirstBody = true;
                }
            }
        }

        foreach(var body in data)
        {
            if (body == null)
            {
                //Debug.Log("Null Body");
                continue;
            }
            if(body.IsTracked)
            {

                if(IsFirstBody)// Start Detecting only one body
                {
                    Debug.Log("It Is First Body, ID: " + body.TrackingId);
                    //put rotation

                    CurrentBody = body;
                    IDToFirstBody = body.TrackingId;
                    IsFirstBody =false;

                    if(!_Bodies.ContainsKey(body.TrackingId))
                    {
                        _Bodies[body.TrackingId] = CreateBodyObject (body.TrackingId);
                    }

                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
                getHandCoordinates(CurrentBody, _Bodies[body.TrackingId]);

            }
        }
    }
Exemple #29
0
    void Update () 
    {

        GameControlObject = GameObject.Find("GameController");
        gameController = (GameController)GameControlObject.GetComponent(typeof(GameController));

        if (BodySourceManager == null)
        {
            gameController.body = "undef";
            return;
        }
        
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
       if (_BodyManager == null)
        {
            gameController.body = "undef";
            return;
        }
        
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            gameController.body = "undef";
            return;
        }
        
        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
              }
                
            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }
        
        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);
        
        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

       

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }
            
            if(body.IsTracked)
            {
                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }
                
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }

           /* else
            {
                gameController.body = "undef";
            }
            */
        }
    }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        if ( _CoordinateMapper ==null ) {
            _CoordinateMapper = _BodyManager.Sensor.CoordinateMapper;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {

                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    // depth distance winnow
                    Kinect.Joint head = body.Joints[Kinect.JointType.Head];
                    float z = head.Position.Z;
                    if(z >= distanceThreshold){
                        //Destroy(bodyObject);
                        continue;
                    }

                    // 認識してるボディの数表示 認識制限1人にする
                    Debug.Log(_Bodies.Count);
                    if(_Bodies.Count > 0){
                        Debug.Log("1人プレイだよ");
                        continue;
                    }

                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);

                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
Exemple #31
0
    void Update()
    {
        Kinect.Body[] data = mBodySourceManager.GetData();

        //check to see if kenect is returning data
        if (data == null)
        {
            return;
        }

        //all tracking ids that the kinect can see
        List <ulong> trackedIds = new List <ulong>();



        foreach (var body in data)
        {
            //check to see if data isnt a body
            if (body == null)
            {
                continue;
            }

            //if body is currently being tracked add it to trackedIds list

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        //the keys of the bodies dictionary
        List <ulong> knownIds = new List <ulong>(mBodies.Keys);

        foreach (ulong trackingId in knownIds)
        {
            //if trackedIds list does not contain the tracking id from know ids delete from scene
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(mBodies[trackingId]);

                mBodies.Remove(trackingId);

                //reset bool tests
                resetTest();
            }
        }

        int counter = 0;

        //create bodies
        foreach (var body in data)
        {
            //if no body, skip
            if (body == null)
            {
                continue;
            }

            //body.TrackingId == trackedIds[0] ie/ if the bodys tracking ID is the first body that was tracked, creater and update it
            if (body.IsTracked && body.TrackingId == trackedIds[0])
            {
                chosenBody = body;

                //if body doesnt exist, create it
                if (!mBodies.ContainsKey(body.TrackingId))
                {
                    mBodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }


                UpdateBodyObject(body, mBodies[body.TrackingId]);
                //update position

                counter++;

                if (collisionManager.CheckHandsShowing())
                {
                    //MAKE rightState be grabbed from BodySourceView as body is not defined here.
                    Kinect.HandState rightState = chosenBody.HandRightState;

                    if (rightState == Kinect.HandState.Closed)
                    {
                        rightCloseFlag = true;
                        GameObject.Find("HandRight").GetComponent <SpriteRenderer>().sprite = mClosedRight;
                        //drop.DragOrPickUp();
                    }
                    if (rightState == Kinect.HandState.Open)
                    {
                        rightCloseFlag = false;
                        GameObject.Find("HandRight").GetComponent <SpriteRenderer>().sprite = mOpenRight;
                        //drop.DropItem();
                    }

                    //left hand
                    Kinect.HandState leftState = chosenBody.HandLeftState;

                    if (leftState == Kinect.HandState.Closed)
                    {
                        leftCloseFlag = true;
                        GameObject.Find("HandLeft").GetComponent <SpriteRenderer>().sprite = mClosedLeft;
                    }
                    if (leftState == Kinect.HandState.Open)
                    {
                        leftCloseFlag = false;
                        GameObject.Find("HandLeft").GetComponent <SpriteRenderer>().sprite = mOpenLeft;
                    }
                }
            }
        }
    }
Exemple #32
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        bool checkedFirst = false;
        ulong firstBody = 0;
        ulong persistBody = 0;
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }
            if(body.IsTracked)
            {
                if (!assigned)
                {
                    bodyOnly = body.TrackingId;
                    assigned = true;
                }
                if (!checkedFirst)
                {
                    firstBody = body.TrackingId;
                    checkedFirst = true;
                }
                if (body.TrackingId == bodyOnly)
                {
                    persistBody = body.TrackingId;
                }

                trackedIds.Add (body.TrackingId);
            }
        }

        if (persistBody == bodyOnly)
        {
            bodyOnly = persistBody;
        }
        else
        {
            bodyOnly = firstBody;
        }
        if (bodyOnly == 0)
            assigned = false;

           // Debug.Log("Calling here: " + bodyOnly);
           // assigned = false;

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
	void Update () 
	{
		if (BodySourceManager == null)
		{
			return;
		}
		
		_BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
		if (_BodyManager == null)
		{
			return;
		}
		
		Kinect.Body[] data = _BodyManager.GetData();
		if (data == null)
		{
			return;
		}
		
		List<ulong> trackedIds = new List<ulong>();
		foreach(var body in data)
		{
			if (body == null)
			{
				continue;
			}
			
			if(body.IsTracked)
			{
				trackedIds.Add (body.TrackingId);
			}
		}
		
		List<ulong> knownIds = new List<ulong>(_Bodies.Keys);
		
		// First delete untracked bodies
		foreach(ulong trackingId in knownIds)
		{
			if(!trackedIds.Contains(trackingId))
			{
				Destroy(_Bodies[trackingId]);
				_Bodies.Remove(trackingId);
			}
		}
		
		bodyTracked = false;
		
		foreach(var body in data)
		{
			if (body == null)
			{
				continue;
			}
			
			if (bodyTracked){
				continue;
			}
			
			if(body.IsTracked)
			{
				if(!_Bodies.ContainsKey(body.TrackingId))
				{
					// Draws stick figure of body to screen
					//_Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
				}

				//RefreshBodyObject(body, _Bodies[body.TrackingId]);
				
				// New head tracking code (testing)
				Kinect.Joint headJoint = body.Joints[Kinect.JointType.Head];
				if (headJoint.TrackingState == Kinect.TrackingState.Tracked)
				{
					Kinect.KinectSensor sensor = _BodyManager.getSensor();
					Kinect.DepthSpacePoint dsp = sensor.CoordinateMapper.MapCameraPointToDepthSpace(headJoint.Position);
					x = dsp.X;
					y = dsp.Y;
					bodyTracked = true;
					//Debug.Log (x);
					
				}
			}
		}
	}
Exemple #34
0
    // Update is called once per frame
    void Update()
    {
        //最初に追尾している人のBodyデータを取得する
        Body body = bodySourceManager.GetData().FirstOrDefault(b => b.IsTracked);

        if (body == null)
        {
            Debug.Log("体がないよ");
        }
        // Kinectを斜めに置いてもまっすぐにするようにする
        var        floorPlane = bodySourceManager.FloorClipPlane;
        Quaternion comp       = Quaternion.FromToRotation(
            new Vector3(-floorPlane.X, floorPlane.Y, floorPlane.Z), Vector3.up);

        Quaternion SpineBase;
        Quaternion SpineMid;
        Quaternion SpineShoulder;
        Quaternion ShoulderLeft;
        Quaternion ShoulderRight;
        Quaternion ElbowLeft;
        Quaternion WristLeft;
        Quaternion HandLeft;
        Quaternion ElbowRight;
        Quaternion WristRight;
        Quaternion HandRight;
        Quaternion KneeLeft;
        Quaternion AnkleLeft;
        Quaternion KneeRight;
        Quaternion AnkleRight;

        Quaternion       q;
        Quaternion       comp2;
        CameraSpacePoint pos;

        // 関節の回転を取得する
        if (body != null)
        {
            var joints = body.JointOrientations;

            //Kinectの関節回転情報をUnityのクォータニオンに変換
            SpineBase     = joints[JointType.SpineBase].Orientation.ToQuaternion(comp);
            SpineMid      = joints[JointType.SpineMid].Orientation.ToQuaternion(comp);
            SpineShoulder = joints[JointType.SpineShoulder].Orientation.ToQuaternion(comp);
            ShoulderLeft  = joints[JointType.ShoulderLeft].Orientation.ToQuaternion(comp);
            ShoulderRight = joints[JointType.ShoulderRight].Orientation.ToQuaternion(comp);
            ElbowLeft     = joints[JointType.ElbowLeft].Orientation.ToQuaternion(comp);
            WristLeft     = joints[JointType.WristLeft].Orientation.ToQuaternion(comp);
            HandLeft      = joints[JointType.HandLeft].Orientation.ToQuaternion(comp);
            ElbowRight    = joints[JointType.ElbowRight].Orientation.ToQuaternion(comp);
            WristRight    = joints[JointType.WristRight].Orientation.ToQuaternion(comp);
            HandRight     = joints[JointType.HandRight].Orientation.ToQuaternion(comp);
            KneeLeft      = joints[JointType.KneeLeft].Orientation.ToQuaternion(comp);
            AnkleLeft     = joints[JointType.AnkleLeft].Orientation.ToQuaternion(comp);
            KneeRight     = joints[JointType.KneeRight].Orientation.ToQuaternion(comp);
            AnkleRight    = joints[JointType.AnkleRight].Orientation.ToQuaternion(comp);

            // 関節の回転を計算する
            q = transform.rotation;
            transform.rotation = Quaternion.identity;

            comp2 = Quaternion.AngleAxis(0, new Vector3(0, 1, 0));               // * Quaternion.AngleAxis (-90, new Vector3 (0, 0, 1));

            Spine1.transform.rotation = SpineMid * comp2;

            RightArm.transform.rotation     = ElbowRight * comp2;
            RightForeArm.transform.rotation = WristRight * comp2;
            RightHand.transform.rotation    = HandRight * comp2;

            LeftArm.transform.rotation     = ElbowLeft * comp2;
            LeftForeArm.transform.rotation = WristLeft * comp2;
            LeftHand.transform.rotation    = HandLeft * comp2;

            RightUpLeg.transform.rotation = KneeRight * comp2;
            RightLeg.transform.rotation   = AnkleRight * comp2;

            LeftUpLeg.transform.rotation = KneeLeft * Quaternion.AngleAxis(90, new Vector3(1, 0, 0)) * Quaternion.AngleAxis(90, new Vector3(0, 0, 1));
            LeftLeg.transform.rotation   = AnkleLeft * Quaternion.AngleAxis(90, new Vector3(1, 0, 0)) * Quaternion.AngleAxis(90, new Vector3(0, 0, 1));

            // モデルの回転を設定する
            transform.rotation = q;

            // モデルの位置を移動する
            pos = body.Joints[JointType.SpineMid].Position;
            Ref.transform.position = new Vector3(-pos.X, pos.Y, pos.Z);
        }
    }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        Kinect.Body closestBody = FindClosestBody(data);

        if (closestBody == null)
        {
            return;
        }

        if (closestBody.IsTracked)
        {
            if (!_Bodies.ContainsKey(closestBody.TrackingId))
            {
                _Bodies[closestBody.TrackingId] = CreateBodyObject(closestBody.TrackingId);
            }

            RefreshBodyObject(closestBody, _Bodies[closestBody.TrackingId]);
        }
        //foreach (var body in data)
        //{
        //    if (body == null)
        //    {
        //        continue;
        //    }

        //    if (body.IsTracked)
        //    {
        //        if (!_Bodies.ContainsKey(body.TrackingId))
        //        {
        //            _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
        //        }

        //        RefreshBodyObject(body, _Bodies[body.TrackingId]);
        //    }
        //}
    }
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        if (frameCount == 0)
            firstBody = data [0];

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        for (int i=0; i<data.Length; i++) {

        //foreach(var body in data)
        //{
            if (data[i] == null)
            {
                continue;
            }

            if(data[i].IsTracked)
            {
                //data[i] = NormalizedBody(data[i],firstBody);
                //RefreshBodyObject(data[i],firstBody);
                RefreshBodyObjectOrientation (data[i]);
                /*Debug.Log("ELBOW RIGHT-> "+
                          "W: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.W *Mathf.Rad2Deg +
                          "X: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.X *Mathf.Rad2Deg+
                          "Y: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.Y *Mathf.Rad2Deg+
                          "Z: "+data[i].JointOrientations [Kinect.JointType.ElbowRight].Orientation.Z *Mathf.Rad2Deg
                          );*/
            }
        }
        /*
        //record skeleton and store to memory first
        if (Recording) {
            //bodyFrames.Clear();
            Debug.Log("Recording...");
            MySkeleton skel = new MySkeleton();
            skel.JointId = new int[data[0].Joints.Count];
            skel.Position = new Vector3Serializer[data[0].Joints.Count];
            skel.Rotation = new QuaternionSerializer[data[0].Joints.Count];
            //GetVector3FromJoint(body.Joints[Kinect.JointType.SpineBase]);
            for(int i=0;i<data[0].Joints.Count;i++){
                //Vector3 a=GetVector3FromJoint(data[0].Joints[(Kinect.JointType)i]);
                skel.Position[i]= new Vector3Serializer(GetVector3FromJoint(data[0].Joints[(Kinect.JointType)i]));
            }
            bodyFrames.Add(skel);
        }
        if (Metadata) {
            //bodyFrames.Clear();
            MySkeleton skel = new MySkeleton ();
            Debug.Log ("recording metadata");
            skel.JointId = new int[data[0].Joints.Count];
            skel.Position = new Vector3Serializer[data[0].Joints.Count];
            skel.Rotation = new QuaternionSerializer[data[0].Joints.Count];
            for(int i=0;i<data[0].Joints.Count;i++){
                skel.Position[i] = new Vector3Serializer(GetVector3FromJoint(data[0].Joints[(Kinect.JointType)i]));
            }
            Debug.Log("asu"+skel.Position[0].getVector());
            bodyFrames.Add(skel);

        }
        //serialize (store recorded skeleton as binary)
        if (isSaving) {
            Debug.Log("saving...");
            isSaving = false;
            serialize(bodyFrames);
            bodyFrames.Clear();
        }
        if(isSavingMetadata){
            serializeLength(bodyFrames);
            Debug.Log("Skeletons count:"+boneLengths.Count);
            Debug.Log("saving metadata");
            isSavingMetadata = false;
            bodyFrames.Clear();
        }
        frameCount++;
        */
    }
Exemple #37
0
    IEnumerator WaitForBodies()
    {
        if (pause)
        {
            yield break;
        }

        pause = true;
        yield return(null);

        bgmAudio1.Pause();

        //TODO:
        // 1)appear waiting infomation(UI)

        avatarL.hidden = true;
        avatarR.hidden = true;

        waitInfo.SetActive(true);

        for (;;)
        {
            Kinect.Body[] data = _BodyManager.GetData();
            if (data == null)
            {
                yield return(null);

                continue;
            }

            List <Kinect.Body> bodies = new List <Kinect.Body>();
            foreach (Kinect.Body body in data)
            {
                if (body != null && body.IsTracked)
                {
                    bodies.Add(body);
                }
            }

            if (bodies.Count == 2)
            {
                // todo: define left and right body
                float b0_x = bodies[0].Joints[Kinect.JointType.SpineBase].Position.X;
                float b1_x = bodies[1].Joints[Kinect.JointType.SpineBase].Position.X;


                if (b0_x < b1_x)
                {
                    BodyL = bodies[0];
                    BodyR = bodies[1];
                }
                else
                {
                    BodyL = bodies[1];
                    BodyR = bodies[0];
                }

                //Debug.Log("b0x = " + b0_x.ToString());
                //Debug.Log("b1x = " + b1_x.ToString());

                avatarL.hidden = false;
                avatarR.hidden = false;
                break;
            }
            yield return(null);
        }

        //TODO:
        //0)disappear waiting information
        waitInfo.SetActive(false);
        //1)Prepare to go( 3 ,2 ,1, GO!): UI

        countdownAudio.PlayOneShot(countdownAudio.clip);

        CountText.text = "3";

        yield return(new WaitForSeconds(1));

        CountText.text = "2";

        yield return(new WaitForSeconds(1));

        CountText.text = "1";

        yield return(new WaitForSeconds(1));

        //CountText.text = "Start!";
        pause = false;

        for (int i = 0; i < 5; ++i)
        {
            if (charL.transform.position.z > levelL[i].transform.position.z - wallAnimDistance)
            {
                levelL[i].GetComponent <Animator>().SetBool("isPlay", true);
            }
            else
            {
                break;
            }
        }

        for (int i = 0; i < 5; ++i)
        {
            if (charR.transform.position.z > levelR[i].transform.position.z - wallAnimDistance)
            {
                levelR[i].GetComponent <Animator>().SetBool("isPlay", true);
            }
            else
            {
                break;
            }
        }

        StartCoroutine(MoveCams());
        StartCoroutine(GameUpdateR());
        StartCoroutine(GameUpdateL());

        bgmAudio1.UnPause();

        CountText.text = "";
    }
    void Update()
    {
        /*
        // dont run Update() if there is no user
        BodySourceManager kinectManager;
        kinectManager = _bodySourceManager.GetComponent<BodySourceManager>();
        if(autoChangeAlfterDelay && (!kinectManager))
            return;
        */
        if(!isSpinning)
        {
            if(slideChangeWithKeys)
            {
                if(Input.GetKeyDown(KeyCode.PageDown))
                    RotateToNext();
                else if(Input.GetKeyDown(KeyCode.PageUp))
                    RotateToPrevious();
            }
            // check for automatic slide-change after a given delay time
            if(autoChangeAlfterDelay && Time.realtimeSinceStartup >= slideWaitUntil)
            {
                RotateToNext();
            }
        }
        else
        {
            // spin the presentation
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, spinSpeed * Time.deltaTime);

            // check if transform reaches the target rotation. If yes - stop spinning
            float deltaTargetX = Mathf.Abs(targetRotation.eulerAngles.x - transform.rotation.eulerAngles.x);
            float deltaTargetY = Mathf.Abs(targetRotation.eulerAngles.y - transform.rotation.eulerAngles.y);

            if(deltaTargetX < 1f && deltaTargetY < 1f)
            {
                // delay the slide
                slideWaitUntil = Time.realtimeSinceStartup + slideChangeAfterDelay;
                isSpinning = false;
            }
        }

        if (_bodySourceManager == null)
        {
            return;
        }

        _bodyManager = _bodySourceManager.GetComponent<BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

        Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        foreach (var body in data) {
            if (body == null) {
                continue;
            }
            if (body.IsTracked) {
                if(body.Joints[JointType.HandTipRight].Position.Y > body.Joints[JointType.Head].Position.Y){
                    if(!isSpinning)
                        RotateToNext();
                }
                if(body.Joints[JointType.HandTipLeft].Position.Y > body.Joints[JointType.Head].Position.Y){
                    if(!isSpinning)
                        RotateToPrevious();
                }
                string sideOfSquare = slideTextures[tex].name;
                if(body.HandRightState == HandState.Lasso && body.HandLeftState == HandState.Lasso){
                    if(sideOfSquare == "bomb"){
                        Application.LoadLevel("Main Scene");
                    }
                    else if(sideOfSquare == "scores"){
                        Application.LoadLevel("Scores");
                    }
                    else{
                        Application.LoadLevel("Second Scene");
                    }
                }
            }
        }
    }
Exemple #39
0
    void Update()
    {
        if (leftyToggle != null)
        {
            if (leftyToggle.isOn) //Left handed
            {
                leftyMode = true;
            }
            else
            {
                leftyMode = false;
            }
        }


        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            BodyFound = false;
            return;
        }

        FaceFrameResult[] faceData = _BodyManager.GetFaceData();

        if (faceData[0] != null)
        {
            faceRotation = new Quaternion(faceData[0].FaceRotationQuaternion.X, faceData[0].FaceRotationQuaternion.Y, faceData[0].FaceRotationQuaternion.Z, faceData[0].FaceRotationQuaternion.W);
        }


        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                BodyFound = true;
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    void Update()
    {
        int state = 0;

        if (BodySourceManager == null)
        {
            Debug.Log("Is BodyManager null" + BodySourceManager);

            return;
        }
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                //RefreshBodyObject(body, _Bodies[body.TrackingId]);

                //Check Hand State if body is being Tracked
                state = CheckLeftHandState(body.HandLeftState) + (2 * CheckRightHandState(body.HandRightState));
                if (!levelHasGenerated)
                    return;
                switch (state)
                {
                    case 0:
                        signalStart = false; 
                        break;
                    case 1:
                        //Left
                        if (prevState == 0)
                            platformRotate.TurnLeft();
                        Debug.Log("Left");
                        break;
                    case 2:
                        //Right
                        Debug.Log("Right");
                        if (prevState == 0)
                            platformRotate.TurnRight();
                        break;
                    case 3:
                        //Both
                        Debug.Log("Both");
                        if (prevState == 0)
                        {
                            //                     playerScript.flipjump = true; 
                            platformRotate.Flip();
                        }
                        break;
                    default:
                        break;
                }

                /*
                CheckRightHandState(body.HandRightState);
                CheckLeftHandState(body.HandLeftState);

                if(rightHandActive && leftHandActive)
                {
                    //flip
                    Debug.LogError("BOTH");
                }
                */
            }
        }


    }
Exemple #41
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }
        if (socket == null)
        {
            print("Null socket");
            socket = BodySourceManager.AddComponent <SocketIOComponent>();
            //socket.Awake();
            socket.Start();
            socket.Emit("kinect", JSONObject.StringObject("60"));
        }
        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        //foreach(ulong trackingId in knownIds)
        //{
        //    if(!trackedIds.Contains(trackingId))
        //    {
        //        Destroy(_Bodies[trackingId]);
        //        _Bodies.Remove(trackingId);
        //    }
        //}

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
Exemple #42
0
	// Update is called once per frame
	void Update () {

        if (bodySourceManager == null)
        {
            return;
        }
        bodyManager = bodySourceManager.GetComponent<BodySourceManager>();
        if(bodyManager == null)
        {
            return;
        }

        // get data from kinect
        Kinect.Body[] data = bodyManager.GetData();
        if(data == null)
        {
            return;
        }

        // get list of currently tracked bodies
        Kinect.Body potentialNewTrackedBody = null;
        bool stillTrackingPreviousBody = false;     // check if the previously tracked body is still there
        
        foreach(Kinect.Body body in data)
        {
            if(body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                
                // no body being track, get the first body found
                if (currentTrackedObject == null)
                {
                    currentTrackedObject = body;
                }

                // the previous body may already disappearred, save the first body found just in case
                if (potentialNewTrackedBody == null)
                {
                    potentialNewTrackedBody = body;
                }

                // still tracking previous body
                if (body.TrackingId == currentTrackedObject.TrackingId)
                {
                    stillTrackingPreviousBody = true;
                    break;
                }
            }
        }

        // 

        // the previously tracked body have disappear, get the new trackid found
        if(!stillTrackingPreviousBody)
        {
            currentTrackedObject = potentialNewTrackedBody;
        }

        if(currentTrackedObject == null)
        {
            return;
        }


        //////////////////////////////////////////
        // Everything after this is getting data of the body and manipulate the world
        ScoreManager.ready = true;


        // if holding something and left hand is closed, move the object according to hand movement
        if (currentTrackedObject.HandLeftState == Kinect.HandState.Closed && grabbed)
        {
            Debug.Log("Holding Object");
            DragObject();
        }

        // if not holding anything and left hand is closed, attempt to grab the object in the desired direction
        else if (!grabbed && currentTrackedObject.HandLeftState == Kinect.HandState.Closed)
        {
            Debug.Log("Trying to Grab Object");
            GrabObject();
        }

        // release hand while holding something will initiate throw
        else if (currentTrackedObject.HandLeftState == Kinect.HandState.Open && grabbed)
        {
            Debug.Log("Throwing Object");
            ThrowObject();
        }

        // shoot wave bullet if two hand open
        else if (currentTrackedObject.HandLeftState == Kinect.HandState.Open && currentTrackedObject.HandRightState == Kinect.HandState.Open) {

            Debug.Log("Wave Attack");
            UpdateAimTarget();
            GetComponent<Shooting>().Shoot(waveBullet, aimTarget.transform.position, aimTarget.transform.rotation);
        }

        // shoot wave bullet if left hand open and not holding anything
        else if (currentTrackedObject.HandLeftState == Kinect.HandState.Open) {
            Debug.Log("Bullet Attack");
            UpdateAimTarget();
            GetComponent<Shooting>().Shoot(lightBullet, aimTarget.transform.position, aimTarget.transform.rotation);
        }

        // other action should reset holding state
        else
        {
            //currentlyGrabbedObj = null;
            Debug.Log("Unknow Action");
            grabbed = false;
        }

        

        //Debug.Log(currentTrackedObject.HandRightState);
        //Debug.Log(previousHandState);
        previousHandState = currentTrackedObject.HandRightState;

        SaberControl();
    }
    void Update()
    {
        #region Get Kinect data
        Body[] data = mBodySourceManager.GetData();
        //checks to see if we have any data
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();
        //This list contains all the ids for bodies the kinect is tracking
        foreach (var body in data)
        {
            if (body == null)
            {
                //checks to see if we have a body
                continue;
            }

            if (body.IsTracked)
            {
                //if the body is actively being tracked we add it to the list
                trackedIds.Add(body.TrackingId);
            }
        }
        #endregion

        #region Delete Kinect Bodies
        List <ulong> knownIds = new List <ulong>(mBodies.Keys);
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                //Destroy body object
                Destroy(mBodies[trackingId]);

                //Remove from list
                mBodies.Remove(trackingId);
            }
        }
        #endregion

        #region Create Kinect bodies

        foreach (var body in data)
        {
            //If no body, skip
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                //If body isn't tracked, create body
                if (!mBodies.ContainsKey(body.TrackingId))
                {
                    //need to test if this works
                    //only creates a new body if mBodies is empty
                    if (mBodies.Count == 0)
                    {
                        mBodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                    }
                }
                if (mBodies.ContainsKey(body.TrackingId))
                {
                    //Update positions
                    UpdateBodyObject(body, mBodies[body.TrackingId]);
                }
                //after it updates it breaks so it doesnt getting any new tracking
                break;
            }
        }
        #endregion
    }
    void Update()
    {
        //如果沒有負責建立骨骼資料的GameObject則跳出這個Function。
        if (BodySourceManager == null)
        {
            return;
        }
        //讀取建立骨骼資料的Script。
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }
        //取得記錄骨骼資料的_Data陣列,如果取到的資料為null則離開這個Function。。
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        //new一個新的uLong的List,用來記錄當下(該次Update)所讀取到的骨骼的ID。
        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }
        //new一個新的uLong的List,顯示當前已經建立出來的骨骼模型,用來與上面建立的當前讀取骨骼做比對。
        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        //如果在比對的過程中,骨骼模型的ID並沒有在當前骨骼的ID中,代表此玩家已經離開了,因此刪除該GameObject。
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        //在刪除已經不在的玩家之後,繼續比對如果骨骼物件中沒有當前讀取到的骨骼ID,則建立新的骨骼物件。
        //若是比對的結果是骨骼物件也有繼續在當前ID中讀取到該ID,代表玩家還在進行中,則進行更新玩家動作的Function。
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First unassign untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                foreach (var body in bodyList)
                {
                    if (_bodyList[body] == trackingId)
                    {
                        _bodyList[body] = 0;
                    }
                }
                //Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    //if the body isn't set yet
                    //set it to a premade unused body
                    _Bodies[body.TrackingId] = AssignBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Windows.Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        if (rendering) {
                        foreach (var body in data) {
                                if (body != null) {
                                        if (body.IsTracked) {
                                                if (!_Bodies.ContainsKey (body.TrackingId)) {
                                                        _Bodies [body.TrackingId] = CreateBodyObject (body.TrackingId);
                                                }

                                                RefreshBodyObject (body, _Bodies [body.TrackingId]);
                                                currentId = body.TrackingId;
                                        }
                                }
                        }
                }

        if (Input.GetKeyDown (KeyCode.B)) {
            if (rendering)
                disableRendering ();
            else enableRendering();
        }
    }
Exemple #47
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                bodyTracked = true;

                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);

                bodyTracked = false;
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
Exemple #48
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _bodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_bodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _bodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
                break;
            }
        }

        List <ulong> knownIds = new List <ulong>(Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(Bodies[trackingId]);
                Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!Bodies.ContainsKey(body.TrackingId))
                {
                    GameObject   newBody   = new GameObject();
                    KinectPlayer newPlayer = Instantiate(Resources.Load("BlockPlayer") as GameObject, new Vector3(0, 0, 0), Quaternion.identity).GetComponent <KinectPlayer>();
                    newPlayer.Kinect = this;
                    if (players.Count == 0)
                    {
                        newPlayer.makeMainPlayer(true);
                    }
                    Bodies[body.TrackingId] = newPlayer.CreateBodyObject(body, newBody);
                    newPlayer.WarpToLocation(new Vector3(0, 1.5f, 0));
                    players.Add(newPlayer);

                    _bodyThread = new Thread(new ThreadStart(RefreshBody));
                    _bodyThread.Start();
                }

                foreach (KinectPlayer player in players)
                {
                    try
                    {
                        if (player.IsTracked())
                        {
                            player.gameObject.SetActive(true);
                            player.UpdateBodyObject();
                            player.AdjustBodyParts();
                        }
                        else
                        {
                            player.gameObject.SetActive(false);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Error getting body");
                        Debug.LogError(e);
                    }
                }
                break;
            }
        }
    }
Exemple #49
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Global.DeleteBody(_Bodies[trackingId]);
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);

                if (Global.clientStatus == Global.netStatus.Connected)
                {
                    timer += Time.deltaTime;
                    if (timer > bodyNetworkUpdateTime)
                    {
                        // Update body position to the network
                        Global.SendMovedBody(_Bodies[body.TrackingId]);
                        timer = 0f;
                    }
                }
            }
        }
    }
    void Update()
    {
        //GameObject.Find("/Game/FruitCreater").transform.GetComponent<CreateFruit>().GenerateInterval -= 0.0005f;
        //if (GameObject.Find("/Game/FruitCreater").transform.GetComponent<CreateFruit>().GenerateInterval < 0.001)
        //    GameObject.Find("/Game/FruitCreater").transform.GetComponent<CreateFruit>().GenerateInterval = 0.001f;



        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();

        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    StartCoroutine(ExecuteAfterTime(3));
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                    posOffset = GetOffset(body, gameObject.transform.position);

                    _InitialPos = GetInitialPos(body, posOffset);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
                // var pos = _Bodies[body.TrackingId].transform.Find("SpineShoulder").position;
                // var rot = _Bodies[body.TrackingId].transform.Find("SpineShoulder").rotation;
                // Camera.transform.position = pos;
                // Camera.transform.rotation = rot;
            }
        }
    }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }
        if (socket == null)
        {
            print("Null socket");
            socket = BodySourceManager.AddComponent<SocketIOComponent>();
            //socket.Awake();
            socket.Start();
            socket.Emit("kinect",  JSONObject.StringObject("60"));
        }
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
              }

            if (body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        //foreach(ulong trackingId in knownIds)
        //{
        //    if(!trackedIds.Contains(trackingId))
        //    {
        //        Destroy(_Bodies[trackingId]);
        //        _Bodies.Remove(trackingId);
        //    }
        //}

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
Exemple #53
0
    // Update is called once per frame
    void Update()
    {
        if (_BodyManager == null)
        {
            Debug.Log("_BodyManager == null");
            return;
        }

        // Bodyデータを取得する
        var data = _BodyManager.GetData();

        if (data == null)
        {
            return;
        }

        // 最初に追跡している人を取得する
        var body = data.FirstOrDefault(b => b.IsTracked);

        if (body == null)
        {
            return;
        }

        // 床の傾きを取得する
        var floorPlane = _BodyManager.FloorClipPlane;
        var comp       = Quaternion.FromToRotation(
            new Vector3(floorPlane.X, floorPlane.Y, floorPlane.Z), Vector3.up);

        // 関節の回転を取得する
        var joints = body.JointOrientations;

        Quaternion SpineBase;
        Quaternion SpineMid;
        Quaternion SpineShoulder;
        Quaternion ShoulderLeft;
        Quaternion ShoulderRight;
        Quaternion ElbowLeft;
        Quaternion WristLeft;
        Quaternion HandLeft;
        Quaternion ElbowRight;
        Quaternion WristRight;
        Quaternion HandRight;
        Quaternion KneeLeft;
        Quaternion AnkleLeft;
        Quaternion KneeRight;
        Quaternion AnkleRight;

        // 鏡
        if (IsMirror)
        {
            SpineBase     = joints[JointType.SpineBase].Orientation.ToMirror().ToQuaternion(comp);
            SpineMid      = joints[JointType.SpineMid].Orientation.ToMirror().ToQuaternion(comp);
            SpineShoulder = joints[JointType.SpineShoulder].Orientation.ToMirror().ToQuaternion(comp);
            ShoulderLeft  = joints[JointType.ShoulderRight].Orientation.ToMirror().ToQuaternion(comp);
            ShoulderRight = joints[JointType.ShoulderLeft].Orientation.ToMirror().ToQuaternion(comp);
            ElbowLeft     = joints[JointType.ElbowRight].Orientation.ToMirror().ToQuaternion(comp);
            WristLeft     = joints[JointType.WristRight].Orientation.ToMirror().ToQuaternion(comp);
            HandLeft      = joints[JointType.HandRight].Orientation.ToMirror().ToQuaternion(comp);
            ElbowRight    = joints[JointType.ElbowLeft].Orientation.ToMirror().ToQuaternion(comp);
            WristRight    = joints[JointType.WristLeft].Orientation.ToMirror().ToQuaternion(comp);
            HandRight     = joints[JointType.HandLeft].Orientation.ToMirror().ToQuaternion(comp);
            KneeLeft      = joints[JointType.KneeRight].Orientation.ToMirror().ToQuaternion(comp);
            AnkleLeft     = joints[JointType.AnkleRight].Orientation.ToMirror().ToQuaternion(comp);
            KneeRight     = joints[JointType.KneeLeft].Orientation.ToMirror().ToQuaternion(comp);
            AnkleRight    = joints[JointType.AnkleLeft].Orientation.ToMirror().ToQuaternion(comp);
        }
        // そのまま
        else
        {
            SpineBase     = joints[JointType.SpineBase].Orientation.ToQuaternion(comp);
            SpineMid      = joints[JointType.SpineMid].Orientation.ToQuaternion(comp);
            SpineShoulder = joints[JointType.SpineShoulder].Orientation.ToQuaternion(comp);
            ShoulderLeft  = joints[JointType.ShoulderLeft].Orientation.ToQuaternion(comp);
            ShoulderRight = joints[JointType.ShoulderRight].Orientation.ToQuaternion(comp);
            ElbowLeft     = joints[JointType.ElbowLeft].Orientation.ToQuaternion(comp);
            WristLeft     = joints[JointType.WristLeft].Orientation.ToQuaternion(comp);
            HandLeft      = joints[JointType.HandLeft].Orientation.ToQuaternion(comp);
            ElbowRight    = joints[JointType.ElbowRight].Orientation.ToQuaternion(comp);
            WristRight    = joints[JointType.WristRight].Orientation.ToQuaternion(comp);
            HandRight     = joints[JointType.HandRight].Orientation.ToQuaternion(comp);
            KneeLeft      = joints[JointType.KneeLeft].Orientation.ToQuaternion(comp);
            AnkleLeft     = joints[JointType.AnkleLeft].Orientation.ToQuaternion(comp);
            KneeRight     = joints[JointType.KneeRight].Orientation.ToQuaternion(comp);
            AnkleRight    = joints[JointType.AnkleRight].Orientation.ToQuaternion(comp);
        }

        // 関節の回転を計算する
        var q = transform.rotation;

        transform.rotation = Quaternion.identity;

        var comp2 = Quaternion.AngleAxis(90, new Vector3(0, 1, 0)) *
                    Quaternion.AngleAxis(-90, new Vector3(0, 0, 1));

        Spine1.transform.rotation = SpineMid * comp2;

        RightArm.transform.rotation     = ElbowRight * comp2;
        RightForeArm.transform.rotation = WristRight * comp2;
        RightHand.transform.rotation    = HandRight * comp2;

        LeftArm.transform.rotation     = ElbowLeft * comp2;
        LeftForeArm.transform.rotation = WristLeft * comp2;
        LeftHand.transform.rotation    = HandLeft * comp2;

        RightUpLeg.transform.rotation = KneeRight * comp2;
        RightLeg.transform.rotation   = AnkleRight * comp2;

        LeftUpLeg.transform.rotation = KneeLeft * Quaternion.AngleAxis(-90, new Vector3(0, 0, 1));
        LeftLeg.transform.rotation   = AnkleLeft * Quaternion.AngleAxis(-90, new Vector3(0, 0, 1));

        // モデルの回転を設定する
        transform.rotation = q;

        // モデルの位置を移動する
        var pos = body.Joints[JointType.SpineMid].Position;

        Ref.transform.position = new Vector3(-pos.X, pos.Y, -pos.Z);
    }
Exemple #54
0
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }
                //timeSpent += Time.deltaTime;  // Maybe it's not the best place to set this, 2 bodies can cause to double count. Maybe for now it just works
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
        timeSpent += Time.deltaTime;
    }
Exemple #55
0
    void Update()
    {
        int state = 0;

        if (BodySourceManager == null)
        {
            Debug.Log("Is BodyManager null" + BodySourceManager);

            return;
        }
        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                //RefreshBodyObject(body, _Bodies[body.TrackingId]);

                //Check Hand State if body is being Tracked
                state = CheckLeftHandState(body.HandLeftState) + (2 * CheckRightHandState(body.HandRightState));
                if (!levelHasGenerated)
                {
                    return;
                }
                switch (state)
                {
                case 0:
                    signalStart = false;
                    break;

                case 1:
                    //Left
                    if (prevState == 0)
                    {
                        platformRotate.TurnLeft();
                    }
                    Debug.Log("Left");
                    break;

                case 2:
                    //Right
                    Debug.Log("Right");
                    if (prevState == 0)
                    {
                        platformRotate.TurnRight();
                    }
                    break;

                case 3:
                    //Both
                    Debug.Log("Both");
                    if (prevState == 0)
                    {
                        //                     playerScript.flipjump = true;
                        platformRotate.Flip();
                    }
                    break;

                default:
                    break;
                }

                /*
                 * CheckRightHandState(body.HandRightState);
                 * CheckLeftHandState(body.HandLeftState);
                 *
                 * if(rightHandActive && leftHandActive)
                 * {
                 *  //flip
                 *  Debug.LogError("BOTH");
                 * }
                 */
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (_BodyManager == null)
        {
            Debug.Log("_BodyManager == null");
            return;
        }

        // Bodyデータを取得する
        var data = _BodyManager.GetData();

        if (data == null)
        {
            return;
        }

        // 最初に追跡している人を取得する
        var body = data.FirstOrDefault(b => b.IsTracked);

        if (body == null)
        {
            return;
        }


        //手の状態を判定していく、今回はグーで
        RLstate = IFState(body.HandRightState == HandState.Closed, body.HandLeftState == HandState.Closed);

        //RsとLs,つまり両手がグーならば
        if (RLstate)
        {
            //手のX座標の位置を比較
            HandRightBe_X = HandRightAf_X;
            HandLeftBe_X  = HandLeftAf_X;
            HandLeftAf_X  = body.Joints[JointType.HandLeft].Position.X;
            HandRightAf_X = body.Joints[JointType.HandRight].Position.X;
            //手のY座標の位置を比較
            HandRightBe_Y = HandRightAf_Y;
            HandLeftBe_Y  = HandLeftAf_Y;
            HandLeftAf_Y  = body.Joints[JointType.HandLeft].Position.Y;
            HandRightAf_Y = body.Joints[JointType.HandRight].Position.Y;
            double aaa = 0;
            aaa = HandLeftAf_Y - HandLeftBe_Y;
            if (aaa < 0)
            {
                aaa = 0 - aaa;
            }
            if ((aaa > 0.1))
            {
                _SerialR.Write("f");
            }
        }

        // 床の傾きを取得する
        var floorPlane = _BodyManager.FloorClipPlane;
        var comp       = Quaternion.FromToRotation(
             new Vector3(floorPlane.X, floorPlane.Y, floorPlane.Z), Vector3.up);

        // 関節の回転を取得する
        var joints = body.JointOrientations;

        Quaternion SpineBase;
        Quaternion SpineMid;
        Quaternion SpineShoulder;
        Quaternion ShoulderLeft;
        Quaternion ShoulderRight;
        Quaternion ElbowLeft;
        Quaternion WristLeft;
        Quaternion HandLeft;
        Quaternion ElbowRight;
        Quaternion WristRight;
        Quaternion HandRight;
        Quaternion KneeLeft;
        Quaternion AnkleLeft;
        Quaternion KneeRight;
        Quaternion AnkleRight;

        // 鏡
        if (IsMirror)
        {
            SpineBase     = joints[JointType.SpineBase].Orientation.ToMirror().ToQuaternion(comp);
            SpineMid      = joints[JointType.SpineMid].Orientation.ToMirror().ToQuaternion(comp);
            SpineShoulder = joints[JointType.SpineShoulder].Orientation.ToMirror().ToQuaternion(comp);
            ShoulderLeft  = joints[JointType.ShoulderRight].Orientation.ToMirror().ToQuaternion(comp);
            ShoulderRight = joints[JointType.ShoulderLeft].Orientation.ToMirror().ToQuaternion(comp);
            ElbowLeft     = joints[JointType.ElbowRight].Orientation.ToMirror().ToQuaternion(comp);
            WristLeft     = joints[JointType.WristRight].Orientation.ToMirror().ToQuaternion(comp);
            HandLeft      = joints[JointType.HandRight].Orientation.ToMirror().ToQuaternion(comp);
            ElbowRight    = joints[JointType.ElbowLeft].Orientation.ToMirror().ToQuaternion(comp);
            WristRight    = joints[JointType.WristLeft].Orientation.ToMirror().ToQuaternion(comp);
            HandRight     = joints[JointType.HandLeft].Orientation.ToMirror().ToQuaternion(comp);
            KneeLeft      = joints[JointType.KneeRight].Orientation.ToMirror().ToQuaternion(comp);
            AnkleLeft     = joints[JointType.AnkleRight].Orientation.ToMirror().ToQuaternion(comp);
            KneeRight     = joints[JointType.KneeLeft].Orientation.ToMirror().ToQuaternion(comp);
            AnkleRight    = joints[JointType.AnkleLeft].Orientation.ToMirror().ToQuaternion(comp);
        }
        // そのまま
        else
        {
            SpineBase     = joints[JointType.SpineBase].Orientation.ToQuaternion(comp);
            SpineMid      = joints[JointType.SpineMid].Orientation.ToQuaternion(comp);
            SpineShoulder = joints[JointType.SpineShoulder].Orientation.ToQuaternion(comp);
            ShoulderLeft  = joints[JointType.ShoulderLeft].Orientation.ToQuaternion(comp);
            ShoulderRight = joints[JointType.ShoulderRight].Orientation.ToQuaternion(comp);
            ElbowLeft     = joints[JointType.ElbowLeft].Orientation.ToQuaternion(comp);
            WristLeft     = joints[JointType.WristLeft].Orientation.ToQuaternion(comp);
            HandLeft      = joints[JointType.HandLeft].Orientation.ToQuaternion(comp);
            ElbowRight    = joints[JointType.ElbowRight].Orientation.ToQuaternion(comp);
            WristRight    = joints[JointType.WristRight].Orientation.ToQuaternion(comp);
            HandRight     = joints[JointType.HandRight].Orientation.ToQuaternion(comp);
            KneeLeft      = joints[JointType.KneeLeft].Orientation.ToQuaternion(comp);
            AnkleLeft     = joints[JointType.AnkleLeft].Orientation.ToQuaternion(comp);
            KneeRight     = joints[JointType.KneeRight].Orientation.ToQuaternion(comp);
            AnkleRight    = joints[JointType.AnkleRight].Orientation.ToQuaternion(comp);
        }

        // 関節の回転を計算する
        //調整するならここ


        var q = transform.rotation;

        transform.rotation = Quaternion.identity;

        var comp2 = Quaternion.AngleAxis(90, new Vector3(0, 1, 0)) *
                    Quaternion.AngleAxis(-90, new Vector3(0, 0, 1));

        Spine1.transform.rotation = SpineMid * comp2;

        RightArm.transform.rotation     = ElbowRight * comp2;
        RightForeArm.transform.rotation = WristRight * comp2;
        RightHand.transform.rotation    = HandRight * comp2;

        LeftArm.transform.rotation     = ElbowLeft * comp2;
        LeftForeArm.transform.rotation = WristLeft * comp2;
        LeftHand.transform.rotation    = HandLeft * comp2;

        RightUpLeg.transform.rotation = KneeRight * comp2;
        RightLeg.transform.rotation   = AnkleRight * comp2;

        LeftUpLeg.transform.rotation = KneeLeft * Quaternion.AngleAxis(-90, new Vector3(0, 0, 1));
        LeftLeg.transform.rotation   = AnkleLeft * Quaternion.AngleAxis(-90, new Vector3(0, 0, 1));

        // モデルの回転を設定する
        transform.rotation = q;

        // モデルの位置を移動する
        //var pos = body.Joints[JointType.SpineMid].Position;
        //Ref.transform.position = new Vector3(-pos.X, pos.Y, -pos.Z);
    }
    private void Update()
    {
        #region Get Kinect data
        Body[] data = mBodySourceManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }
            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }
        #endregion

        #region Delete Kinect Bodies
        List <ulong> knownIds = new List <ulong>(mBodies.Keys);
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                //Destroy body objet
                Destroy(mBodies[trackingId]);
                DeleteBody(trackingId);
                transforms.Remove(trackingId);
                //Remove from list
                mBodies.Remove(trackingId);
            }
        }
        #endregion

        #region Create Kinect bodies
        foreach (var body in data)
        {
            //if no body, skip
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                //if body isn't tracked, create body
                if (!mBodies.ContainsKey(body.TrackingId))
                {
                    mBodies[body.TrackingId]    = CreateBodyObject(body.TrackingId);
                    transforms[body.TrackingId] = mBodies[body.TrackingId].transform;
                    //Assign new body to a penguin gameobject
                    NewBody(body.TrackingId);
                }

                //Update positions
                UpdateBodyObject(body, mBodies[body.TrackingId]);
                //UpdateChildBodyObject(body, mBodies[body.TrackingId]);
            }
        }
        #endregion
    }
Exemple #58
0
    void Update()
    {
        moveInput_x = 0.0f;
        //通过键盘操作游戏.
        //获取水平方向,得到移动距离.
        moveInput_x = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
        //float moveInput_y = Input.GetAxis ("Vertical") * Time.deltaTime * moveSpeed;
        transform.position += new Vector3(moveInput_x, 0, 0);
        if (transform.position.x <= min || transform.position.x >= max)
        {
          float xPosition = Mathf.Clamp(transform.position.x, min, max); //板条移动的x坐标范围在-max和max之间.
        transform.position = new Vector3(xPosition, transform.position.y, transform.position.z);
        }

        if (BodySourceManager == null)
        {
            return;
        }
        //得到类BodySourceManager.
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }
        //得到实时的骨骼数据.
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
                //print (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach(ulong trackingId in knownIds)
        {
            if(!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {

                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                Kinect.Joint sourceJoint2 = body.Joints[Kinect.JointType.HandRight];

                Transform jointObj2 = _Bodies[body.TrackingId].transform;

                jointObj2.localPosition = GetVector3FromJoint(sourceJoint2);

                //print(jointObj2.localPosition.x);
                //print(x);
                if(jointObj2.localPosition.x-x-offset>jointObj2.localPosition.x){
                    moveInput_x = -0.5f * Time.deltaTime * moveSpeed;

                    transform.position += new Vector3(moveInput_x, 0, 0);
                }
                if(jointObj2.localPosition.x-x+offset<jointObj2.localPosition.x){
                    moveInput_x = 0.5f * Time.deltaTime * moveSpeed;

                    transform.position += new Vector3(moveInput_x, 0, 0);

                }
                if(jointObj2.localPosition.x-x==jointObj2.localPosition.x){
                    moveInput_x = 0;

                    transform.position += new Vector3(moveInput_x, 0, 0);
                }

                //控制板条移动范围.
                //float max = 19.0f;
                //float min = 1.5f;
                if (transform.position.x <= min || transform.position.x >= max)
                {
                  float xPosition = Mathf.Clamp(transform.position.x, min, max); //板条移动的x坐标范围在-max和max之间.
                transform.position = new Vector3(xPosition, transform.position.y, transform.position.z);
                }

                x = jointObj2.localPosition.x;
                moveInput_x = 0.0f;
            }
            moveInput_x = 0.0f;
        }
    }
Exemple #59
0
    void Update()
    {
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }
        //인물 한명만 잡아내기 의심
        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
        //의심
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }

            // Tracking for UI Component
            if (body.IsTracked)
            {
                KinectInputModule.instance.TrackBody(body);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                Destroy(_Puppets[trackingId]);
                _Bodies.Remove(trackingId);
                _Puppets.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    GameObject PuppetClone     = Instantiate <GameObject>(Characters[UnityEngine.Random.Range(0, Characters.Count)]);
                    GameObject UnityBodyObject = PuppetClone.GetComponentInChildren <IKControl>().CreateBodyObject(body);
                    PuppetClone.GetComponentInChildren <IKControl>().KinectBodyObject = body;
                    PuppetClone.GetComponentInChildren <IKControl>().UnityBodyObject  = UnityBodyObject;
                    _Puppets[body.TrackingId] = PuppetClone;
                    _Bodies[body.TrackingId]  = UnityBodyObject;
                }
            }
        }
    }