internal EdgeObject MakeConnection(NodeObject first, NodeObject second)
        {
            Debug.Log("Making connection from " + first + " to " + second);
            GameObject connection = GameObject.CreatePrimitive(PrimitiveType.Cube);

            DestroyColliders(connection);
            MeshRenderer renderer = connection.GetComponent <MeshRenderer>();

            renderer.material.color         = Color.gray;
            connection.transform.localScale = Vector3.one * edgeScale;  // make very small at first
            EdgeObject edge = connection.AddComponent <EdgeObject>();

            edge.floatingSpheres = this;
            edge.startNode       = first;
            edge.endNode         = second;
            edge.scale           = edgeScale;
            edge.UpdateConnection();
            first.AddEdge(edge);
            second.AddEdge(edge);
            if (edges != null)
            {
                connection.transform.parent = edges.transform;
            }
            return(edge);
        }
Beispiel #2
0
        internal EdgeObject FindEdge(NodeObject other)
        {
            EdgeObject edge = FindEdge(other, this, incoming);

            if (edge == null)
            {
                edge = FindEdge(this, other, outgoing);
            }
            return(edge);
        }
Beispiel #3
0
 private EdgeObject FindEdge(NodeObject first, NodeObject second, HashSet <EdgeObject> edges)
 {
     HashSet <EdgeObject> .Enumerator edge = edges.GetEnumerator();
     while (edge.MoveNext())
     {
         EdgeObject current = edge.Current;
         if (current.endNode == second && current.startNode == first)
         {
             return(current);
         }
     }
     return(null);
 }
Beispiel #4
0
        internal void RemoveEdge(EdgeObject edge)
        {
            EdgeObject toRemove = null;

            if (edge.startNode == this)
            {
                toRemove = FindEdge(edge.startNode, edge.endNode, outgoing);
                outgoing.Remove(toRemove);
            }
            else if (edge.endNode == this)
            {
                toRemove = FindEdge(edge.endNode, edge.startNode, incoming);
                incoming.Remove(toRemove);
            }
            if (toRemove == null)
            {
                Debug.Log("Invalid edge: " + edge);
            }
        }
Beispiel #5
0
 private void Detach(HashSet <EdgeObject> edges)
 {
     EdgeObject[] toDestroy = new EdgeObject[edges.Count];
     edges.CopyTo(toDestroy);
     edges.Clear();
     foreach (EdgeObject edge in toDestroy)
     {
         if (edge.startNode != null)
         {
             edge.startNode.RemoveEdge(edge);
         }
         if (edge.endNode != null)
         {
             edge.endNode.RemoveEdge(edge);
         }
         edge.startNode = null;
         edge.endNode   = null;
         Destroy(edge.gameObject);
     }
 }
Beispiel #6
0
 internal void AddEdge(EdgeObject edge)
 {
     if (edge.startNode == this)
     {
         if (FindEdge(edge.startNode, edge.endNode, outgoing) == null)
         {
             outgoing.Add(edge);
         }
     }
     else if (edge.endNode == this)
     {
         if (FindEdge(edge.endNode, edge.startNode, incoming) == null)
         {
             incoming.Add(edge);
         }
     }
     else
     {
         Debug.Log("Invalid edge: " + edge);
     }
 }
Beispiel #7
0
        private void TriggerCreate()
        {
            float dx     = hand.transform.position.x - head.transform.position.x;
            float dz     = hand.transform.position.z - head.transform.position.z;
            float x      = head.transform.position.x + 2 * dx;
            float z      = head.transform.position.z + 2 * dz;
            float height = 1;

            if (elementToTrack != null)
            {
                height = Math.Max(height, elementToTrack.position.y);
                if (this.animToTrigger != null)
                {
                    double angleToHand    = EdgeObject.Azimuth(head.transform, hand.transform);
                    double angleToElement = EdgeObject.Azimuth(head.transform, elementToTrack.transform);
                    Debug.Log("AngleToHand: " + angleToHand);
                    Debug.Log("AngleToElement: " + angleToElement);
                    Debug.Log("Difference between hand and element: " + Math.Abs(angleToElement - angleToHand));
                    if (Math.Abs(angleToElement - angleToHand) < 0.1)
                    {
                        this.animToTrigger.SetTrigger(this.closeParameter);
                        this.animToTrigger.ResetTrigger(this.farParameter);
                    }
                    else
                    {
                        this.animToTrigger.ResetTrigger(this.closeParameter);
                        this.animToTrigger.SetTrigger(this.farParameter);
                    }
                }
                else
                {
                    Debug.LogError("Could not find animation component on " + elementToTrack);
                }
            }
            height = Math.Max(height, Math.Max(head.transform.position.y, hand.transform.position.y));
            floatingSpheres.MakeOne(x, height, z);
        }
Beispiel #8
0
 public void FixedUpdate()
 {
     if (hand != null)
     {
         if (hand.Inputs[NVRButtons.ApplicationMenu].PressDown)
         {
             appMenuWasPressed = true;
         }
         if (hand.Inputs[NVRButtons.ApplicationMenu].PressUp)
         {
             if (appMenuWasPressed)
             {
                 MenuPressed();
             }
             appMenuWasPressed = false;
         }
         if (hand.UseButtonDown)
         {
             //if(!floatingSpheres.canvasInput.OnCanvas)
             {
                 triggerWasPressed = true;
             }
         }
         if (hand.UseButtonUp)
         {
             if (triggerWasPressed)// && !floatingSpheres.canvasInput.OnCanvas)
             {
                 TriggerPressed();
             }
             triggerWasPressed = false;
         }
         if (hand.IsInteracting)
         {
             this.twoHandInteraction = false;
             if (otherHand != null)
             {
                 if (otherHand.IsInteracting)
                 {
                     this.twoHandInteraction = true;
                     if (otherHand.CurrentlyInteracting == hand.CurrentlyInteracting)
                     {
                         // NewtonVR already filters this out, so we would need more changes to get to this point
                         Debug.Log("Two hands interacting with same object: " + hand.CurrentlyInteracting);
                     }
                     else
                     {
                         //FloatingSpheres.DebugSphere(hand.CurrentlyInteracting, "Interacting with");
                         NodeObject first  = hand.CurrentlyInteracting.GetComponent <NodeObject>();
                         NodeObject second = otherHand.CurrentlyInteracting.GetComponent <NodeObject>();
                         if (first == null)
                         {
                             Debug.Log("Hand is interacting with something that is not a NodeObject: " + hand.CurrentlyInteracting);
                         }
                         else if (second == null)
                         {
                             Debug.Log("Other hand is interacting with something that is not a NodeObject: " + hand.CurrentlyInteracting);
                         }
                         else
                         {
                             EdgeObject edge = first.FindEdge(second);
                             if (edge == null)
                             {
                                 Debug.Log("No edge exists - making one");
                                 edge = floatingSpheres.MakeConnection(first, second);
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         Debug.LogError("No hand defined for " + this);
     }
     //Debug.Log("FixedUpdate: " + this);
 }