Esempio n. 1
0
    public override void Update()
    {
        base.Update();

        zones[0].distance = distance1;
        zones[1].distance = distance2;
        zones[2].distance = distance3;

        foreach (Zone z in zones)
        {
            z.transform.localScale = new Vector3(z.distance, 1, z.distance);
        }

        Zone newZone = getZone(bodyTransform.transform.position);

        if (zone != newZone)
        {
            zone = newZone;

            if (zone != null)
            {
                Debug.Log("Change zone " + zone.intimity);

                switch (zone.intimity)
                {
                case 0:
                    mood.sendMood(LampMoodController.RELAXED, .5f);
                    break;

                case 1:
                    mood.sendMood(LampMoodController.ALARMED, .8f);
                    break;

                case 2:
                    mood.sendMood(LampMoodController.ANGER, .8f);
                    break;
                }

                DataFeedback.sendZone(zone.intimity);
            }
            else
            {
                mood.sendMood(LampMoodController.RELAXED, .5f);
                DataFeedback.sendZone(-1);
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    override public void Update()
    {
        base.Update();

        if (isTouched != lastTouched)
        {
            DataFeedback.sendTouch(isTouched ? 1 : 0);
            if (isTouched)
            {
                timeAtLastTouched = Time.time;
            }
            else
            {
                if (Time.time < timeAtLastTouched + shortTouchTime)
                {
                    DataFeedback.sendShortTouch();
                }
            }
        }

        lastTouched = isTouched;
    }
Esempio n. 3
0
    public override void Update()
    {
        base.Update();

        processBodies();

        if (closestBody != null && !closestBody.IsTracked)
        {
            Debug.LogWarning("Force body null");
            closestBody = null;
        }

        closestBody = null;
        float dist = 20;

        foreach (KeyValuePair <ulong, Body> b in bodies)
        {
            float d = getLocalJointPos(b.Value, JointType.SpineBase).magnitude;
            if (d < dist)
            {
                closestBody = b.Value;
                dist        = d;
            }
        }

        bool  shouldSend      = false;
        float deltaUpdateTime = Time.time - lastUpdateTime;

        if (Time.time > lastUpdateTime + 1.0f / sendFreq)
        {
            lastUpdateTime = Time.time;
            shouldSend     = true;
        }

        if (closestBody != null)
        {
            headT.targetLocalPosition      = getLocalJointPos(closestBody, JointType.Head);
            bodyT.targetLocalPosition      = getLocalJointPos(closestBody, JointType.SpineBase);
            leftHandT.targetLocalPosition  = getLocalJointPos(closestBody, JointType.HandLeft);
            rightHandT.targetLocalPosition = getLocalJointPos(closestBody, JointType.HandRight);
            spineShoulder = getAbsoluteJointPos(closestBody, JointType.SpineShoulder);
            bodyTarget.transform.position = new Vector3(bodyT.transform.position.x, 0.01f, bodyT.transform.position.z);

            if (sendOSC && shouldSend)
            {
                sendFeedback();
            }

            if (bodyIsTracked && shouldSend)
            {
                bodySpeed  = Vector3.Distance(bodyT.transform.localPosition, lastBodyPos) / deltaUpdateTime;
                handSpeeds = Vector3.Distance(rightHandT.transform.localPosition, lastHandPos) / deltaUpdateTime;


                if (bodySpeed > bodySpeedThreshold)
                {
                    mood.sendMood(LampMoodController.DELIGHTED, .4f);
                }
                if (handSpeeds > handSpeedThreshold)
                {
                    mood.sendMood(LampMoodController.HAPPY, .4f);
                }
            }

            lastBodyPos = bodyT.transform.localPosition;
            lastHandPos = rightHandT.transform.localPosition;

            Vector2 groundBody   = new Vector2(bodyTarget.position.x, bodyTarget.position.z);
            Vector2 groundOrigin = new Vector2(origin.position.x + 1, origin.position.z);
            angle = Vector2.SignedAngle(groundOrigin, groundBody);
            DataFeedback.sendAngle(angle);

            bodyIsTracked = true;
        }
        else
        {
            spineShoulder = Vector3.Lerp(headT.transform.position, bodyT.transform.position, .3f);

            if (Input.GetMouseButton(0))
            {
                Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(r, out hit))
                {
                    bodyTarget.position = new Vector3(hit.point.x, bodyTarget.position.y, hit.point.z);
                    bodyTarget.LookAt(new Vector3(origin.position.x, bodyTarget.position.y, origin.position.z));

                    bodyT.targetLocalPosition      = transform.InverseTransformPoint(bodyTarget.TransformPoint(relTargetBody));
                    headT.targetLocalPosition      = transform.InverseTransformPoint(bodyTarget.TransformPoint(relTargetHead));
                    leftHandT.targetLocalPosition  = transform.InverseTransformPoint(bodyTarget.TransformPoint(relTargetLH));
                    rightHandT.targetLocalPosition = transform.InverseTransformPoint(bodyTarget.TransformPoint(relTargetRH));

                    if (sendOSC && bodyIsTracked && shouldSend)
                    {
                        sendFeedback();
                    }


                    Vector2 groundBody   = new Vector2(bodyTarget.position.x, bodyTarget.position.z);
                    Vector2 groundOrigin = new Vector2(origin.position.x + 1, origin.position.z);
                    angle = Vector2.SignedAngle(groundOrigin, groundBody);
                    DataFeedback.sendAngle(angle);
                }
            }

            if (bodyIsTracked && shouldSend)
            {
                bodySpeed  = Vector3.Distance(bodyT.transform.localPosition, lastBodyPos) / deltaUpdateTime;
                handSpeeds = Vector3.Distance(rightHandT.transform.localPosition, lastHandPos) / deltaUpdateTime;

                if (bodySpeed > bodySpeedThreshold)
                {
                    mood.sendMood(LampMoodController.DELIGHTED, .4f);
                }
                if (handSpeeds > handSpeedThreshold)
                {
                    mood.sendMood(LampMoodController.HAPPY, .4f);
                }
            }

            lastBodyPos = bodyT.transform.localPosition;
            lastHandPos = rightHandT.transform.localPosition;

            bodyIsTracked = simulateBodyIsTracked;
        }


        if (lastBodyIsTracked != bodyIsTracked)
        {
            lastBodyIsTracked = bodyIsTracked;
            if (bodyIsTracked)
            {
                mood.sendMood(LampMoodController.RELAXED, .5f);
            }
            else
            {
                mood.sendMood(LampMoodController.OFF, .7f);
            }
            bodyTarget.GetComponent <Renderer>().material.color = bodyIsTracked ? (simulateTouch ? Color.blue : Color.green) : Color.red;

            if (sendOSC)
            {
                sendTrackFeedback();
            }
            DataFeedback.sendTracked(bodyIsTracked);
        }

        if (!bodyIsTracked)
        {
            mood.sendMood(LampMoodController.OFF, .5f);
        }
        else
        {
            mood.sendMood(LampMoodController.RELAXED, .15f);
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            simulateTouch = !simulateTouch;
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            simulateBodyIsTracked = !simulateBodyIsTracked;
        }

        if (lastSimulateBody != simulateBodyIsTracked)
        {
            lastSimulateBody = simulateBodyIsTracked;
            bodyTarget.GetComponent <Renderer>().material.color = simulateBodyIsTracked ? (simulateTouch?Color.blue:Color.green) : Color.red;
        }

        if (lastSimulateTouch != simulateTouch)
        {
            lastSimulateTouch = simulateTouch;
            if (sendOSC)
            {
                sendTouchFeedback();
            }
            TouchHandler.instance.isTouched = simulateTouch;
            mood.sendMood(LampMoodController.DELIGHTED, .8f);
            bodyTarget.GetComponent <Renderer>().material.color = bodyIsTracked ? (simulateTouch ? Color.blue : Color.green) : Color.red;
        }

        foreach (LineRenderer r in lr)
        {
            r.SetPositions(new Vector3[] { spineShoulder, r.transform.position });
        }
    }
Esempio n. 4
0
 override public void Awake()
 {
     base.Awake();
     instance = this;
 }
Esempio n. 5
0
    void Update()
    {
        transform.localPosition = Vector3.SmoothDamp(transform.localPosition, targetLocalPosition, ref velocity, tracker.smoothing, 10, Time.deltaTime);

        Vector3 zOrigin = new Vector3(origin.position.x, 0, origin.position.z);

        relPos    = transform.position - zOrigin;
        groundPos = new Vector3(transform.position.x, 0, transform.position.z) - zOrigin;

        if (relPos != lastSendPos)
        {
            hasChangedSinceLastUpdate = true;
        }


        if (Time.time > lastSendUpdateTime + 1.0f / sendUpdateFPS)
        {
            float deltaUpdateTime = (Time.time - lastSendUpdateTime);
            float targetSpeed     = Vector3.Distance(relPos, lastRealUpdatePos) / deltaUpdateTime;
            if (speedSmooth == 0)
            {
                currentSpeed = targetSpeed;
            }
            else
            {
                currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref refSpeed, speedSmooth);
            }

            if (currentSpeed < idleSpeedThreshold)
            {
                idleTime += deltaUpdateTime;
            }
            else
            {
                idleTime = 0;
            }

            bool nowIsMoving = idleTime > 0;

            if (sendIdleTime)
            {
                DataFeedback.sendIdleTime(idleTime);
                if (isMoving != nowIsMoving)
                {
                    DataFeedback.sendIsMoving(nowIsMoving);
                }
            }

            isMoving = nowIsMoving;


            if (sendDistAndSpeed)
            {
                DataFeedback.sendDistance(jointName, groundPos.magnitude);
                DataFeedback.sendSpeed(jointName, currentSpeed);
            }

            lastRealUpdatePos  = new Vector3(relPos.x, relPos.y, relPos.z);
            lastSendUpdateTime = Time.time;
        }
    }