GetTipPosition() 공개 메소드

public GetTipPosition ( ) : Vector3
리턴 Vector3
예제 #1
0
    //Draws a line straight forward from the index finguer
    public Vector3 getShootingFingerPoint(int index)
    {
        FingerModel finger = hand_model.fingers[index];

        Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);

        Ray finger_ray = new Ray(finger.GetTipPosition(), finger.GetRay().direction);

        RaycastHit hit;
        Vector3    shooting_point;

        bool collision = Physics.Raycast(finger_ray, out hit);

        if (collision)
        {
            shooting_point = hit.point;
        }
        else
        {
            int infinite_distance = 100;
            shooting_point = finger_ray.origin + (finger_ray.direction.normalized * infinite_distance);
        }

        return(shooting_point);
    }
예제 #2
0
    /// <summary>
    /// Do a raycast from each finger of a hand.
    /// </summary>
    /// <param name="castDistance"> The distance the raycast should check.</param>
    /// <param name="rayIsEmpty"> If the ray is the 'empty' default ray that returns when no valid raycast hits.</param>
    /// <returns>A RaycastHit. If rayIsEmpty is false then this hit is the first hit from a finger onto an object.</returns>
    public RaycastHit RaycastFromFingers(float castDistance, out bool rayIsEmpty)
    {
        RaycastHit hit;
        bool       raycastHit;

        //Iterate through each finger
        for (int i = 0; i < HandModel.NUM_FINGERS; i++)
        {
            FingerModel finger = hand_model.fingers[i]; //This is sometimes null? Apparently? Not sure why?

            // draw ray from finger tips (enable Gizmos in Game window to see)
            Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);

            //Do actual raycast
            raycastHit = Physics.Raycast(finger.GetTipPosition(), finger.GetRay().direction, out hit, castDistance);

            if (raycastHit == true)
            {
                rayIsEmpty = false;
                return(hit);
            }
        }

        rayIsEmpty = true;

        //Default raycast, should never actually be called
        raycastHit = Physics.Raycast(Vector3.zero, Vector3.one, out hit, castDistance);
        return(hit);
    }
예제 #3
0
    void Update()
    {
        FingerModel finger = hand_model.fingers[1];

        line = GetComponent <LineRenderer>();
        RaycastHit hit;

        Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);
        Physics.Raycast(finger.GetTipPosition(), finger.GetRay().direction, out hit, Mathf.Infinity);

        line.SetWidth(0.01f, 0.01f);

        Vector3[] points = new Vector3[2];
        points[0] = finger.GetTipPosition();
        points[1] = finger.GetTipPosition() + 1000 * finger.GetRay().direction;

        line.SetPositions(points);

        if (Input.GetKey(KeyCode.Space))
        {
            audio.Play();
            if (hit.transform.tag == "TARGET")
            {
                hit.transform.gameObject.SendMessage("Ding", targetHandler);
            }
            else
            {
            }
        }
    }
예제 #4
0
    /// <summary>
    /// Disegna prendendo il dito indice come riferimento.
    /// </summary>
    public void Draw()
    {
        //guarda se le dita sono nella giusta posizione
        if (!leftHand.GetComponent <ManageLeft>().IsFaceUp())
        {
            //prende come riferimento il dito indice
            FingerModel finger = hand_model.fingers[1];
            RaycastHit  hit;
            //guardo se il raycost colpisce la tela
            if (Physics.Raycast(finger.GetTipPosition(), Vector3.forward, 1000))
            {
                Debug.Log("Tela colpita");
                //prendo la posizone del punto in cui è stata colpita la tela
                Debug.DrawRay(finger.GetTipPosition(), Vector3.forward, Color.red);
            }
            //prendo la texture dalla tela
            Texture2D tex = (Texture2D)tela.GetComponent <Renderer>().material.mainTexture;

            //disegno sulla tela
            tex = DrawCircle(tex, color, (int)(tex.width * (finger.GetTipPosition().x + 0.5)), (int)(tex.height * (finger.GetTipPosition().y - 3.5)), brushSize);
            //Debug.Log("X: " + finger.GetTipPosition().x);
            //Debug.Log("Y: " + finger.GetTipPosition().z);
            //Debug.Log("XT: " + (tex.width * (finger.GetTipPosition().x + width / 2)));
            //Debug.Log("YT: " + (tex.height * (finger.GetTipPosition().z + height / 2)));
            // applica il disegno sulla tela
            tex.Apply();
        }
    }
예제 #5
0
    void Update()
    {
        FingerModel finger = hand_model.fingers[1];

        Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.blue);
        RaycastHit hit;

        isHit = Physics.Raycast(finger.GetTipPosition(), finger.GetRay().direction, out hit);

        if (isHit)
        {
            if (hit.transform.gameObject.name == "GeoSphere346")
            {
                isShow = !isShow;
                Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.clear);

                /* print("风池(足少阳胆经)【定位】在颈后区,枕骨下,胸锁乳突肌上端与斜方肌上端之间的凹陷中  【解剖】浅层布有枕小神经,枕动静脉的分支和属支。深层有枕大神经。  【针刺层次】皮肤——>皮下组织——>头夹肌——>头半棘肌  【主治】1.头痛,眩晕,失眠,癫痫,中风  2.目赤肿痛,视物不明,鼻塞,鼻窦,鼻渊,耳鸣,咽喉肿痛  3.感冒,热病  4.颈项强痛 ");
                 * print("【定位】在颈后区,枕骨下,胸锁乳突肌上端与斜方肌上端之间的凹陷中");
                 * print("【解剖】浅层布有枕小神经,枕动静脉的分支和属支。深层有枕大神经。");
                 * print("【针刺层次】皮肤——>皮下组织——>头夹肌——>头半棘肌");
                 * print("【主治】1.头痛,眩晕,失眠,癫痫,中风  2.目赤肿痛,视物不明,鼻塞,鼻窦,鼻渊,耳鸣,咽喉肿痛  3.感冒,热病  4.颈项强痛 ");*/
                //selectedObject = null;
            }
            if (hit.transform.gameObject.name == "GeoSphere347")
            {
                isShow = !isShow;
            }
            if (selectedObject != null && hit.transform.gameObject == selectedObject)
            {
                alreadyHit = true;
            }

            /*if (selectedObject != null && hit.transform.gameObject != selectedObject)
             * {
             *  alreadyHit = false;
             *  selectedObject.transform.GetComponent<MeshRenderer>().material.color = previousColour;
             *  selectedObject.transform.localScale = previousScale;
             *  selectedObject = hit.transform.gameObject;
             * }
             * selectedObject = hit.transform.gameObject;
             * if (selectedObject != null && !alreadyHit)
             * {
             *  Debug.Log(selectedObject.name);
             *  selectedObject.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
             *  MeshRenderer temp = selectedObject.GetComponent<MeshRenderer>();
             *  previousColour = temp.material.color;
             *  temp.material.color = Color.red;
             * }
             *
             * else if (selectedObject != null)
             * {
             *  alreadyHit = false;
             *  selectedObject.transform.GetComponent<MeshRenderer>().material.color = previousColour;
             *  selectedObject.transform.localScale = previousScale;
             *  selectedObject = null;
             * }*/
        }
    }
예제 #6
0
    IEnumerator MoveLaser(FingerModel finger)
    {
        line.enabled = true;

        float rayLength = Vector3.Distance(finger.GetTipPosition(), selectedObject.transform.position);

        Ray ray = new Ray(finger.GetTipPosition(), finger.GetRay().direction);

        line.SetPosition(0, ray.origin);
        line.SetPosition(1, ray.GetPoint(rayLength));
        yield return(null);

        line.enabled = false;
    }
예제 #7
0
파일: Colors.cs 프로젝트: brunick/VRAR
 void OnTriggerEnter(Collider collider)
 {
     if (IsFinger(collider) && gm.getColorChoserActive()) {
         if (!hasSphere)
         {
             fingerModel = collider.gameObject.GetComponentInParent<FingerModel>();
             f = fingerModel.GetLeapFinger();
     //                Debug.Log(f);
             if(fingerModel.fingerType.ToString().Equals("TYPE_INDEX"))
             {
                 col = collider;
                 // Neue Sphere erstellen mit der Farbe vom Bucket
                 QuizManager.setHasColor(true);
                 Destroy(drop);
                 Colors.drop = Instantiate(Resources.Load("Drop")) as GameObject;
                 Colors.drop.transform.position = new Vector3(0, 1.5F, 0);
                 Colors.drop.transform.localScale = new Vector3(0.5F,0.5F,0.5F);
                 Renderer m = Colors.drop.GetComponent<Renderer>();
                 QuizManager.shaderName = bucketMat.name;
                 m.material = bucketMat;
                 Colors.drop.transform.position = fingerModel.GetTipPosition();
                 hasSphere = true;
                 QuizManager.setHasColor(true);
             }
         }
     }
     if (IsHand(collider))
     {
      //           print("Hand berührt");
     }
 }
예제 #8
0
    // Update is called once per frame
    void Update()
    {
        FingerModel finger = handmodel.fingers [1];

        Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);
        InterfaceManager.Instance.leapMotionManager.screenPointToRay = finger.GetRay();
    }
예제 #9
0
    // Update is called once per frame
    void Update()
    {
        HandModel[] allGraphicHands = LeapHandController.GetAllGraphicsHands();

        if (allGraphicHands.Length <= 0) return;
        HandModel handModel = allGraphicHands[0];

        finger = handModel.fingers[(int)Finger.FingerType.TYPE_INDEX];

        fingerTipPos = finger.GetTipPosition();

        fingerdetect = (Input.GetKey(KeyCode.Space));

        if (fingerdetect)
        {
            // Using named temp variables like this helps me think more clearly about the code
            Vector3 previousPoint = (linePoints.Count > 0) ? linePoints[linePoints.Count - 1] : new Vector3(-1000, -1000, -1000); // If you've never seen this before, it's called a ternary expression.
                                                                                                        // It's just an if/else collapsed into a single line of code.
                                                                                                        // Also, the crazy out of bounds initial value here ensures the starting point will always draw.

            if (Vector3.Distance(fingerTipPos, previousPoint) > newPointDelta)
            {
                linePoints.Add(fingerTipPos);
                lineRenderer.SetVertexCount(linePoints.Count);
                lineRenderer.SetPosition(linePoints.Count - 1, (Vector3)linePoints[linePoints.Count - 1]);
                Debug.Log(string.Format("Added point at: {0}!", fingerTipPos));
            }
        }
    }
예제 #10
0
    // Update is called once per frame
    void Update()
    {
        HandModel[] allGraphicHands = LeapHandController.GetAllGraphicsHands();

        if (allGraphicHands.Length <= 0)
        {
            return;
        }
        HandModel handModel = allGraphicHands[0];

        finger = handModel.fingers[(int)Finger.FingerType.TYPE_INDEX];

        fingerTipPos = finger.GetTipPosition();

        fingerdetect = (Input.GetKey(KeyCode.Space));

        if (fingerdetect)
        {
            // Using named temp variables like this helps me think more clearly about the code
            Vector3 previousPoint = (linePoints.Count > 0) ? linePoints[linePoints.Count - 1] : new Vector3(-1000, -1000, -1000); // If you've never seen this before, it's called a ternary expression.
            // It's just an if/else collapsed into a single line of code.
            // Also, the crazy out of bounds initial value here ensures the starting point will always draw.

            if (Vector3.Distance(fingerTipPos, previousPoint) > newPointDelta)
            {
                linePoints.Add(fingerTipPos);
                lineRenderer.SetVertexCount(linePoints.Count);
                lineRenderer.SetPosition(linePoints.Count - 1, (Vector3)linePoints[linePoints.Count - 1]);
                Debug.Log(string.Format("Added point at: {0}!", fingerTipPos));
            }
        }
    }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        Vector3    fwd = transform.TransformDirection(Vector3.forward);
        RaycastHit hit;

        for (int i = 0; i < HandModel.NUM_FINGERS; i++)
        {
            finger = handModel.fingers[i];
            if (Physics.Raycast(finger.GetTipPosition(), fwd, out hit))
            {
                float distanceToGround = hit.distance;
                Debug.Log("hit something" + distanceToGround);
            }
            Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red, Time.deltaTime, true);
        }
    }
예제 #12
0
 // Update is called once per frame
 void Update()
 {
     for (int i = 0; i < HandModel.NUM_FINGERS; i++)
     {
         FingerModel finger = hand_model.fingers[i];
         Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);
     }
 }
예제 #13
0
 void Update()
 {
     for (int i = 0; i < HandModel.NUM_FINGERS; i++)
     {
         FingerModel finger = hand_model.fingers[i];
         // draw ray from finger tips (enable Gizmos in Game window to see)
         Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);
     }
 }
예제 #14
0
    // Update is called once per frame
    void Update()
    {
        Vector3 thumbPosition  = thumb.GetTipPosition() - transform.localPosition;
        Vector3 indexPosition  = index.GetTipPosition() - transform.localPosition;
        Vector3 middlePosition = (thumbPosition + indexPosition) * 0.5f;
        Vector3 localScale     = transform.localScale;

        middlePosition = new Vector3(middlePosition.x / localScale.x, middlePosition.y / localScale.y, middlePosition.z / localScale.z);

        middlePointContainer.transform.localPosition = middlePosition;

        float distance = Vector3.Distance(thumbPosition, indexPosition);

        isPinching = (distance < PINCH_DISTANCE);
        if (isPinching != wasPinching)
        {
            StateTransition();
        }

        float x = middlePosition.x;

        if (Mathf.Abs(x) > SCROLL_THRESHOLD_X)
        {
            scrollThresholdAccumulatedFrames += 1;
            if (scrollThresholdAccumulatedFrames > SCROLL_THRESHOLD_ACCUMULATED_FRAMES_MIN)
            {
                x = (x > 0)? +1 : -1;

                if (scrollThresholdAccumulatedFrames > SCROLL_THRESHOLD_ACCUMULATED_FRAMES_MAX)
                {
                    scrollThresholdAccumulatedFrames = SCROLL_THRESHOLD_ACCUMULATED_FRAMES_MAX;
                }
                float strengthMultiplierUponAccumulatedFrames = ((float)scrollThresholdAccumulatedFrames - SCROLL_THRESHOLD_ACCUMULATED_FRAMES_MIN) / (SCROLL_THRESHOLD_ACCUMULATED_FRAMES_MAX - SCROLL_THRESHOLD_ACCUMULATED_FRAMES_MIN);

                gameController.OnGestureScroll(strength: x * strengthMultiplierUponAccumulatedFrames);
            }
        }
        else
        {
            scrollThresholdAccumulatedFrames = 0;
        }
    }
예제 #15
0
 void SetFingerSpritePosition(FingerModel index, FingerModel thumb)
 {
     if (index != null)
     {
         fingerSprite.transform.position = TransformPosition(index.GetTipPosition());
     }
     if (thumb != null)
     {
         thumbSprite.transform.position = TransformPosition(thumb.GetTipPosition());
     }
 }
예제 #16
0
    /// <summary>
    /// Metodo eseguito ad ogni frame.
    /// </summary>
    void Update()
    {
        try
        {
            if (leap_hand != null)
            {
                //prende le dimensione della tela
                float width  = telaDisegnabile.GetComponent <Renderer>().bounds.size.x;
                float height = telaDisegnabile.GetComponent <Renderer>().bounds.size.y;
                //guarda se le dita sono nella giusta posizione
                if (leap_hand.IsPinching() && !leftHand.GetComponent <ManageLeft>().IsFaceUp() && !leftHand.GetComponent <ManageLeft>().IsGrabbing() &&
                    !leftHand.GetComponent <ManageLeft>().IsPinching())
                {
                    //prende come riferimento il dito indice
                    FingerModel finger = hand_model.fingers[1];
                    RaycastHit  hit;
                    //guardo se il raycost colpisce la tela
                    if (Physics.Raycast(finger.GetTipPosition(), Vector3.forward, 1000))
                    {
                        Debug.Log("Tela colpita");
                        //prendo la posizone del punto in cui è stata colpita la tela
                        Debug.DrawRay(finger.GetTipPosition(), Vector3.forward, Color.red);
                    }
                    //prendo la texture dalla tela
                    Texture2D tex = (Texture2D)telaDisegnabile.GetComponent <Renderer>().material.mainTexture;

                    //disegno sulla tela
                    tex = DrawCircle(tex, color, (int)(tex.width * (finger.GetTipPosition().x + 0.5)), (int)(tex.height * (finger.GetTipPosition().y - 3.5)), brushSize);
                    //Debug.Log("X: " + finger.GetTipPosition().x);
                    //Debug.Log("Y: " + finger.GetTipPosition().z);
                    //Debug.Log("XT: " + (tex.width * (finger.GetTipPosition().x + width / 2)));
                    //Debug.Log("YT: " + (tex.height * (finger.GetTipPosition().z + height / 2)));
                    tex.Apply();
                }
            }
        }
        catch (NullReferenceException e)
        {
            Debug.LogError("Mani non inserite");
        }
    }
예제 #17
0
        void AnimateCursor(FingerModel index, FingerModel thumb)
        {
            Vector3 midPosition = (index.GetTipPosition() + thumb.GetTipPosition()) / 2;

            immediatePosition = (smoothCursor) ? Utils.ExponentialVectorSmoothing(immediatePosition, midPosition, cursorExp) : midPosition;
            if (state == PinchState.Open)
            {
                cursorPosition = immediatePosition;
            }
            curosrSprite.transform.position    = TransformPosition(cursorPosition);
            immediateSprite.transform.position = TransformPosition(immediatePosition);
        }
예제 #18
0
    private const float MIN_CONFIDENCE         = 0.2f;                                  //Minimum value of handmodel confidence
    #endregion

    // Update is called once per frame
    void Update()
    {
        //define LeapHands & Fingers
        handModel = GetComponent <HandModel> ();
        leapHand  = handModel.GetLeapHand();
        //get indexfinger
        indexFingerModel = handModel.fingers [1];
        //get indexfingerTip position
        indexTip = indexFingerModel.GetTipPosition();
        //get thumbTip position
        thumbTip = leapHand.Fingers [0].TipPosition.ToUnityScaled();

        //calculating velocity of finger
        currPosition = thumbTip;
        velocity     = (currPosition - prePosition).magnitude / Time.deltaTime;
        prePosition  = thumbTip;

        //Trigger test (true: thumbTip got close to rest of fingers)
        bool patternTrigger = false;

        for (int i = 1; i < 5 && !patternTrigger; ++i)
        {
            for (int j = 0; j < 4 && !patternTrigger; ++j)
            {
                Finger.FingerJoint joint      = (Finger.FingerJoint)(j);
                Vector3            difference = leapHand.Fingers[i].JointPosition(joint).ToUnityScaled() - thumbTip;
                if (difference.magnitude < THUMB_TRIGGER_DISTANCE &&
                    leapHand.Confidence > MIN_CONFIDENCE)
                {
                    //Trigger is ON
                    patternTrigger = true;
                }
            }
        }
        //Particle system On/Off
        switch (patternTrigger)
        {
        case (true):
            //Start recording finger position
            AddPositionCache(indexTip);
            transform.FindChild("particle").gameObject.SetActive(true);
            break;

        case (false):
            transform.FindChild("particle").gameObject.SetActive(false);
            break;
        }

        if (DetectFingerGesture())
        {
            //Detected!
        }
    }
예제 #19
0
    public bool SetButton(int num)
    {
        // if a hand exists set the real world position of the button to the tip of the finger
        if (r_index != null)
        {
            bPos[num] = r_index.GetTipPosition();

            return(true);
        }

        return(false);
    }
예제 #20
0
 void Update()
 {
     handModel = GetComponent <HandModel>();
     leapHand  = handModel.GetLeapHand();
     finger    = handModel.fingers[1];
     indexTip  = finger.GetTipPosition();
     AddPositionCache(indexTip);
     if (DetectCircleGesture() || DetectPolygonGesture())
     {
         // Detected!
     }
 }
예제 #21
0
    void Update()
    {
        for (int i = 0; i < HandModel.NUM_FINGERS; i++)
        {
            RaycastHit  hit;
            FingerModel finger = hand_model.fingers[i];
            // draw ray from finger tips (enable Gizmos in Game window to see)

            Ray fingerRay = new Ray(finger.GetTipPosition(), finger.GetRay().direction);
            Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);

            if (Physics.Raycast(fingerRay, out hit))
            {
                if (hit.collider.tag == "Teleport" && Input.GetKeyDown(KeyCode.E))
                {
                    Debug.Log("this hit the teleport cube 1");
                    teleportLocation.transform.position = teleport1.transform.position;
                    teleportLocation.transform.rotation = teleport1.transform.rotation;
                }
                else if (hit.collider.tag == "Teleport 2" && Input.GetKeyDown(KeyCode.E))
                {
                    Debug.Log("this hit the teleport cube 2");
                    teleportLocation.transform.position = teleport2.transform.position;
                    teleportLocation.transform.rotation = teleport2.transform.rotation;
                }
                else if (hit.collider.tag == "Teleport 3" && Input.GetKeyDown(KeyCode.E))
                {
                    Debug.Log("this hit the teleport cube 3");
                    teleportLocation.transform.position = teleport3.transform.position;
                    teleportLocation.transform.rotation = teleport3.transform.rotation;
                }
                else if (hit.collider.tag == "Teleport 4" && Input.GetKeyDown(KeyCode.E))
                {
                    Debug.Log("this hit the teleport cube 4");
                    teleportLocation.transform.position = teleport4.transform.position;
                    teleportLocation.transform.rotation = teleport4.transform.rotation;
                }
            }
        }
    }
예제 #22
0
 // Update is called once per frame
 void Update()
 {
     try
     {
         if (leap_hand != null)
         {
             //guarda se le dita sono nella giusta posizione
             if (leap_hand.IsPinching() && !prevPinch)
             {
                 //prende come riferimento il dito indice
                 FingerModel finger = hand_model.fingers[1];
                 RaycastHit  hit;
                 //guardo se il raycost colpisce la tela
                 if (Physics.Raycast(finger.GetTipPosition(), Vector3.forward, 1000))
                 {
                     Debug.Log("Tela colpita");
                     //prendo la posizone del punto in cui è stata colpita la tela
                     Debug.DrawRay(finger.GetTipPosition(), Vector3.forward, Color.red);
                 }
                 //prendo la texture dalla tela
                 Texture2D tex = (Texture2D)telaDisegnabile.GetComponent <Renderer>().material.mainTexture;
                 //disegno sulla tela
                 Debug.Log("Ciao");
                 FloodFill(tex, 1, (int)(tex.width * (finger.GetTipPosition().x + 0.5)), (int)(tex.height * (finger.GetTipPosition().y + 0.5)));
                 tex.Apply();
                 prevPinch = true;
             }
         }
         else if (!leap_hand.IsPinching() && prevPinch)
         {
             prevPinch = false;
         }
     }
     catch (NullReferenceException e)
     {
         Debug.LogError("Mani non inserite");
     }
 }
예제 #23
0
    void rotateObject()
    {
        if (!leap_hand.IsLeft)
        {
            return;
        }

        float middle_index = Vector3.Distance(indexFinger.GetTipPosition(), middleFinger.GetTipPosition());
        float ring_middle  = Vector3.Distance(middleFinger.GetTipPosition(), ringFinger.GetTipPosition());

        Debug.Log("middle_index: " + middle_index);
        Debug.Log("ring_middle: " + ring_middle);

        if ((middle_index < .13) && (ring_middle < .13))
        {
            Debug.Log("here 1");
            float      zPos = Mathf.Exp((middleFinger.GetTipPosition().z + 5));
            Quaternion rotz = Quaternion.AngleAxis(zPos, Vector3.forward);
            selectedObject.transform.rotation = rotz * selectedObject.transform.rotation;
            return;
        }
        else if (middle_index < .13)
        {
            Debug.Log("here 2");
            float      yPos = Mathf.Exp((middleFinger.GetTipPosition().y));
            Quaternion roty = Quaternion.AngleAxis(yPos, Vector3.down);
            selectedObject.transform.rotation = roty * selectedObject.transform.rotation;
            return;
        }
        else
        {
            Debug.Log("here 3");
            float      xPos = Mathf.Exp((indexFinger.GetTipPosition().x));
            Quaternion rotx = Quaternion.AngleAxis(xPos, Vector3.right);
            selectedObject.transform.rotation = rotx * selectedObject.transform.rotation;
            return;
        }



//		/////
//
//		float xPos = Mathf.Exp((indexFinger.GetTipPosition ().x));
//		float yPos = Mathf.Exp((indexFinger.GetTipPosition ().y));
//		float zPos = Mathf.Exp((indexFinger.GetTipPosition ().z + 5));
//
//		selectedObject.transform.Rotate (xPos, yPos, zPos);
    }
예제 #24
0
    void Update()
    {
        FingerModel finger = hand_model.fingers[1];
        //Debug.DrawRay (finger.GetTipPosition(), finger.GetRay().direction, Color.red);
        RaycastHit hit;

        isHit = Physics.Raycast(finger.GetTipPosition(), finger.GetRay().direction, out hit);

        if (isHit)
        {
            if (hit.transform.gameObject == null)
            {
                selectedObject = null;
            }

            if (selectedObject != null && hit.transform.gameObject == selectedObject)
            {
                alreadyHit = true;
            }

            if (selectedObject != null && hit.transform.gameObject != selectedObject)
            {
                alreadyHit = false;
                selectedObject.transform.GetComponent <MeshRenderer>().material.color = previousColour;
                selectedObject.transform.localScale = previousScale;
                selectedObject = hit.transform.gameObject;
            }
            selectedObject = hit.transform.gameObject;
            if (selectedObject != null && !alreadyHit)
            {
                Debug.Log(selectedObject.name);
                Transform    tmp  = selectedObject.transform;
                MeshRenderer temp = selectedObject.GetComponent <MeshRenderer>();
                previousScale       = tmp.localScale;
                previousColour      = temp.material.color;
                tmp.localScale      = new Vector3(0.8f, 0.8f, 0.8f);
                temp.material.color = Color.red;
            }

            else if (selectedObject != null)
            {
                alreadyHit = false;
                selectedObject.transform.GetComponent <MeshRenderer>().material.color = previousColour;
                selectedObject.transform.localScale = previousScale;
                selectedObject = null;
            }
        }
    }
예제 #25
0
    IEnumerator FireLaser(FingerModel finger)
    {
        line.enabled = true;

        //TODO: only raycast when selectedObject == null
//		if (selectedObject == null) {
        Ray ray = new Ray(finger.GetTipPosition(), finger.GetRay().direction);

        line.SetPosition(0, ray.origin);
        line.SetPosition(1, ray.GetPoint(100));
        yield return(null);

//		}

        line.enabled = false;
    }
예제 #26
0
    private void MoveShadow(bool fromCamera)
    {
        RaycastHit hit;
        HandModel  rightGraphicHand = ChangingHeights.Instance.getRightGraphicHand();

        if (!rightGraphicHand)
        {
            return;
        }
        //if from camera take thumb, else take index finger
        FingerModel finger            = rightGraphicHand.fingers[fromCamera ? 0 : 1];
        Vector3     fingerTipPosition = finger.GetTipPosition();
        Ray         ray = fromCamera ? new Ray(fingerTipPosition, fingerTipPosition - ChangingHeights.Instance.camera.transform.position): new Ray(fingerTipPosition, Vector3.down);

        if (Physics.Raycast(ray, out hit, 200, ChangingHeights.Instance.terrainLayerMask))
        {
            shadowProjectorTransform.position = hit.point + new Vector3(0, 15, 0);//maybe 22
        }
    }
예제 #27
0
    private void selectObject()
    {
        if (!leap_hand.IsRight)
        {
            return;
        }

        line.SetColors(Color.red, Color.white);

        StopCoroutine("FireLaser");
        StartCoroutine("FireLaser", indexFinger);

        Debug.DrawRay(indexFinger.GetTipPosition(), indexFinger.GetRay().direction, Color.red);
        RaycastHit indexHit;

        isHit = Physics.Raycast(indexFinger.GetTipPosition(), indexFinger.GetRay().direction, out indexHit);

        if (isHit)
        {
            //can only select desired objects

            Debug.Log(indexHit.collider);

            if (indexHit.transform.parent.name == "Objects")
            {
                selectedObject = indexHit.transform.gameObject;
                originalZPos   = selectedObject.transform.position.z;
                return;
            }
            else if (indexHit.transform.parent.name == "Satellite")
            {
                selectedObject = indexHit.transform.parent.gameObject;
                originalZPos   = selectedObject.transform.position.z;
                return;
            }

            selectedObject = null;
            return;
        }
    }
예제 #28
0
    void Update()
    {
        hands = LMHandController.GetAllGraphicsHands();
        if (hands.Length > 0)
        {
            aHand  = hands[0];
            finger = aHand.fingers[1]; //thumb is index 0
            indexFingerPosition = finger.GetTipPosition();
            distance            = Vector3.Distance(signalModePosition, indexFingerPosition);
            if (distance > maximumDistance)
            {
                distance = -1;
            }
        }
        else
        {
            distance = -1;
            doRequest(0);
        }

        this.gameObject.transform.position = indexFingerPosition;

        //gameObject.GetComponent<Renderer>().material.color = Color.gray;
    }
    void Update()
    {
        //Define fingers
        FingerModel finger1  = handModel.fingers[1];       //get index finger
        FingerModel finger2  = handModel.fingers[2];       //get middle finger
        FingerModel finger3  = handModel.fingers [3];      //get kusuri-yubi finger
        Rigidbody   palmBody = palm.GetComponent <Rigidbody>();
        Frame       frame    = controller.Frame();

        //caculate distance between fingers
        float dis  = Mathf.Abs(finger2.GetTipPosition().x - finger1.GetTipPosition().x);
        float dis2 = Mathf.Abs(finger3.GetTipPosition().y - finger2.GetTipPosition().y);

        //calculate velocity of hand
        float vel = palmBody.velocity.y;



        //Gesture Setting
        GestureList gestures = frame.Gestures();

        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[i];
            if (gesture.Type == Gesture.GestureType.TYPESWIPE)
            {
                SwipeGesture Swipe          = new SwipeGesture(gesture);
                Vector       SwipeDirection = Swipe.Direction;

                /** Vertical Swipe Direction
                 * y:   hand Direction
                 * vel:     minimum velocity to recognize the action
                 * dis:	minimum distance to travel of hand
                 * dis2:	fingertip distance
                 **/
                if (SwipeDirection.y < 0 && dis < 0.35 && vel < -2 && dis2 > 0.7)
                {
                    //On ();
                    //Debug.Log("DOWN");//Gesture Confirm
                    b1.SetActive(true);
                    b2.SetActive(true);
                    b3.SetActive(true);
                    b4.SetActive(true);
                    iTween.MoveTo(b1, iTween.Hash("path", iTweenPath.GetPath("BtnPath1"), "time", 1.20, "easetype", "easeOutBack"));
                    iTween.MoveTo(b2, iTween.Hash("path", iTweenPath.GetPath("BtnPath2"), "time", 1.20, "easetype", "easeOutBack"));
                    iTween.MoveTo(b3, iTween.Hash("path", iTweenPath.GetPath("BtnPath3"), "time", 1.20, "easetype", "easeOutBack"));
                    iTween.MoveTo(b4, iTween.Hash("path", iTweenPath.GetPath("BtnPath4"), "time", 1.20, "easetype", "easeOutBack"));
                }
                else if (SwipeDirection.y > 0 && vel > 5)
                {
                    //Debug.Log ("UP");
                    iTween.MoveFrom(b1, iTween.Hash("path", iTweenPath.GetPath("BtnPath1"), "time", .20, "easetype", "linear"));
                    iTween.MoveFrom(b2, iTween.Hash("path", iTweenPath.GetPath("BtnPath2"), "time", .20, "easetype", "linear"));
                    iTween.MoveFrom(b3, iTween.Hash("path", iTweenPath.GetPath("BtnPath3"), "time", .20, "easetype", "linear"));
                    iTween.MoveFrom(b4, iTween.Hash("path", iTweenPath.GetPath("BtnPath4"), "time", .20, "easetype", "linear"));
                    b1.SetActive(false);
                    b2.SetActive(false);
                    b3.SetActive(false);
                    b4.SetActive(false);

                    //------------Use Below When using lerp--------------
                    //isOpen=false;
                    //Vector3 scale = container.localScale;
                    //scale.y = Mathf.Lerp (scale.y, 0, Time.deltaTime*10);
                    //container.localScale = scale;
                }
//				Vector3 scale = container.localScale;
//				scale.y = Mathf.Lerp (scale.y, isOpen? 1:0, Time.deltaTime*20);
//				container.localScale = scale;
            }
        }
    }
				void SetFingerSpritePosition (FingerModel index, FingerModel thumb)
				{
						if (index != null)
								fingerSprite.transform.position = TransformPosition (index.GetTipPosition ());
						if (thumb != null)
								thumbSprite.transform.position = TransformPosition (thumb.GetTipPosition ());
				}
    void GunGesture()
    {
        // LEFT ACTIVE
        if (stateL == "Active")
        {
            // Index extended and all other fingers not extended
            if (IsExtended(leftIndex) && !IsExtended(leftMiddle) && !IsExtended(leftRing) && !IsExtended(leftPinkie))
            {
                // PLACE WANTED LEFT SWIPE FUNCTIONALITY HERE //

                Debug.DrawRay(leftIndex.GetRay().origin, leftIndex.GetRay().direction, Color.green);
                leftIndexDirection = leftIndex.GetRay().direction;
                leftIndexPosition  = leftIndex.GetRay().origin;

                // Index Begin Finger Glow
                if (glowingL == false)
                {
                    glowObjectL = Instantiate(fingerGlowObject, leftIndex.GetTipPosition(), fingerGlowObject.transform.rotation);
                    glowingL    = true;

                    Debug.Log("Gun Left");
                }
                else if (glowingL == true && triggerStateL != "fired")
                {
                    // Glow on so update position to finger tip
                    glowObjectL.transform.position = leftIndex.GetTipPosition();
                }

                // Check if Thumb Trigger Primed
                if ((((leftThumb.bones[2].localEulerAngles.z - 360f) > forwardFingerRange + 20f) || (leftThumb.bones[2].localEulerAngles.z < backwardFingerRange)) && triggerStateL == null)
                {
                    triggerStateL = "primed";
                }

                if (!(((leftThumb.bones[2].localEulerAngles.z - 360f) > forwardFingerRange + 20f) || (leftThumb.bones[2].localEulerAngles.z < backwardFingerRange)) && triggerStateL == "primed" && timeStartL == 0)
                {
                    triggerStateL = "fired";

                    // ADD THUMB TRIGGER FUNCTIONALITY HERE //

                    timeStartL = Time.time;
                    glowObjectL.GetComponent <Rigidbody>().AddForce(leftIndex.GetRay().direction * 2, ForceMode.Impulse);

                    // END OF TRIGGER FUNCTIONALITY //

                    triggerStateL = null;
                    glowingL      = false;
                }

                if (Time.time - timeStartL > 2f)
                {
                    //Destroy(glowObjectL);
                }

                // END OF FUNCTIONALITY //
            }
            // If Finger not in Gun Gesture any more
            else
            {
                glowingL      = false;
                timeStartL    = 0f;
                triggerStateL = null;
                Destroy(glowObjectL);
            }
        }
        // If Hand not in object any more
        else
        {
            glowingL      = false;
            timeStartL    = 0f;
            triggerStateL = null;
            Destroy(glowObjectL);
        }

        // RIGHT ACTIVE
        if (stateR == "Active")
        {
            // Index extended and all other fingers not extended
            if (IsExtended(rightIndex) && !IsExtended(rightMiddle) && !IsExtended(rightRing) && !IsExtended(rightPinkie))
            {
                // PLACE WANTED RIGHT SWIPE FUNCTIONALITY HERE //

                Debug.DrawRay(rightIndex.GetRay().origin, rightIndex.GetRay().direction, Color.green);
                rightIndexDirection = rightIndex.GetRay().direction;
                rightIndexPosition  = rightIndex.GetRay().origin;

                //Index Begin Finger Glow
                if (glowingR == false)
                {
                    glowObjectR = Instantiate(fingerGlowObject, rightIndex.GetTipPosition(), fingerGlowObject.transform.rotation);
                    glowingR    = true;

                    Debug.Log("Gun Right");
                }
                else if (glowingR == true && triggerStateR != "fired")
                {
                    //Glow on so update position to finger tip
                    glowObjectR.transform.position = rightIndex.GetTipPosition();
                }

                // Check if Thumb Trigger Primed
                if ((((rightThumb.bones[2].localEulerAngles.z - 360f) > forwardFingerRange + 20f) || (rightThumb.bones[2].localEulerAngles.z < backwardFingerRange)) && triggerStateR == null)
                {
                    triggerStateR = "primed";
                }

                if (!(((rightThumb.bones[2].localEulerAngles.z - 360f) > forwardFingerRange + 20f) || (rightThumb.bones[2].localEulerAngles.z < backwardFingerRange)) && triggerStateR == "primed" && timeStartR == 0f)
                {
                    triggerStateR = "fired";

                    // ADD THUMB TRIGGER FUNCTIONALITY HERE //

                    //timeStartR = Time.time;
                    Destroy(glowObjectR);

                    GameObject shooter = Instantiate(fingerGlowObject, rightIndex.GetTipPosition(), fingerGlowObject.transform.rotation);
                    shooter.GetComponent <Rigidbody>().AddForce(rightIndex.GetRay().direction * 1, ForceMode.Impulse);

                    glowingR      = false;
                    triggerStateR = null;

                    // END OF TRIGGER FUNCTIONALITY //
                }

                if (Time.time - timeStartR > 2f)
                {
                    //Destroy(glowObjectR);
                }

                // END OF FUNCTIONALITY //
            }
            // If Finger not in Gun Gesture any more
            else
            {
                glowingR      = false;
                timeStartR    = 0f;
                triggerStateR = null;
                Destroy(glowObjectR);
            }
        }
        // If Hand not in object any more
        else
        {
            glowingR      = false;
            timeStartR    = 0f;
            triggerStateR = null;
            Destroy(glowObjectR);
        }
    }     // END OF GUN GESTURE
예제 #32
0
    //MOVE
    private void moveObject(Frame oldFrame)
    {
        line.SetColors(Color.blue, Color.white);

//		float originalZ = selectedObject.transform.position.z;

        if (!leap_hand.IsRight)
        {
            return;
        }

        //debugging
        StopCoroutine("MoveLaser");
        StartCoroutine("MoveLaser", middleFinger);


        RaycastHit indexHit;
        RaycastHit middleHit;
        bool       indexRayIntersectingObject  = Physics.Raycast(indexFinger.GetTipPosition(), indexFinger.GetRay().direction, out indexHit);
        bool       middleRayIntersectingObject = Physics.Raycast(middleFinger.GetTipPosition(), middleFinger.GetRay().direction, out middleHit);

//		//must be pointing at selected object
        if ((indexHit.transform.gameObject != selectedObject) && (indexHit.transform.parent.gameObject != selectedObject))
        {
            return;
        }
//
//		float middle_index = Vector3.Distance (indexFinger.GetTipPosition (), middleFinger.GetTipPosition ());
//
//		//both middle and index finger must point to the same object
//		if ((middleHit.transform.gameObject != selectedObject) && (indexHit.transform.parent.gameObject != selectedObject)) {
//			return;
//		}

        float middle_index = Vector3.Distance(indexFinger.GetTipPosition(), middleFinger.GetTipPosition());

        //both fingers must be pointing at the object
        if (middle_index > 0.13)
        {
            return;
        }

//
        Vector deltaZ = leap_hand.Translation(oldFrame);

        Debug.Log(deltaZ);

//		float averageX = (indexHit.point.x + middleHit.point.x)/2;
//		float averageY = (indexHit.point.y + middleHit.point.y)/2;

        float zPos = Mathf.Exp(3 * (indexFinger.GetTipPosition().z + 5)) + originalZPos;

        Debug.Log(zPos);

        //only move along x and y axis
        Vector3 newPos = new Vector3(middleHit.point.x, middleHit.point.y, zPos);

        //debug
//		float averageZ = (indexHit.point.z + middleHit.point.z)/2;
//		Vector3 debugPos = new Vector3 (averageX, averageY, averageZ);
//		Debug.DrawRay (indexFinger.GetTipPosition(), debugPos, Color.red);
//		Debug.DrawRay (middleFinger.GetTipPosition(), debugPos, Color.red);


//		Debug.Log ("index pos: " + indexFinger.GetTipPosition().z);
//
//		float distance = Vector3.Distance (indexFinger.GetTipPosition (), selectedObject.transform.position);
//
//		float zPos = Mathf.Exp(5 * (indexFinger.GetTipPosition ().z + 5));
//
//		Debug.Log (zPos);
//
        selectedObject.transform.position = newPos;
    }
				void AnimateCursor (FingerModel index, FingerModel thumb)
				{
						Vector3 midPosition = (index.GetTipPosition () + thumb.GetTipPosition ()) / 2;
						immediatePosition = (smoothCursor) ? Utils.ExponentialVectorSmoothing (immediatePosition, midPosition, cursorExp) : midPosition;
						if (state == PinchState.Open) {
								cursorPosition = immediatePosition;
						}
						curosrSprite.transform.position = TransformPosition (cursorPosition);
						immediateSprite.transform.position = TransformPosition (immediatePosition);
				}
예제 #34
0
파일: Colors.cs 프로젝트: brunick/VRAR
 // Update is called once per frame
 void Update()
 {
     if (hasSphere)
     {
         try
         {
             fingerModel = col.gameObject.GetComponentInParent<FingerModel>();
             //Colors.sphere.transform.position = fingerModel.GetTipPosition();
             drop.transform.position = fingerModel.GetTipPosition();
             Vector3 pos = drop.transform.position;
             QuizManager.setColorMaterial(bucketMat);
         }
         catch (MissingReferenceException e)
         {
             hasSphere = !hasSphere;
             Destroy(Colors.sphere);
         }
     }
 }
예제 #35
0
    private void parseFrame()
    {
        #region keyTap
        //gets keyTap position

        bool accessoryHit = false;
        //have to create new Raycast, because Visual Studio does not recognize Physics.Raycast as tapHit input and reports error
        RaycastHit tapHit = new RaycastHit();

        if (currentFrame != null && ((currentFrame.Gestures() != null && !currentFrame.Gestures().IsEmpty)))
        {
            foreach (Gesture g in currentFrame.Gestures())
            {
                if (g.Type == Gesture.GestureType.TYPE_KEY_TAP && getRightHand() != null)
                {
                    foreach (Pointable p in g.Pointables)
                    {
                        Finger f = new Finger(p);
                        if (f.Type() != Finger.FingerType.TYPE_INDEX)
                        {
                            continue;
                        }
                        positionOfTap = rightHandController.
                                        transform.TransformPoint(getIndexFinger(getRightHand()).TipPosition.ToUnityScaled());
                        tapActive = true;
                    }
                }
            }
            if (tapActive)
            {
                Ray tapRay;
                if (mode == Modes.Playing)
                {
                    //Index finger
                    Vector3 indexFingerTipPosition = getRightGraphicHand().fingers[1].GetTipPosition();
                    tapRay = new Ray(indexFingerTipPosition, Vector3.down);
                    Debug.DrawLine(new Vector3(711, 10, 117) /*getRightGraphicHand().fingers[1].GetTipPosition()*/, Vector3.down, Color.red, 1000);
                    if (Physics.Raycast(tapRay, out tapHit, 1000))
                    {
                        Debug.Log(tapHit.collider.gameObject);
                    }
                }
                else
                {
                    tapRay = new Ray(positionOfTap, positionOfTap - camera.transform.position);
                }

                if (Physics.Raycast(tapRay, out tapHit, 1000) && tapHit.collider.gameObject.tag == "Accessory")
                {
                    accessoryHit = true;
                }
            }
        }


        #endregion
        //removes or adds tree
        if (tapActive)
        {
            if (accessoryHit)
            {
                terrainAccessories.removeTree(tapHit.collider.gameObject);
                accessoryHit = false;
                TreesRemaining++;
            }
            else
            {
                if (Application.loadedLevel == 5 || TreesRemaining > 0)
                {
                    terrainAccessories.AddTree(tapHit.point);
                    TreesRemaining--;
                }
                tapActive = false;
            }
        }
        //checks for pinch
        Finger     thumb;
        RaycastHit hit;
        HandModel  rightGraphicHand = getRightGraphicHand();
        if (!rightGraphicHand)
        {
            return;
        }
        FingerModel graphicThumb = rightGraphicHand.fingers[0];
        positionOfThumb = graphicThumb.GetTipPosition();
        Ray ray = mouseIsDown ? camera.ScreenPointToRay(Input.mousePosition) : new Ray(positionOfThumb,
                                                                                       positionOfThumb - camera.transform.position);
        Vector3 tempCoord = new Vector3(0, 0, 0);
        if (Physics.Raycast(ray, out hit, 1000, terrainLayerMask))
        {
            tempCoord = hit.point;
        }

        //if correct gesture is detected
        if (checkForPinch(currentFrame, out thumb, 25))
        {
            //pinch detected but hand not in scene, so something is wrong
            if (rightGraphicHand == null || rightGraphicHand.fingers.Length == 0)
            {
                Debug.Log("graphicHand not found");
                pinchActive = false;
                return;
            }
            pinchActive = true;
            if (mode == Modes.Editor)
            {
                if (thumb.TipPosition.y > 160)
                {
                    heightChange = 0.001f;
                }
                else
                {
                    if (thumb.TipPosition.y <= 160)
                    {
                        heightChange = -0.001f;
                    }
                    else
                    {
                        heightChange = 0;
                    }
                }
            }
        }
        else
        {
            pinchActive = false;
        }


        //raise ground
        // get the normalized position of hit relative to the terrain
        Vector3 coord;
        coord.x = tempCoord.x / terrain.terrainData.size.x;
        coord.y = tempCoord.z / terrain.terrainData.size.z;

        // get the position of the terrain heightmap where hit is
        posXInTerrain = (int)(coord.x * hmWidth);
        posYInTerrain = (int)(coord.y * hmHeight);
        // we set an offset so that all the raising terrain is under this point, rather than at edge
        if (mode == Modes.Editor && posXInTerrain + size < hmWidth && posYInTerrain + size < hmHeight && posXInTerrain > 0 && posYInTerrain > 0 &&
            (pinchActive || mouseIsDown))
        {
            if (!pinchActive && mouseIsDown)
            {
                heightChange = 0.001f;
            }
            RaiseGround();
        }
    }