/// <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); }
// 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(); }
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 { } } }
//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); }
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; * }*/ } }
// 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); } }
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); } }
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; } } } }
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; } }
void FixedUpdate() { // If findger touch this bool standby_gesture = extendedFingerDetector.IsActive; if (standby_gesture) { //if (Input.GetMouseButtonDown(0)) { dragging = false; Ray ray = index.GetRay(); RaycastHit hit; //if (GetComponent<Collider>().Raycast(ray, out hit, Mathf.Infinity)) { if (GetComponent <Collider>().Raycast(ray, out hit, .05f)) { dragging = true; } } // If finger is not there if ((standby_gesture = extendedFingerDetector.IsActive) != true) { dragging = false; } //if (Input.GetMouseButtonUp(0)) dragging = false; if (dragging && standby_gesture) { Ray ray = index.GetRay(); RaycastHit hit; //if (GetComponent<Collider>().Raycast(ray, out hit, Mathf.Infinity)) if (GetComponent <Collider>().Raycast(ray, out hit, .05f)) { //var point = Camera.main.ScreenToWorldPoint(Input.mousePosition); var point = hit.point; point = GetComponent <Collider>().ClosestPointOnBounds(point); SetThumbPosition(point); SendMessage("OnDrag", Vector3.one - (thumb.position - GetComponent <Collider>().bounds.min) / GetComponent <Collider>().bounds.size.x); } } }
private void UpdateMouseOver() { //If its my turn if (!Camera.main) { Debug.Log("Unable to find main camera!"); return; } RaycastHit hit; if (Physics.Raycast(_pinchDetectorA.Position, fingerLeft.GetRay().direction, out hit, 25.0f, LayerMask.GetMask("Board")) || Physics.Raycast(_pinchDetectorB.Position, fingerRight.GetRay().direction, out hit, 25.0f, LayerMask.GetMask("Board")) || Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f, LayerMask.GetMask("Board"))) { mouseOver.x = (int)(hit.point.x - boardOffset.x); mouseOver.y = (int)(hit.point.z - boardOffset.z); } else { mouseOver.x = -1; mouseOver.y = -1; } }
int GetDirection(FingerModel finger0) { float AngleUp = Vector3.Angle(finger0.GetRay().direction, cam.transform.up); float AngleLeft = Vector3.Angle(finger0.GetRay().direction, cam.transform.right * -1); float AngleRight = Vector3.Angle(finger0.GetRay().direction, cam.transform.right); // Debug.Log("UP: " + AngleUp); // Debug.Log("Left: " + AngleLeft); // Debug.Log("Right: " + AngleRight); if (AngleLeft < AngleUp && AngleLeft < AngleRight) { return(-1); } else if (AngleUp < AngleLeft && AngleUp < AngleRight) { return(0); } else { return(1); } }
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; }
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; } } }
// 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); } }
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; }
//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 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
void Update() { ClearDirection(); //for (int i = 0; i < HandModel.NUM_FINGERS; i++) //{ Transform p = hand_model.palm; //finger0 = hand_model.fingers[0]; //finger = hand_model.fingers[1]; // draw ray from finger tips (enable Gizmos in Game window to see) Debug.DrawRay(finger0.GetTipPosition(), finger0.GetRay().direction, Color.red); Debug.DrawRay(p.position, p.transform.up, Color.red); //Debug.Log(p.transform.up); //Debug.Log(finger.GetTipPosition()); //Debug.Log(Vector3.Distance(finger0.GetTipPosition(), finger.GetTipPosition())); int direction = GetDirection(finger0); // if (palmx > -0.2f && palmx < 0.2f && palmy < -0.8f && isLeft) // { // Debug.Log("Left"); // } // if(palmx > -0.2f && palmx < 0.2f && palmy > 0.8f && isLeft) // { // Debug.Log("Right"); // } bool flag = true; bool forward = true; bool error = false; for (int i = 1; i < 5; i++) { FingerModel f = hand_model.fingers[i]; if (Vector3.Distance(f.GetTipPosition(), p.position) > 0.15) { if (!error) { error = true; } else { flag = false; break; } } } for (int i = 1; i < 5; i++) { FingerModel f = hand_model.fingers[i]; if (i == 1) { if (Vector3.Distance(f.GetTipPosition(), p.position) < 0.2) { forward = false; break; } } else { if (Vector3.Distance(f.GetTipPosition(), p.position) > 0.2) { forward = false; break; } } } ClearDirection(); if (isLeft) { if (forward) { // Debug.Log("forward"); MoveForward = true; if (direction == 0) { Jump = true; } } else if (flag) { if (direction == -1) { RotateLeft = true; // Debug.Log("Left"); } else if (direction == 0) { Jump = true; // Debug.Log("Jump"); } else { RotateRight = true; // Debug.Log("Right"); } // Debug.Log("Forward"); // float fx = finger0.GetRay().direction.x; // float fy = finger0.GetRay().direction.y; //Debug.Log(finger0.GetRay().direction); // if (fx > -0.2f && fx < 0.2f && fy > 0.8f) // { // Debug.Log("Jump"); // } } else { // Debug.Log("Neutral"); } } if (Vector3.Distance(finger0.GetTipPosition(), finger2.GetTipPosition()) < 0.02 && !isLeft) { Pinch = true; GetRaycast(); } else { Pinch = false; if (modify != null) { modify.pinch = Pinch; } } if (!isLeft) { ShootFromTargetPosition(finger1.GetTipPosition(), finger1.GetRay().direction, laserMaxLength); } //} }