Beispiel #1
0
    // Identify pulled object using view of hand
    void Update()
    {
        if (view == null ||
            cast == null ||
            hold == null)
        {
            return;
        }

        if (pulled != null)
        {
            return;
        }

        int        layerMask = 1 << layerSelect;                  //Select a single layer
        RaycastHit hit;
        Ray        ray = new Ray(view.position, cast.position - view.position);

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
        {
            Debug.DrawRay(ray.origin, hit.point - ray.origin, Color.red);
            PullToHold intersect = hit.collider.gameObject.GetComponent <PullToHold> ();
            if (intersect != null)
            {
                Acquire(intersect);
            }
        }
        else
        {
            Debug.DrawRay(ray.origin, ray.direction * 100f, Color.white);
        }
    }
Beispiel #2
0
    void Acquire(PullToHold intersect)
    {
        if (intersect.holder != null)
        {
            intersect.holder.enabled = false;
        }

        if (Hold == null)
        {
            throw new System.Exception("Attempting to aquire hold without holder.");
        }

        pulled = intersect;

        if (intersect == null)
        {
            return;
        }

        //NOTE: hold reference is implicitly made null if hold is destroyed
        pulled.holder           = this;
        Hold.transform.rotation = intersect.gameObject.transform.rotation;

        if (intersect.asterismKey != -1 && intersect.asterismKey < Asterisms.AsterismParser.AsterismData.Length)
        {
            float scaleFactor = Asterisms.AsterismParser.AsterismData[intersect.asterismKey].scaleFactor;
            Hold.transform.localScale = new Vector3(0.007f, 0.007f, 0.007f) * scaleFactor;
        }
    }
Beispiel #3
0
 void Release()
 {
     if (pulled == null)
                     return;
             //NOTE: pulled reference is implicitly made null if pulled is destroyed
             pulled.holder = null;
             pulled = null;
 }
Beispiel #4
0
 void Release()
 {
     if (pulled == null)
     {
         return;
     }
     //NOTE: pulled reference is implicitly made null if pulled is destroyed
     pulled.holder = null;
     pulled        = null;
 }
Beispiel #5
0
    void Acquire(PullToHold intersect)
    {
        if (intersect.holder != null) {
                        intersect.holder.enabled = false;
                }

                pulled = intersect;
                if (intersect == null)
                        return;
                //NOTE: hold reference is implicitly made null if hold is destroyed
                pulled.holder = this;
    }
Beispiel #6
0
    void Acquire(PullToHold intersect)
    {
        if (intersect.holder != null)
        {
            intersect.holder.enabled = false;
        }

        pulled = intersect;
        if (intersect == null)
        {
            return;
        }
        //NOTE: hold reference is implicitly made null if hold is destroyed
        pulled.holder = this;
    }
Beispiel #7
0
    void Acquire(PullToHold intersect)
    {
        if (intersect.holder != null) {
        intersect.holder.enabled = false;
        }

        if ( Hold == null ) {
          throw new System.Exception("Attempting to aquire hold without holder.");
        }

        pulled = intersect;

        if (intersect == null) { return; }

        //NOTE: hold reference is implicitly made null if hold is destroyed
        pulled.holder = this;
        Hold.transform.rotation = intersect.gameObject.transform.rotation;

        if ( intersect.asterismKey != -1 && intersect.asterismKey < Asterisms.AsterismParser.AsterismData.Length ) {
          float scaleFactor = Asterisms.AsterismParser.AsterismData[intersect.asterismKey].scaleFactor;
          Hold.transform.localScale = new Vector3(0.007f,0.007f,0.007f) * scaleFactor;
        }
    }
Beispiel #8
0
        private static void setupAsterismGrabbers()
        {
            GameObject starRoot = new GameObject("StarRoot");

            for (int i = 0; i < AsterismData.Length; i++)
            {
                Asterism asterism = AsterismData[i];
                Vector3  centroid = averageStarLocations(asterism.HD_ids);

                GameObject newRoot   = new GameObject();
                GameObject rest      = new GameObject();
                GameObject jewelcase = new GameObject();

                newRoot.name = asterism.name + "_root";
                newRoot.transform.position = centroid;
                newRoot.transform.rotation = Quaternion.identity;

                rest.name                    = "rest";
                rest.transform.parent        = newRoot.transform;
                rest.transform.localPosition = Vector3.zero;
                rest.transform.localRotation = Quaternion.identity;
                rest.transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);

                jewelcase.name                    = "jewelcase";
                jewelcase.transform.parent        = newRoot.transform;
                jewelcase.transform.localPosition = Vector3.zero;
                jewelcase.transform.localRotation = Quaternion.identity;
                jewelcase.transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);
                PullToHold pullscript = jewelcase.AddComponent <PullToHold>();
                pullscript.asterismKey = i;
                pullscript.rest        = rest.transform;
                pullscript.maxSpeed    = 20.0f;

                newRoot.transform.parent = starRoot.transform;
                asterism.root            = newRoot;
                asterism.rest            = rest;
                asterism.mover           = jewelcase;

                System.Collections.Generic.HashSet <uint> used = new System.Collections.Generic.HashSet <uint>();

                GameObject constellationLabel = GameObject.Instantiate(Stars.StarUpdater.Instance.ConstellationLabelPrototype) as GameObject;
                constellationLabel.SetActive(true);
                ConstellationLabel labelBehavior = constellationLabel.GetComponent <ConstellationLabel>();

                if (asterism.root != null)
                {
                    labelBehavior.transform.parent = asterism.root.transform;
                }

                labelBehavior.Label = asterism.name;
                labelBehavior.transform.localPosition = (asterism.root.transform.position.normalized * 500.0f);
                asterism.label = labelBehavior;
                labelBehavior.LabelComp.color = new Color(1.0f, 1.0f, 1.0f, Stars.StarUpdater.Instance.LabelOpacity * 0.8f);

                Stars.StarUpdater.Instance.m_constellationLabels.Add(labelBehavior);

                foreach (uint hdId in asterism.HD_ids)
                {
                    if (!Stars.StarParser.HD_idToIndex.ContainsKey(hdId))
                    {
                        continue;
                    }

                    int            index = Stars.StarParser.HD_idToIndex[hdId];
                    Stars.StarData star  = Stars.StarParser.Instance.Stars[index];

                    star.AsterismIndex = i;
                    Stars.StarParser.Instance.Stars[index] = star;
                    if (star.GameObjectRepresentation != null)
                    {
                        star.GameObjectRepresentation.name             = hdId.ToString();
                        star.GameObjectRepresentation.transform.parent = jewelcase.transform;
                        if (star.Label != "")
                        {
                            if (used.Contains(star.HD_id))
                            {
                                continue;
                            }

                            Stars.StarUpdater.Instance.GenerateStarLabel(star, star.GameObjectRepresentation.transform);
                            used.Add(star.HD_id);
                        }
                    }
                }

                AsterismData[i] = asterism;
            }
        }
Beispiel #9
0
    // Identify pulled object using view of hand
    void Update()
    {
        if (view == null)
        {
            return;
        }

        if (m_hand.CurrentHand == null)
        {
            if (pulled != null)
            {
                if (!attemptingToReaquire)
                {
                    StartCoroutine(reaquireHand(2.0f));
                }
            }
            return;
        }

        if (pulled != null)
        {
            return;
        }



        if (Hold == null && m_hand.CurrentHand != null)
        {
            updateHold();
            //GrabberHand grabberHand = m_hand.CurrentHand.gameObject.GetComponent<GrabberHand>();
            //if ( grabberHand == null ) { return; }
            //Hold = grabberHand.hold;
        }


        Vector2 screenPoint = m_leftCam.WorldToScreenPoint(m_hand.CurrentHand.GetPalmPosition());
        Ray     throughHand = m_leftCam.ScreenPointToRay(screenPoint);

        //Debug.DrawRay(m_leftCam.transform.position, m_leftCam.ScreenPointToRay(screenPoint).direction * 1000.0f);

        RaycastHit castInfo;
        bool       hit = Physics.Raycast(throughHand, out castInfo, float.PositiveInfinity, LayerMask.GetMask("AsterismColliders"));

        if (hit)
        {
            if (!Activate())
            {
                this.enabled = false;
                return;
            }

            AsterismReference asterismRef = castInfo.transform.GetComponent <AsterismReference>();
            if (asterismRef != null)
            {
                Asterisms.Asterism hitAsterism = asterismRef.Asterism;

                PullToHold intersect = hitAsterism.mover.GetComponent <PullToHold>();

                if (intersect.cameraPoint == null)
                {
                    intersect.cameraPoint = m_leftCam.transform;
                }

                if (intersect != null)
                {
                    SelectStars(hitAsterism.mover);
                    Acquire(intersect);
                }
            }
        }
    }