Update() public method

public Update ( float input, float deltaTime = 1f ) : float
input float
deltaTime float
return float
コード例 #1
0
    /** Updates the graphics objects. */
    protected virtual void Update()
    {
        if (leap_controller_ == null)
        {
            return;
        }

        UpdateRecorder();
        Frame frame = GetFrame();

        if (frame != null && !flag_initialized_)
        {
            InitializeFlags();
        }
        if (frame.Id != prev_graphics_id_)
        {
            UpdateHandModels(hand_graphics_, frame.Hands, leftGraphicsModel, rightGraphicsModel);
            prev_graphics_id_ = frame.Id;
        }

        //perFrameFixedUpdateOffset_ contains the maximum offset of this Update cycle
        smoothedFixedUpdateOffset_.Update(perFrameFixedUpdateOffset_, Time.deltaTime);
    }
コード例 #2
0
    void Update()
    {
        space.RecalculateTransformers();
        var transformer = space.transformer;

        List <int> pressedIds = new List <int>();

        float minDistance  = float.MaxValue;
        float averageDelta = 0;
        int   deltaCount   = 0;

        if (interactionEnabled)
        {
            foreach (var hand in provider.CurrentFrame.Hands)
            {
                Vector3 tip = hand.GetIndex().Bone(Leap.Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();

                Vector3 rectTip = transformer.InverseTransformPoint(tip);

                minDistance = Mathf.Min(minDistance, rectTip.z);

                if (rectTip.z > 0)
                {
                    float prevPos;
                    if (_idToPos.TryGetValue(hand.Id, out prevPos))
                    {
                        averageDelta += rectTip.x - prevPos;
                        deltaCount++;
                    }

                    pressedIds.Add(hand.Id);
                    _idToPos[hand.Id] = rectTip.x;
                }
            }
        }

        //If there are two hands and they are both farther than the threshold, do nothing
        if (provider.CurrentFrame.Hands.Count >= 2 && minDistance > -twoHandedZThreshold)
        {
            deltaCount = 0;
        }

        if (cards.Query().Any(c => c.isExpandedOrGrasped))
        {
            deltaCount = 0;
            _resetTween.Play(Direction.Forward);
        }
        else
        {
            _resetTween.Play(Direction.Backward);
        }

        var idsToRemove = _idToPos.Query().Select(t => t.Key).Where(id => !pressedIds.Contains(id)).ToList();

        foreach (var idToRemove in idsToRemove)
        {
            _idToPos.Remove(idToRemove);
        }

        if (deltaCount > 0)
        {
            averageDelta /= deltaCount;

            if (_needsAccum)
            {
                _accumPos += averageDelta;
                if (Mathf.Abs(_accumPos) > positionWarmup)
                {
                    _needsAccum = false;
                }
            }
            else
            {
                _position += averageDelta;
            }

            _smoothedVelocity.Update(averageDelta, Time.deltaTime);
            _velocity = _smoothedVelocity.value;
        }
        else
        {
            _accumPos   = 0;
            _needsAccum = true;

            _position += _velocity;
            _velocity *= damping;
        }

        float totalWidth = cards.Length * spacing;

        for (int i = 0; i < cards.Length; i++)
        {
            float cardOffset = i * spacing;

            float cardPosition = _position + cardOffset;

            while (cardPosition < 0)
            {
                cardPosition += totalWidth;
            }

            float loopedPosition = cardPosition % totalWidth - totalWidth * 0.5f;

            var curvedPos = transformer.TransformPoint(new Vector3(loopedPosition, 0, 0));
            var curvedRot = transformer.TransformRotation(new Vector3(loopedPosition, 0, 0), Quaternion.identity);

            cards[i].transform.localPosition = curvedPos;
            cards[i].transform.localRotation = curvedRot;
        }
    }
コード例 #3
0
 public void Reset(float toValue = 0F)
 {
     _value.reset = true;
     _value.Update(toValue);
 }
コード例 #4
0
    void UpdateHistory()
    {
        if (eyeAlignment.use)
        {
            // Revert the tracking space transform
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;
        }

        // Add current position and rotation to history
        // NOTE: history.Add can be retrieved as history[history.Count-1]
        if (history.Count >= 1)
        {
            lastFrame = history [history.Count - 1].leapTime;
        }
        else
        {
            lastFrame = 0;
        }
        long timeFrame = handController.GetLeapController().Now();

        switch (hasCameras)
        {
        case VRCameras.CENTER:
            history.Add(new TransformData()
            {
                leapTime = timeFrame,
                position = centerCamera.position,
                rotation = centerCamera.rotation
            });
            break;

        case VRCameras.LEFT_RIGHT:
            history.Add(new TransformData()
            {
                leapTime = timeFrame,
                position = Vector3.Lerp(leftCamera.position, rightCamera.position, 0.5f),
                rotation = Quaternion.Slerp(leftCamera.rotation, rightCamera.rotation, 0.5f)
            });
            break;

        default: //case VRCameras.NONE:
            history.Add(new TransformData()
            {
                leapTime = timeFrame,
                position = Vector3.zero,
                rotation = Quaternion.identity
            });
            break;
        }

        // Update smoothed averages of latency and frame rate
        long deltaFrame = timeFrame - lastFrame;
        long deltaImage = timeFrame - _latestImageTimestamp;

        if (deltaFrame + deltaImage < maxLatency)
        {
            frameLatency.Update((float)deltaFrame, Time.deltaTime);
            imageLatency.Update((float)deltaImage, Time.deltaTime);
            //Debug.Log ("Leap deltaTime = " + ((float)deltaTime / 1000f) + " ms");
            //Debug.Log ("Unity deltaTime = " + (Time.deltaTime * 1000f) + " ms");
            // RESULT: Leap & Unity deltaTime measurements are consistent within error tolerance.
            // Leap deltaTime will be used, since it references the same clock as images.
        }
        else
        {
            // Expect high latency during initial frames or after pausing
            //Debug.Log("Maximum latency exceeded: " + ((float)(deltaFrame + deltaImage) / 1000f) + " ms -> reset latency estimates");
            frameLatency.value = 0f;
            imageLatency.value = 0f;
            frameLatency.reset = true;
            imageLatency.reset = true;
        }

        // Reduce history length
        while (history.Count > 0 &&
               maxLatency < timeFrame - history [0].leapTime)
        {
            //Debug.Log ("Removing oldest from history.Count = " + history.Count);
            history.RemoveAt(0);
        }
    }