Example #1
0
            protected override float getRawValue()
            {
                float raw = 1.0f - _infoCalculator._discardCloseFingertipCurl;

                DebugGraph.Log("Release Pose Raw", raw);
                return(raw);
            }
Example #2
0
    public static void ShowWindow()
    {
        DebugGraphWindow window = GetWindow <DebugGraphWindow>("Debug Graph");

        DebugGraph.SetWindow(window);
        window.previousWindowSize = new Vector2(window.position.width, window.position.height);
    }
Example #3
0
    public static float getGrabHeuristic(Hand hand, GameObject obj)
    {
        float grabProbability = 0.0f;

        //If palm is facing away from the object, no chance of grabbing
        Vector3 palmNormal = handController.transform.TransformDirection(hand.PalmNormal.ToUnity());
        Vector3 palmPos    = handController.transform.TransformPoint(hand.PalmPosition.ToUnityScaled());

        if (Vector3.Dot(palmNormal, obj.transform.position - palmPos) < 0)
        {
            return(0);
        }

        float proximityFactor = 0.0f;

        foreach (Finger finger in hand.Fingers)
        {
            Vector3 point    = handController.transform.TransformPoint(finger.JointPosition(Leap.Finger.FingerJoint.JOINT_TIP).ToUnityScaled());
            Vector3 pointOn  = ColliderUtil.closestPointOnSurfaces(obj, point);
            float   distance = Vector3.Distance(point, pointOn);
            if (ColliderUtil.isInsideColliders(obj, point))
            {
                distance = 0.0f;
            }

            //if any finger is <releaseRadius> meters away, negative infinity, no way that hand is close enough
            float thresh = Mathf.Clamp01(1.0f - distance / 0.15f);
            proximityFactor += 2.0f - 1.0f / thresh;
        }

        proximityFactor /= hand.Fingers.Count;
        //Debug.Log(proximityFactor);

        grabProbability += proximityFactor;

        //The more the hand is opening, the more grabbable
        grabProbability += getHandClosingSpeed(hand) * 10.0f;

        //If the hand is mostly open, the probability of a grab goes down
        grabProbability -= Mathf.Pow(1.0f - getHandClosedPercent(hand), 4.0f);

        if (hand.PalmVelocity.ToUnityScaled().sqrMagnitude > 0.09f)
        {
            grabProbability = 0.7f;
        }

        grabProbability = 0.7f + (grabProbability - 0.7f) / (hand.PalmVelocity.ToUnityScaled().sqrMagnitude * 3.0f + 1);

        grabProbability = 0.7f + (grabProbability - 0.7f) / (getHandRotationAmount(hand) * 1 + 1.0f);

        if (grabProbability > 0 && grabProbability < 10.0f)
        {
            DebugGraph.Log("Grabbing", grabProbability, grabProbability > 0.7f ? Color.green : Color.red);
        }

        return(grabProbability);
    }
 private void SquiggleTest(float step = 0.1f)
 {
     for (float t = 0; t <= 1f; t += step)
     {
         var lerp = (t - (t > 0.5 ? 1 : 0));     //Parabola
         lerp = 4 * lerp * lerp;
         DebugGraph.Log("Scale Function", lerp, Color.red, t);
         DebugGraph.Log("Scale Complete", GetScale(t), Color.blue);
     }
 }
 protected override IGraphConsole LoadGraph()
 {
     foreach (IGraphConsole console in DebugGraph.GetGraphEnumerator())
     {
         if (console.Name == GraphName)
         {
             return(console);
         }
     }
     return(null);
 }
 public bool tryReleaseObject()
 {
     if (GrabbingInfo.shouldRelease(InteractionController.grabbingInfoSettings, _leapHand, _grabbedObject))
     {
         _lastTimeReleased = Time.time;
         _isGrabbingObject = false;
         disconnectAllBasisPoints();
         disconnectAllFingerPoints();
         DebugGraph.Write("Released");
         return(true);
     }
     return(false);
 }
        protected override IGraphConsole LoadGraph()
        {
            IEnumerator <IGraphConsole> graphs = DebugGraph.GetGraphEnumerator();

            while (graphs.MoveNext())
            {
                if (graphs.Current.Name == GraphName)
                {
                    return(graphs.Current);
                }
            }
            return(null);
        }
        public void UpdateOutgoing(bool host = false)
        {
            _log.Debug($"UpdateOutgoing() - Frame: {Time.frameCount} Seq: {_seq}\n");

            // flow control
            if (_transmissionRecords.Count >= 32)
            {
                _log.Debug("Skipped sending outgoing data. Max in un-ACKed transmissions reached");
                return;
            }

            // fill in our reusable packet struct with the data for this sequence
            _header.Seq     = _seq;
            _header.AckFlag = _remoteSeqAckFlag;

            _log.Debug($"Generated Packet Seq: {_header.Seq}");
            _log.Debug($"RemoteAckFlag: {_remoteSeqAckFlag}");

            // Create a transmission record for the packet
            PacketTransmissionRecord record = new PacketTransmissionRecord
            {
                Seq     = _header.Seq,
                AckFlag = _remoteSeqAckFlag
            };

            // Write the packet header to the stream
            _header.Serialize(_netWriter);

            // let each stream manager write until the packet is full
            foreach (IPacketStreamWriter streamWriter in _streamWriters)
            {
                streamWriter.WriteToPacketStream(_netWriter);
            }

            // create output events
            _transmissionRecords.Enqueue(record);

            _packetSender.Send(_netWriter.Data, 0, _netWriter.Length);

            _log.Debug($"Sent Bytes: {_netWriter.Length}");

#if SQUIGGLE
            DebugGraph.Log("Sent Bytes", _netWriter.Length, Color.green);
#endif
            _netWriter.Reset();

            // Only increment our seq on successful send
            // IE if waiting for acks then seq doesn't increase
            _seq++;
        }
 public bool tryGrabObject()
 {
     foreach (GameObject closeObject in _closeObjects)
     {
         InteractionObject interactionObject = InteractionObject.getInteractionObject(closeObject);
         if (GrabbingInfo.shouldGrab(InteractionController.grabbingInfoSettings, _leapHand, interactionObject))
         {
             _isGrabbingObject = true;
             _grabbedObject    = interactionObject;
             _cachedRigidbody  = _grabbedObject.rigidbody;
             connectAllFingerPoints(_grabbedObject, InteractionPointConnectMethod.SURFACE);
             connectBasisPoints(_grabbedObject);
             DebugGraph.Write("Grabbed");
             return(true);
         }
     }
     return(false);
 }
Example #10
0
        public void ensureUpdated(Hand newHand, bool isCurrentlyGrabbing)
        {
            if (newHand == _hand)
            {
                return;
            }
            _isCurrentlyGrabbing = isCurrentlyGrabbing;
            deltaTime            = Time.fixedDeltaTime;

            _hand = newHand;

            calculatePalmDistanceToSurface();
            calculateFingerCurl();
            calculateFingertipDistance();

            float grabMax = 0.0f, releaseMax = 0.0f;
            float grabSum = 0.0f, releaseSum = 0.0f;

            foreach (IValueCalculator vc in _valueCalculators)
            {
                vc.updateValue();
                float value = vc.getValue();

                if (value > 0)
                {
                    grabSum += value;
                    if (value > grabMax)
                    {
                        grabMax = value;
                    }
                }
                else
                {
                    releaseSum += -value;
                    if (-value > releaseMax)
                    {
                        releaseMax = -value;
                    }
                }

                if (vc.getValueType() == ValueType.GRAB)
                {
                    DebugGraph.Log(vc.ToString(), value, value >= 0.0f ? Color.green : Color.red);
                }
                else
                {
                    DebugGraph.Log(vc.ToString(), -value, -value >= 0.0f ? Color.red : Color.green);
                }
            }

            float grabWeighted    = grabMax * grabSum / (grabSum + releaseSum);
            float releaseWeighted = releaseMax * releaseSum / (grabSum + releaseSum);

            _grabValue = Mathf.Clamp01(grabWeighted - releaseWeighted);

            Color logColor = Color.blue;

            if (_grabValue > _settings.releaseGrabThreshold.y)
            {
                logColor = Color.green;
            }
            if (_grabValue < _settings.releaseGrabThreshold.x)
            {
                logColor = Color.red;
            }

            DebugGraph.Log("GrabValue", _grabValue, logColor);

            _lastUpdatedFrameId = _hand.Frame.Id;
        }
Example #11
0
 protected override float getRawValue()
 {
     DebugGraph.Log("Palm To Surface Distance", _infoCalculator._palmToSurfaceDistance);
     return(_infoCalculator._palmToSurfaceDistance / _settings.maxPalmDistance);
 }
Example #12
0
    void Update()
    {
        BooleanValue = Mathf.Repeat(Time.time, 1.0f) > 0.5f;

        FloatValue = Mathf.PingPong(Time.realtimeSinceStartup, 1.0f);

        IntValue = Mathf.FloorToInt(FloatValue * 10.0f);

        Vector2Value = GetComponent <Rigidbody2D>().velocity;

        Vector3Value = transform.position;

        ColorValue = Color.Lerp(DebugGraph.DefaultBlue, new Color(1.0f, 0.75f, 0.25f), Mathf.PingPong(Time.realtimeSinceStartup, 1.0f));

        Color32Value = ColorValue;

        StringValue = "Hello World! The Current Frame Number Is: " + Time.frameCount;

        EnumValue = (ExampleEnum)(Time.frameCount % 3);

        float sin = Mathf.Sin(Mathf.Repeat(Time.time, 6.28f));
        float cos = Mathf.Cos(Mathf.Repeat(Time.time, 6.28f));

        DebugGraph.Log("Color Gradient", ColorValue);

        DebugGraph.Write("String", StringValue);

        DebugGraph.Log("Vector3", Input.mousePosition);

        DebugGraph.Log("Vector4", new Vector4(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)));

        transform.Rotate(Vector3.up, Time.deltaTime * 90.0f);
        DebugGraph.Log("Quaternion", transform.rotation);

        DebugGraph.Log("Rect", new Rect(0, 0, 100, 100));

        DebugGraph.Draw(new Vector2(sin * Time.time, cos * Time.time));

        DebugGraph.MultiLog("Related Variables", DebugGraph.DefaultRed, sin, "Sin");
        DebugGraph.MultiLog("Related Variables", DebugGraph.DefaultGreen, cos, "Cos");

        DebugGraph.Log(FloatValue); //Anonymous Float

        //Anonymous Multi Float
        DebugGraph.MultiLog(cos * 1.1f);
        DebugGraph.MultiLog(cos * 1.2f);
        DebugGraph.MultiLog(cos * 1.3f, "C"); //with Value names
        DebugGraph.MultiLog(cos * 1.4f, "D");
        DebugGraph.MultiLog(cos * 1.5f, "E");

        //Anonymous Values in a Loop
        for (int i = 0; i < 10; i++)
        {
            DebugGraph.MultiLog(DebugGraph.GetUniqueColor(i), sin * (1.0f + i * 0.1f), i.ToString());
        }

        DebugGraph.Log(Mathf.FloorToInt(sin * 10));                                        //Anonymous Integer

        DebugGraph.Log(Mathf.RoundToInt(Mathf.PerlinNoise(Time.time, Time.time) * 1) > 0); //Anonymous Boolean

        //Anonymous Multi Enum
        DebugGraph.MultiLog(EnumValue);
        DebugGraph.MultiLog((ExampleEnum2)(Mathf.PerlinNoise(Time.time, Time.time) * 3));
    }
        public void UpdateIncoming(bool host = false)
        {
            if (_dataReceivedEvents.Count == 0)
            {
                return;
            }

            _log.Debug($"UPDATE INCOMING - Frame: {Time.frameCount} Seq: {_seq}\n");

            DebugGraph.Log("Packets Received", _dataReceivedEvents.Count);

            try
            {
                // Process data received events
                _log.Debug($"Received {_dataReceivedEvents.Count} packets");
                for (int i = 0; i < _dataReceivedEvents.Count; i++)
                {
                    // Get data reader from evt which contains the binary data for the packet
                    NetPacketReader reader = _dataReceivedEvents[i].DataReader;

                    // Deserialize packet (including header)
                    _header.Deserialize(reader);

                    _log.Debug($"Received Packet Sequence: {_header.Seq}");
                    _log.Debug($"Packet AckFlag: {_header.AckFlag}");
                    _log.Debug($"Local AckedFlag- before: {_remoteSeqAckFlag}");

                    if (_remoteSeqAckFlag.SeqCount == 0)
                    {
                        // No sequences in the flag so just initialize it with this sequence being ACKed
                        _remoteSeqAckFlag.InitWithAckedSequence(_header.Seq);
                    }
                    else if (SequenceHelper.SeqIsAheadButInsideWindow32(_remoteSeqAckFlag.EndSeq, _header.Seq))
                    {
                        _log.Debug($"Received sequence {_header.Seq} is ahead of the last sequence in our ack flag: {_remoteSeqAckFlag.EndSeq}");

                        // The seq is ahead of the range of our flag (ie a new seq) but we want to NACK any that
                        // sequences that are in between the last sequence we ACKed, and this sequence we are now receiving
                        // since they must have been dropped (or delivered out of order)
                        while (_remoteSeqAckFlag.EndSeq != (byte)(_header.Seq - 1))
                        {
                            _remoteSeqAckFlag.NackNextSequence();
                            _log.Debug($"NACKed sequence {_remoteSeqAckFlag.EndSeq}");
                        }

                        // Ack this sequence in our flag
                        _remoteSeqAckFlag.AckNextSequence();
                    }
                    else
                    {
                        // This packet was delivered out of order
                        // or is outside the expected window so don't process it further
                        _log.Debug($"{_header.Seq} - SKIPPED UNEXPECTED");
                        continue;
                    }

                    // Generate notifications based on ACKs received from the remote stream
                    if (_header.AckFlag.SeqCount > 0)
                    {
                        if (_seqLastNotified == -1)
                        {
                            _log.Debug("Initializing SeqLastNotified");
                            // This is the start of us notifying packets.. if any packets were sent but aren't
                            // included in this ack flag then they must have been dropped
                            while (_transmissionRecords.Peek().Seq != _header.AckFlag.StartSeq)
                            {
                                PacketTransmissionRecord record = _transmissionRecords.Dequeue();
                                _seqLastNotified = record.Seq;
                                _transmissionNotifications.Add(false);
                                _log.Debug($"Seq {record.Seq} was dropped");
                            }
                            // Notify based on sequences in flag
                            GenerateNotificationsFromAckFlagAndUpdateSeqLastNotified(_header.AckFlag);
                        }
                        else if (SequenceHelper.SeqIsAheadButInsideWindow32((byte)_seqLastNotified, _header.AckFlag.StartSeq))
                        {
                            // NACK all packets up until the start of this ACK flag because they must have been lost or delivered out of order
                            while (_seqLastNotified != (byte)(_header.AckFlag.StartSeq - 1))
                            {
                                _transmissionRecords.Dequeue();
                                _transmissionNotifications.Add(false);
                                _seqLastNotified = ++_seqLastNotified <= byte.MaxValue ? _seqLastNotified : 0;
                                _log.Debug($"Sequence: {_seqLastNotified} was dropped");
                            }
                            // Notify based on sequences in flag
                            GenerateNotificationsFromAckFlagAndUpdateSeqLastNotified(_header.AckFlag);
                        }
                        else if (SequenceHelper.SeqIsInsideRangeInclusive(_header.AckFlag.StartSeq, _header.AckFlag.EndSeq, (byte)_seqLastNotified))
                        {
                            _log.Debug($"{_seqLastNotified} is inside ack flag range");
                            // Drop sequences we have already notified
                            _header.AckFlag.DropStartSequenceUntilItEquals((byte)(_seqLastNotified + 1));

                            // Notify based on sequences remaining in flag
                            GenerateNotificationsFromAckFlagAndUpdateSeqLastNotified(_header.AckFlag);
                        }
                    }

                    _log.Debug("Finished generating notifications");

                    // Give stream to each system to processors in the order they were added
                    foreach (IPacketStreamReader streamProcessor in _streamProcessors)
                    {
                        streamProcessor.ReadPacketStream(reader);
                    }
                }
                _log.Debug($"SeqLastNotified - After: {_seqLastNotified}");
                _log.Debug($"Generated {_transmissionNotifications.Count} transmission notifications");
                _log.Debug($"There are now { _transmissionRecords.Count} remaining transmission records in the queue");

                // Give notifications to any stream writers that are interested in whether or not their transmissions made it
                foreach (IPacketTransmissionNotificationReceiver notificationReceiver in _notificationReceivers)
                {
                    notificationReceiver.ReceiveNotifications(_transmissionNotifications);
                }
            }
            catch (Exception e)
            {
                _log.Debug(e.Message);
                throw;
            }
            finally
            {
                _dataReceivedEvents.Clear();
                _transmissionNotifications.Clear();
            }
        }