void Update()
    {
        if (_currentRecording != null)
        {
            if (Input.GetKeyDown(_endRecording))
            {
                EndRecording();
            }
        }
        else
        {
            if (Input.GetKeyDown(_startRecording))
            {
                StartRecording();
            }
        }

        if (playbackMode)
        {
            if (Input.GetKeyDown(KeyCode.N))
            {
                if (currentInstruction == AnnotationRecordings.Count)
                {
                    return;
                }

                currentInstruction++;
                next.Play();
                logger.AddKeyLogs("Next");
                StartCoroutine(PlaybackFunction(currentInstruction));
            }
            else if (Input.GetKeyDown(KeyCode.P))
            {
                if (currentInstruction == 0)
                {
                    return;
                }

                currentInstruction--;
                //Play the previous cue here
                previous.Play();
                logger.AddKeyLogs("Previous");
                StartCoroutine(PlaybackFunction(currentInstruction));
            }
            else if (Input.GetKeyDown(KeyCode.R))
            {
                logger.AddKeyLogs("Repeat");
                StartCoroutine(PlaybackFunction(currentInstruction));
            }
        }
    }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.N))
        {
            if (currentInstruction == instructionLocations.Count)
            {
                return;
            }

            currentInstruction++;
            next.Play();
            logger.AddKeyLogs("Next");
            UpdateAndPlay();
        }
        else if (Input.GetKeyDown(KeyCode.P))
        {
            if (currentInstruction == 0)
            {
                return;
            }

            currentInstruction--;
            previous.Play();
            logger.AddKeyLogs("Previous");
            UpdateAndPlay();
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            logger.AddKeyLogs("Repeat");
            UpdateAndPlay();
        }
        else if (Input.GetKeyDown(KeyCode.C))
        {
            completed.Play();
        }
    }
Esempio n. 3
0
    void Update()
    {
        if (_currentRecording != null)
        {
            _currentRecording.headPosition.Add(head.transform.position);
            _currentRecording.headRotation.Add(head.transform.rotation);
            _currentRecording.leftHandPosition.Add(leftHand.transform.position);
            _currentRecording.leftHandRotation.Add(leftHand.transform.rotation);
            _currentRecording.rightHandPosition.Add(rightHand.transform.position);
            _currentRecording.rightHandRotation.Add(rightHand.transform.rotation);
            _currentRecording.frameTimes.Add(Time.time - _beginTime);

            if (Input.GetKeyDown(_endRecording))
            {
                EndRecording();
            }
        }
        else
        {
            if (Input.GetKeyDown(_startRecording))
            {
                StartRecording();
            }
        }
        if (playbackMode)
        {
            ik_playback.SetActive(true);
            if (Input.GetKeyDown(KeyCode.N))
            {
                if (currentInstruction == recordings.Count)
                {
                    return;
                }

                currentInstruction++;
                next.Play();
                logger.AddKeyLogs("Next");
                StartCoroutine(PlaybackFunction(currentInstruction));
            }
            else if (Input.GetKeyDown(KeyCode.P))
            {
                if (currentInstruction == 0)
                {
                    return;
                }

                currentInstruction--;
                previous.Play();
                logger.AddKeyLogs("Previous");
                StartCoroutine(PlaybackFunction(currentInstruction));
            }
            else if (Input.GetKeyDown(KeyCode.R))
            {
                logger.AddKeyLogs("Repeat");
                StartCoroutine(PlaybackFunction(currentInstruction));
            }
        }
        else
        {
            ik_recording.SetActive(true);
        }
    }
Esempio n. 4
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.N))
            {
                currentInstruction++;
                isPlaying = false; Play = true;
                logger.AddKeyLogs("Next");
                if (this.IsLeft)
                {
                    next.Play();
                }
            }
            else if (Input.GetKeyDown(KeyCode.P))
            {
                currentInstruction--;
                isPlaying = false; Play = true;
                logger.AddKeyLogs("Previous");
                if (this.IsLeft)
                {
                    previous.Play();
                }
            }
            else if (Input.GetKeyDown(KeyCode.R))
            {
                isPlaying = false; Play = true;
                logger.AddKeyLogs("Repeat");
            }


            if (_currentRecording != null)
            {
                GestureResult frame = IsLeft ? GestureProvider.LeftHand : GestureProvider.RightHand;
                if (frame != null)
                {
                    _currentRecording.Handframes.Add(new HandFrame(frame.isLeft, frame.points, frame.gesture, frame.position, frame.rotation));
                    _currentRecording.frameTimes.Add(Time.time - _beginTime);
                }

                if (Input.GetKeyDown(_endRecording))
                {
                    EndRecording();
                }
            }
            else
            {
                if (Input.GetKeyDown(_startRecording))
                {
                    StartRecording();
                }
            }

            if (!GestureProvider.UpdatedInThisFrame && !Play)
            {
                return;
            }

            GestureResult result = null;

            if (Play)
            {
                if (!isPlaying)
                {
                    _playBackBeginTime = Time.time;
                    playbackFrame      = 0;
                    isPlaying          = true;
                    //playbackFrame = GetSeekFrame();
                }
                if (playbackFrame >= HandRecordings[currentInstruction].frameTimes.Count)
                {
                    isPlaying = false;
                    Play      = false;
                    if (this.IsLeft)
                    {
                        completed.Play();
                    }
                    return;
                }
                if (isPlaying && (Time.time - _playBackBeginTime) < HandRecordings[currentInstruction].frameTimes[playbackFrame])
                {
                    return;
                }
                else
                {
                    result = HandRecordings[currentInstruction].GRFrames[playbackFrame];
                    playbackFrame++;
                }

                /* if (HandRecordings[currentInstruction].frameTimes[playbackFrame] >= HandRecordings[currentInstruction].finishAtSeconds)//Limit playback to certain seconds
                 * {
                 *   Hand.SetActive(false);
                 *   return;
                 * }*/
            }
            else
            {
                result = IsLeft ? GestureProvider.LeftHand : GestureProvider.RightHand;
            }
            if (result == null)
            {
                Hand.SetActive(false);
                return;
            }

            if (DisableLiveHands && !Play)
            {
                return;
            }

            Hand.SetActive(true);
            for (int i = 0; i < 5; i++)
            {
                int   startIndex         = i * 4 + 1;
                float squareLengthRoot   = (result.points[startIndex] - result.points[0]).sqrMagnitude;
                float squareLengthFirst  = (result.points[startIndex + 1] - result.points[startIndex]).sqrMagnitude;
                float squareLengthSecond = (result.points[startIndex + 2] - result.points[startIndex + 1]).sqrMagnitude;
                float squareLengthThird  = (result.points[startIndex + 3] - result.points[startIndex + 2]).sqrMagnitude;
                if (squareLengthRoot < epsilon || squareLengthFirst < epsilon || squareLengthSecond < epsilon ||
                    squareLengthThird < epsilon)
                {
                    return;
                }
                for (int j = i + 1; j < 5; j++)
                {
                    int nextStartIndex = j * 4 + 1;
                    if ((result.points[nextStartIndex] - result.points[startIndex]).sqrMagnitude == 0)
                    {
                        return;
                    }
                }
            }
            Vector3 _Wrist  = result.points[0];
            Vector3 _Index  = result.points[5];
            Vector3 _Middle = result.points[9];
            Vector3 _ring   = result.points[13];

            transform.position = _Wrist;
            Vector3 _MidDir   = _Middle - _Wrist;
            Vector3 _ringDir  = _ring - _Wrist;
            Vector3 _IndexDir = _Index - _Wrist;

            Vector3 _PalmDir = Vector3.Cross(_IndexDir, _ringDir);

            Vector3 _UpDir = Vector3.Cross(_ringDir, _PalmDir);

            _MidDir            = Quaternion.AngleAxis(4.7f, _PalmDir) * _MidDir;
            transform.rotation = Quaternion.LookRotation(_MidDir, _UpDir);

            setFingerPos(result);
            setAxis(result);
            adjustFingerRootPos(result);
            for (int i = 0; i < 5; ++i)
            {
                SetFingerAngle(result, i);
            }
            for (int i = 0; i < 5; i++)
            {
                int startIndex = i * 4 + 1;
                Nodes[startIndex].position = Nodes[0].position + (Nodes[startIndex].position - Nodes[0].position).normalized *
                                             idealFingerLength[i * 3];
                Nodes[startIndex + 1].position = Nodes[startIndex].position + (Nodes[startIndex + 1].position -
                                                                               Nodes[startIndex].position).normalized * idealFingerLength[i * 3 + 1];
                Nodes[startIndex + 2].position = Nodes[startIndex + 1].position + (Nodes[startIndex + 2].position - Nodes[startIndex +
                                                                                                                          1].position).normalized * idealFingerLength[i * 3 + 2];
            }
        }