void updateColorSelectionBar() { if (hue && hue.activeSelf) { hue.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f; hue.transform.rotation = leftHandModel.GetPalmRotation(); } }
private void DrawDebugLines() { HandModel hand = GetComponent <HandModel>(); Debug.DrawLine(hand.GetElbowPosition(), hand.GetWristPosition(), Color.red); Debug.DrawLine(hand.GetWristPosition(), hand.GetPalmPosition(), Color.white); Debug.DrawLine(hand.GetPalmPosition(), hand.GetPalmPosition() + hand.GetPalmNormal(), Color.black); Debug.Log(Vector3.Dot(hand.GetPalmDirection(), hand.GetPalmNormal())); }
void Start() { handmodel = GetComponent<HandModel>(); _grabedObj = null; palmPostion = handmodel.GetPalmPosition(); velocity = Vector3.zero; }
protected void UpdateTracker() { //get the 1st hand in the frame if (handController.GetAllGraphicsHands().Length != 0) { handModel = handController.GetAllGraphicsHands()[0]; handModel.transform.GetComponentInChildren <SkinnedMeshRenderer>().enabled = visibleHand; hand = handModel.GetLeapHand(); Position = handModel.GetPalmPosition(); Rotation = handModel.GetPalmRotation(); float grabStrength = handModel.GetLeapHand().GrabStrength; if (grabStrength >= 0.9) { Grab = true; } else if (grabStrength <= 0.75) { Grab = false; } } //mask/display the graphical hand on key down if (Input.GetKeyDown(visibleHandKey)) { var smr = handModel.transform.GetComponentInChildren <SkinnedMeshRenderer>(); visibleHand = !visibleHand; } }
protected override void UpdateTracker() { previousPosition = Position; previousOrientation = Orientation; previousGrabbingStrength = currentGrabbingStrength; //get the rightmost hand in the frame if (handController.GetAllGraphicsHands().Length != 0) { handModel = handController.GetAllGraphicsHands()[0]; handModel.transform.GetComponentInChildren<SkinnedMeshRenderer>().enabled = visibleHand; hand = handModel.GetLeapHand(); currentGrabbingStrength = lowPassFilter(hand.GrabStrength, previousGrabbingStrength); Position = lowPassFilter(handModel.GetPalmPosition(), previousPosition); Orientation = lowPassFilter(handModel.GetPalmDirection(), previousOrientation); } //mask/display the graphical hand on key down if (Input.GetKeyDown(visibleHandKey)) { var smr = handModel.transform.GetComponentInChildren<SkinnedMeshRenderer>(); visibleHand = !visibleHand; } Translation = Position - previousPosition; Rotation = previousOrientation - Orientation; }
protected void UpdateGraspPosition() { HandModel handModel = this.GetComponent <HandModel>(); // our grasp center only depends on thumb and index finger for stability reasons this.CurrentGraspCenter = 0.5f * (handModel.fingers[0].GetTipPosition() + handModel.fingers[1].GetTipPosition()); if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null) { // not the best style, but this hardcoded rule creates a grasp center near the palm, // if you would rather use a pinch, than just take the centroid of the thumb (index 0) // and the index finger (index 1) /*this.CurrentGraspCenter = ( * handModel.fingers[0].GetTipPosition() * .2f + * handModel.fingers[1].GetTipPosition() * .2f + * handModel.GetPalmPosition() * .6f);*/ /*this.CurrentGraspCenter = ( * (handModel.fingers[0].GetTipPosition() + * handModel.fingers[1].GetTipPosition() + * handModel.fingers[2].GetTipPosition() + * handModel.fingers[3].GetTipPosition() + * handModel.fingers[4].GetTipPosition() ) *.2f * .4f + * handModel.GetPalmPosition() * .6f);*/ this.CurrentGraspCenter = handModel.GetPalmPosition() + handModel.GetPalmNormal() * .025f; } Vector3 graspDelta = this.CurrentGraspCenter - this.SmoothedGraspPosition; this.SmoothedGraspPosition += (1.0f - this.PositionFiltering) * graspDelta; }
// Update is called once per frame void Update() { hand = transform.GetComponent <HandModel> (); //Somente deve funcionar na mão escolhida, direita ou esquerda if (maoCerta) { for (int i = 0; i < 2; i++) { dedos [i] = hand.fingers [i + 1].GetBoneCenter(3); distancias [i] = (dedos [i] - hand.GetPalmPosition()).magnitude; //distâncias dos dedos à palma da mão } //Verifica se a mão está fechada e próxima da base ou se o usuário quer ter que alcançar a seringa para pega-la if (pegando()) { if ((hand.GetPalmPosition() - baseSeringaPosition).magnitude < distBaseSeringa || !GetComponentInParent <escolherMao> ().alcançarSeringa) { pegou = true; } } //"Prende" a seringa à palma da mão, utilizando sua posição e rotação + ajustes if (pegou) { seringa.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * distSeringa.x + Vector3.Cross(hand.GetPalmDirection(), hand.GetPalmNormal()).normalized *distSeringa.y + hand.GetPalmDirection() * distSeringa.z; seringa.transform.rotation = hand.GetPalmRotation() * rotSeringa; GetComponentInParent <escolherMao> ().Congelar(); } //Solta a seringa de volta a base else { seringa.transform.position = baseSeringaPosition; seringa.transform.rotation = baseSeringaRotation; } //Verifica se a mão está aberta e próxima da base da seringa ou se o usuário quer soltar a seringa a qualquer momento if (soltando()) { if ((hand.GetPalmPosition() - baseSeringaPosition).magnitude < distBaseSeringa || !GetComponentInParent <escolherMao> ().alcançarSeringa) { pegou = false; } } } }
Vector3 GetFireBallSpawnPosition(HandModel hand, float distance){ Vector3 palmPos = hand.GetPalmPosition (); Vector3 palmDir = hand.GetPalmNormal (); return palmPos + Vector3.Scale(palmDir,new Vector3(distance,distance,distance)); }
public static Vector3 DirectionBetweenPalm(HandModel fromHand, HandModel toHand){ Vector3 fromHandPalmPos = fromHand.GetPalmPosition (); Vector3 toHandPalmPos = toHand.GetPalmPosition (); return Math3dExt.Direction (fromHandPalmPos, toHandPalmPos); }
void CastBolts(HandModel leftHand, HandModel rightHand ){ if (!IsCastingStarted && !spellControl.SpellCasting()) { Vector3 middle = leftHand.GetPalmPosition () + rightHand.GetPalmPosition (); currentThunderBolt = GameObject.Instantiate (thunderBoltPrefab, middle, gameObject.transform.rotation) as ThunderBolt; currentThunderBolt.SetPosition (leftHand.GetPalmPosition (), rightHand.GetPalmPosition ()); IsCastingStarted = true; spellControl.GrabCastingControl (); } }
public static float DistanceBetweenPalms(HandModel handOne, HandModel handTwo){ Vector3 handOnePalmPos = handOne.GetPalmPosition(); Vector3 handTwoPalmPos = handTwo.GetPalmPosition (); return Math3dExt.Distance (handOnePalmPos, handTwoPalmPos); }
void Update() { if (active && isRight) { line.SetPosition(0, hand_model.GetPalmPosition()); line.SetPosition(1, (hand_model.GetPalmDirection() * 20f));//+ 2 * hand_model.GetPalmPosition());// * finger.GetTipPosition()); rr.origin = hand_model.GetPalmPosition(); rr.direction = hand_model.GetPalmDirection(); int bitLayer = 1 << 15; if (Physics.Raycast(hand_model.GetPalmPosition(), hand_model.GetPalmDirection(), out hit, Mathf.Infinity, bitLayer)) { if (hit.collider.CompareTag("ViewTable")) { hit.collider.gameObject.GetComponent <Table>().AltActivation(); } } } }
// Update is called once per frame void Update() { //Debug.Log("index --> " + _indexColliding); //Debug.Log("thumb --> " + _thumbColliding); if (isGrabbed) { HandModel handModel = followObject.GetComponent <HandModel>(); Vector3 pos = handModel.GetPalmPosition().ToVector().ToVector3(); Debug.Log("is grabbed by " + handModel.name); Debug.Log("position -> " + pos.ToString()); gameObject.transform.position = pos; } }
public bool HorizonCheck(HandModel hand) { Ray ray = new Ray(m_rayRoot.position, (hand.GetPalmPosition() - m_rayRoot.position).normalized); Debug.DrawRay(m_rayRoot.position, ray.direction * 10000.0f, new Color(1.0f, 0.0f,0.0f)); RaycastHit hitInfo; LayerMask mask = LayerMask.GetMask("Earth"); bool hit = Physics.Raycast(ray, out hitInfo, 10000.0f, mask); if ( hit ) { return true; } else { return false; } }
void HandleHandEvent(object sender, LMWidgets.EventArg <HandData> e) { if (e.CurrentValue.HasHand) { HandModel hand = e.CurrentValue.HandModel; Vector3 pivot = hand.GetPalmPosition(); Vector3 normal = pivot + hand.GetPalmNormal(); Vector3 axis = upTarget.transform.position; FloatValue = Vector3.Dot((normal - pivot).normalized, (axis - pivot).normalized); } else { FloatValue = -1; } }
public void Update() { // if (handModel == null) return; RaycastHit hit; if (brushActive) { paintBrush.SetActive(true); palmPos = handModel.GetPalmPosition(); fwd = handModel.GetPalmNormal(); headPos = new Vector3(Camera.main.transform.position.x + headOffset, Camera.main.transform.position.y, Camera.main.transform.position.z); destination = tracker.position - headPos; Debug.Log("BRUSH IS ACTIVE!"); if (Physics.Raycast(Camera.main.transform.position, destination, out hit, Mathf.Infinity, lm)) { Debug.DrawRay(Camera.main.transform.position, destination, Color.red); filter = hit.collider.GetComponent <MeshFilter>(); if (filter) { selectedTransform = hit.collider.transform; Debug.Log("Current object: " + selectedTransform.gameObject.name); if (filter != unappliedMesh) { ApplyMeshCollider(); unappliedMesh = filter; //historyFilters.Add(filter); } Vector3 relativePoint = filter.transform.InverseTransformPoint(hit.point); DeformMesh(filter.mesh, relativePoint, pull * Time.deltaTime, radius); paintBrush.transform.position = hit.point; } } } else { paintBrush.SetActive(false); ApplyMeshCollider(); return; } }
protected void UpdateGraspPosition() { HandModel handModel = this.GetComponent <HandModel>(); // our grasp center only depends on thumb and index finger for stability reasons this.CurrentGraspCenter = 0.5f * (handModel.fingers[0].GetTipPosition() + handModel.fingers[1].GetTipPosition()); if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null) { this.CurrentGraspCenter = handModel.GetPalmPosition() + handModel.GetPalmNormal() * .025f; } Vector3 graspDelta = this.CurrentGraspCenter - this.SmoothedGraspPosition; this.SmoothedGraspPosition += (1.0f - this.PositionFiltering) * graspDelta; }
public bool HorizonCheck(HandModel hand) { Ray ray = new Ray(m_rayRoot.position, (hand.GetPalmPosition() - m_rayRoot.position).normalized); Debug.DrawRay(m_rayRoot.position, ray.direction * 10000.0f, new Color(1.0f, 0.0f, 0.0f)); RaycastHit hitInfo; LayerMask mask = LayerMask.GetMask("Earth"); bool hit = Physics.Raycast(ray, out hitInfo, 10000.0f, mask); if (hit) { return(true); } else { return(false); } }
public void FixedUpdate() { if (graphicsEnabled) { UpdateHandRepresentations(); if (ikActive) { if (leftActive && leftHand != null) { RiggedHand l = leftHand as RiggedHand; vrIK.solver.leftArm.IKPosition = leftHand.GetPalmPosition(); vrIK.solver.leftArm.IKRotation = leftHand.GetPalmRotation() * l.Reorientation(); vrIK.solver.leftArm.positionWeight = 1.0f; vrIK.solver.leftArm.rotationWeight = 0.0f; leftTransform.Enabled = true; } else { vrIK.solver.leftArm.positionWeight = 0.0f; vrIK.solver.leftArm.rotationWeight = 0.0f; leftTransform.Enabled = false; } if (rightActive && rightHand != null) { RiggedHand r = rightHand as RiggedHand; vrIK.solver.rightArm.IKPosition = rightHand.GetPalmPosition(); vrIK.solver.rightArm.IKRotation = rightHand.GetPalmRotation() * r.Reorientation(); vrIK.solver.rightArm.positionWeight = 1.0f; vrIK.solver.rightArm.rotationWeight = 0.0f; rightTransform.Enabled = true; } else { vrIK.solver.rightArm.positionWeight = 0.0f; vrIK.solver.rightArm.rotationWeight = 0.0f; rightTransform.Enabled = false; } } } }
void Update() { if (handModel == null) { return; } Vector3 palmPos = handModel.GetPalmPosition(); if (!pickedUp) { Debug.Log("Picked up !"); RaycastHit hit; Vector3 fwd = handModel.GetPalmNormal(); Vector3 destination = tracker.position - palmPos; if (Physics.Raycast(palmPos, destination, out hit, Mathf.Infinity)) { float distanceToGround = hit.distance; Debug.Log("Hitting " + hit); Debug.DrawRay(palmPos, destination, Color.red); deformer = hit.collider.GetComponent <MeshDeformer>(); if (deformer) { tracker.SetParent(null); deformPoint = hit.point; deformPoint += hit.normal * forceOffset; pickedUp = true; inTransport = true; } } } if (inTransport) { deformer.AddDeformingForce(deformPoint, force * Vector3.Distance(tracker.transform.position, palmPos)); } }
private void OnPinch(Vector3 pinch_position) { pinching_ = true; // Check if we pinched a movable object and grab the closest one that's not part of the hand. Collider[] close_things = Physics.OverlapSphere(pinch_position, grabDistance); Vector3 distance = new Vector3(grabDistance, 0.0f, 0.0f); HandModel hand_model = GetComponent <HandModel>(); for (int j = 0; j < close_things.Length; ++j) { Vector3 new_distance = pinch_position - close_things[j].transform.position; if (close_things[j].GetComponent <Rigidbody>() != null && new_distance.magnitude < distance.magnitude && !close_things[j].transform.IsChildOf(transform)) { grabbed_ = close_things[j]; distance = new_distance; } } if (grabbed_ != null) { grabbed_.GetComponent <Rigidbody>().maxAngularVelocity = Mathf.Infinity; grabbed_.GetComponent <Rigidbody>().detectCollisions = false; palm_rotation_ = hand_model.GetPalmRotation(); palm_position_ = hand_model.GetPalmPosition(); start_rotation_ = grabbed_.transform.rotation * Quaternion.Inverse(palm_rotation_); start_position_ = Quaternion.Inverse(palm_rotation_) * (grabbed_.transform.position - palm_position_); Grabbable grabbable = grabbed_.GetComponent <Grabbable>(); if (grabbable != null) { grabbable.OnGrab(); } } }
// Update is called once per frame void Update() { if (handModel != null) { if (this.GetComponent <Collider>().bounds.Contains(handModel.GetPalmPosition())) { if (!handIsSet) { ControlHandTracker.getInstance().setControllingHandIsRight(!handModel.GetLeapHand().IsRight); handIsSet = true; } bool res = Vector3.Cross(handModel.GetLeapHand().PalmNormal.ToVector3(), Vector3.forward).x > 0; if (res != facingUp) { Debug.Log("palm facing Up : " + res); facingUp = res; MidiController.getInstance().setPalmFacingUp(facingUp); } bool closed = handModel.GetLeapHand().GrabStrength > 0.6; if (closed != handIsClosed) { Debug.Log("hand is closed : " + closed); handIsClosed = closed; ControlHandTracker.getInstance().setStaticHandIsClosed(handIsClosed); } } else if (handIsSet) { handIsSet = false; ControlHandTracker.getInstance().stopTracking(); foreach (MeshRenderer child in gameObject.GetComponentsInChildren <MeshRenderer>()) { child.material.color = Color.white; } } } }
private void UpdateHandModels(Dictionary <int, HandModel> all_hands, HandList leap_hands, HandModel left_model, HandModel right_model) { List <int> ids_to_check = new List <int>(all_hands.Keys); // Go through all the active hands and update them. int num_hands = leap_hands.Count; if (num_hands == 0) { RightMostHandPosition = LeftMostHandPosition = 0; } for (int h = 0; h < num_hands; ++h) { Hand leap_hand = leap_hands[h]; HandModel model = leap_hand.IsLeft? left_model : right_model; // Only create or update if the hand is enabled. if (model != null) { ids_to_check.Remove(leap_hand.Id); // Create the hand and initialized it if it doesn't exist yet. if (!all_hands.ContainsKey(leap_hand.Id)) { HandModel new_hand = CreateHand(model); new_hand.SetLeapHand(leap_hand); new_hand.SetController(this); // Set scaling based on reference hand. float hand_scale = leap_hand.PalmWidth / MODEL_PALM_WIDTH; new_hand.transform.localScale = hand_scale * transform.localScale; new_hand.InitHand(); new_hand.UpdateHand(); all_hands[leap_hand.Id] = new_hand; model = new_hand; } else { // Make sure we update the Leap Hand reference. HandModel hand_model = all_hands[leap_hand.Id]; hand_model.SetLeapHand(leap_hand); // Set scaling based on reference hand. float hand_scale = leap_hand.PalmWidth / MODEL_PALM_WIDTH; hand_model.transform.localScale = hand_scale * transform.localScale; hand_model.UpdateHand(); model = hand_model; } if (h == 0) { RightMostHandPosition = LeftMostHandPosition = model.GetPalmPosition().x; } RightMostHandPosition = model.GetPalmPosition().x > RightMostHandPosition?model.GetPalmPosition().x : RightMostHandPosition; LeftMostHandPosition = model.GetPalmPosition().x < LeftMostHandPosition?model.GetPalmPosition().x : LeftMostHandPosition; } } InterpolateKeys.UpdateHands(num_hands); // Destroy all hands with defunct IDs. for (int i = 0; i < ids_to_check.Count; ++i) { Destroy(all_hands[ids_to_check[i]].gameObject); all_hands.Remove(ids_to_check[i]); } if (DateTime.Now.Subtract(prevLogTime).TotalSeconds >= 1) { prevLogTime = DateTime.Now; if (LeftMostHandPosition < LeftBorder && RightMostHandPosition > RightBorder) { return; } Main.CameraTargetPos = Camera.main.transform.position; if (LeftMostHandPosition < LeftBorder) { Tools.ShiftView(Tools.Direction.Left); } if (RightMostHandPosition > RightBorder) { Tools.ShiftView(Tools.Direction.Right); } } }
public Vector3 MiddleBetweenPalms(HandModel handOne, HandModel handTwo){ return Math3dExt.MidPosition (handOne.GetPalmPosition (), handTwo.GetPalmPosition ()); }
void Update() { bool trigger_pinch = false; HandModel hand_model = GetComponent <HandModel>(); Hand leap_hand = hand_model.GetLeapHand(); if (leap_hand == null) { return; } // Scale trigger distance by thumb proximal bone length. Vector leap_thumb_tip = leap_hand.Fingers[0].TipPosition; float proximal_length = leap_hand.Fingers[0].Bone(Bone.BoneType.TYPE_PROXIMAL).Length; float trigger_distance = proximal_length * TRIGGER_DISTANCE_RATIO; // Check thumb tip distance to joints on all other fingers. // If it's close enough, start pinching. for (int i = 1; i < HandModel.NUM_FINGERS && !trigger_pinch; ++i) { Finger finger = leap_hand.Fingers[i]; for (int j = 0; j < FingerModel.NUM_BONES && !trigger_pinch; ++j) { Vector leap_joint_position = finger.Bone((Bone.BoneType)j).NextJoint; if (leap_joint_position.DistanceTo(leap_thumb_tip) < trigger_distance) { trigger_pinch = true; } } } Vector3 pinch_position = 0.5f * (hand_model.fingers[0].GetTipPosition() + hand_model.fingers[1].GetTipPosition()); // Only change state if it's different. if (leap_hand.Confidence >= minConfidence && leap_hand.PalmVelocity.ToUnityScaled().magnitude <= maxVelocity) { if (trigger_pinch && !pinching_) { OnPinch(pinch_position); } else if (!trigger_pinch && pinching_) { OnRelease(); } } // Accelerate what we are grabbing toward the pinch. if (grabbed_ != null) { Grabbable grabbable = grabbed_.GetComponent <Grabbable>(); palm_rotation_ = Quaternion.Slerp(palm_rotation_, hand_model.GetPalmRotation(), 1.0f - filtering); Vector3 delta_palm_position = hand_model.GetPalmPosition() - palm_position_; palm_position_ += (1 - filtering) * delta_palm_position; Vector3 target_position = pinch_position; Quaternion target_rotation = palm_rotation_ * start_rotation_; if (grabbable != null) { if (grabbable.keepDistanceWhenGrabbed) { target_position = palm_position_ + palm_rotation_ * start_position_; } if (grabbable.preferredOrientation) { Quaternion relativeToPalm = Quaternion.FromToRotation(grabbable.objectOrientation, grabbable.palmOrientation); target_rotation = palm_rotation_ * relativeToPalm; } } Vector3 velocity = (target_position - grabbed_.transform.position) / Time.fixedDeltaTime; grabbed_.GetComponent <Rigidbody>().velocity = velocity; Quaternion delta_rotation = target_rotation * Quaternion.Inverse(grabbed_.transform.rotation); float angle = 0.0f; Vector3 axis = Vector3.zero; delta_rotation.ToAngleAxis(out angle, out axis); if (angle >= 180) { angle = 360 - angle; axis = -axis; } if (angle != 0) { grabbed_.GetComponent <Rigidbody>().angularVelocity = angle * axis; } } }
private void onHandEvent(object sender, LMWidgets.EventArg <HandData> e) { if (!e.CurrentValue.HasHand) { if (m_activeObject != null) { m_activeObject.GetComponent <Renderer>().enabled = false; } return; } else { if (m_activeObject != null) { m_activeObject.GetComponent <Renderer>().enabled = true; } } HandModel hand = e.CurrentValue.HandModel; transform.rotation = hand.GetPalmRotation(); transform.position = hand.GetPalmPosition() + (transform.up * IconOffsetDistance); // Transition logic below here. if (ModalityManager.Instance.HasActiveItem()) { if (ModalityManager.Instance.ActiveItemName == "ARMHUD" && m_activeObject != null || ModalityManager.Instance.ActiveItemName == "Joyball" && m_activeObject != null) { m_activeObject = null; //Debug.Log("Go None"); StopAllCoroutines(); StartCoroutine(transitionOut(switchToNone)); } return; } bool aboveHorizon = !m_raycastEmitter.RayCheck(hand.GetPalmPosition()); if (aboveHorizon && !m_wasAboveHorizon || (aboveHorizon && m_activeObject == null)) { if (m_activeObject == null) { m_activeObject = m_constellationIcon; } StopAllCoroutines(); StartCoroutine(transitionOut(switchToConstellation)); } // else if (!aboveHorizon && m_wasAboveHorizon || (!aboveHorizon && m_activeObject == null) ) { else if (!aboveHorizon && m_wasAboveHorizon) { if (m_activeObject == null) { m_activeObject = null; } StopAllCoroutines(); // DECISION: Joyball icon is NOT needed due to the affordance presented by the JoyBall itself // StartCoroutine(transitionOut(switchToJoyball)); StartCoroutine(transitionOut(switchToNone)); // StartCoroutine(transitionOut(switchToGrabCycle)); } m_wasAboveHorizon = aboveHorizon; }
public void juego_oculus() { //moverseOculus(); moverse2Oculus(); if (Mano_derecha.IsTracked) { /* * CALCULAR ACELERACION MANO */ if (tiempo_cal_ac < 0) { Vector3 posicion_actual = Mano_derecha.GetPalmPosition(); Vector3 aceleracion_actual = posicion_actual - pos_mano; pos_mano = posicion_actual; tiempo_cal_ac = 0.2f; if (aceleraciones.Count > 4) { aceleraciones.Remove(aceleraciones[0]); } aceleraciones.Add(aceleracion_actual); Vector3 aceleracion_media = new Vector3(0, 0, 0); for (int i = 0; i < aceleraciones.Count; i++) { aceleracion_media += aceleraciones[i]; } aceleracion_leap = aceleracion_media / aceleraciones.Count; } else { tiempo_cal_ac -= Time.deltaTime; } /* * SI TENEMOS UN OBJETO COGIDO / LANZAMIENTO / SOLTAR * */ if (seleccionado) { Debug.Log("cogido"); if (Mano_derecha.GetLeapHand().PinchStrength <= 0.5 && tiempo > 1f) { seleccionado = false; temp_transform.transform.position = Mano_derecha.GetPalmPosition(); temp_transform.transform.rotation = Mano_derecha.GetPalmRotation(); GameObject aux_aceleracion = new GameObject(); /*aux_aceleracion.transform.position = aceleracion_leap;*/ aux_aceleracion.transform.position = Mano_derecha.GetLeapHand().PalmVelocity.ToVector3(); interactuable.GetComponent <Interactuable>().suelta(temp_transform.transform, aux_aceleracion.transform); Destroy(aux_aceleracion); interactuable = null; } else { temp_transform.transform.position = Mano_derecha.GetPalmPosition(); temp_transform.transform.rotation = Mano_derecha.GetPalmRotation(); interactuable.GetComponent <Interactuable>().mueve(temp_transform.transform); } } else { /* * RECOGER OBJETO DE LIBRE USO * */ objeto_mover_oculus(); boton_oculus(); } } else { /*no tenemos mano detectada */ if (seleccionado) { Debug.Log("mano no detectada"); seleccionado = false; GameObject aux_aceleracion = new GameObject(); aceleracion_leap = new Vector3(0, 0, 0); aux_aceleracion.transform.position = aceleracion_leap; interactuable.GetComponent <Interactuable>().suelta(temp_transform.transform, aux_aceleracion.transform); Destroy(aux_aceleracion); interactuable = null; } } }
void Update() { Frame frame = provider.CurrentFrame; List <Hand> hands = frame.Hands; HandModel hml = FindObjectOfType <HandModel> (); StateMachine StateMachineFlags = StateMachine.GetComponent <StateMachine>(); if (hands.Count == 1) { for (int h = 0; h < hands.Count; h++) { Hand hand = hands [h]; //--------------------------------------------------------------------------------------------- if (hand.IsLeft) { l_strength = hand.GrabStrength; l_palmPos = hml.GetPalmPosition(); //Raycast if (!l_ObjectHeld && (StateMachineFlags.TrainFlag == 1)) { l_ObjectDetected = false; RaycastHit l_hit; bool hitornot = Physics.Raycast(l_palmPos, hml.GetPalmNormal(), out l_hit, 20); if (hitornot) { l_pickup = l_hit.transform.gameObject; l_ObjectDetected = true; } // ATTACH TO HAND if ((l_ObjectDetected) && (l_strength > l_curr_strength / 100)) { l_ObjectHeld = true; l_pickup_pos = l_hit.transform.position; } } //KEEP TO Hand if (l_ObjectHeld && l_strength > l_curr_strength / 100) { l_pickup.transform.position = l_palmPos + (hml.GetPalmNormal()) / 8; } else if (l_strength < l_curr_strength / 100) { if (l_ObjectHeld) { l_pickup_release_pos = l_palmPos; } l_ObjectHeld = false; } } //-------------------------------------------------------------------------------------- if (hand.IsRight) { r_strength = hand.GrabStrength; r_palmPos = hml.GetPalmPosition(); //Apply Raycast only if object not held if (!r_ObjectHeld && (StateMachineFlags.TrainFlag == 1)) { r_ObjectDetected = false; RaycastHit r_hit; if (Physics.Raycast(r_palmPos, hml.GetPalmNormal(), out r_hit, 20)) { r_pickup = r_hit.transform.gameObject; r_ObjectDetected = true; } // ATTACH TO HAND if ((r_ObjectDetected) && (r_strength > r_curr_strength / 100)) { r_ObjectHeld = true; r_pickup_pos = r_hit.transform.position; //Debug.Log ("Right Pick Up"+r_pickup_pos); //Debug.Log ("Right Pick Up tag"+ r_pickup.tag); } } //KEEP IN Hand if (r_ObjectHeld && r_strength > r_curr_strength / 100) { r_pickup.transform.position = r_palmPos + (hml.GetPalmNormal()) / 8; } else if (r_strength < r_curr_strength / 100) { if (r_ObjectHeld) { r_pickup_release_pos = r_palmPos; } r_ObjectHeld = false; } } HapticFeedback HapticFlags = Haptics.GetComponent <HapticFeedback>(); if (l_ObjectHeld || r_ObjectHeld) { HapticFlags.HapticPalmFeedback = 1; } if (l_ObjectHeld == false && r_ObjectHeld == false && HapticFlags.HapticPalmFeedback == 1) { HapticFlags.HapticPalmFeedback = 0; } //---------------------------------------------------------------------------------------- } } //end of if } //End of update
void updateLeftHand() { Vector3 upCam = mainCamera.transform.up; float difference = Vector3.Angle(leftHandModel.GetPalmNormal(), upCam); if (difference < MAX_ANGLE_DIFFERENCE_FOR_INTERFACE && leftHand.activeSelf) { if (leftHandInterfaceActive) { //Update the position, rotation, and color if (hue && hue.activeSelf) { hue.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f; hue.transform.rotation = leftHandModel.GetPalmRotation(); } if (alpha && alpha.activeSelf) { alpha.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f; alpha.transform.rotation = leftHandModel.GetPalmRotation(); } if (saturation && saturation.activeSelf) { saturation.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f; saturation.transform.rotation = leftHandModel.GetPalmRotation(); } } else { //Spawn in the light, 3 selectors, and sphere. //update each position, rotation, and color if (hue) { hue.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f; hue.transform.rotation = leftHandModel.GetPalmRotation(); hue.SetActive(true); } else if (huePrefab) { hue = (GameObject)Instantiate(huePrefab, leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f, leftHandModel.GetPalmRotation()); hueSliderHeightPercentage = 0.5f; updateColorSelected(); } if (alpha) { alpha.SetActive(true); } else if (alphaPrefab) { alpha = (GameObject)Instantiate(alphaPrefab, leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f, leftHandModel.GetPalmRotation()); } if (saturation) { saturation.SetActive(true); } else if (saturationPrefab) { saturation = (GameObject)Instantiate(saturationPrefab, leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f, leftHandModel.GetPalmRotation()); } leftHandInterfaceActive = true; } } else { if (leftHandInterfaceActive) { if (!leftHand.activeSelf || difference >= MAX_ANGLE_DIFFERENCE_FOR_INTERFACE) { if (hue) { hue.SetActive(false); } if (saturation) { saturation.SetActive(false); } if (alpha) { alpha.SetActive(false); } leftHandInterfaceActive = false; } } } }
void selector() { Debug.Log(hand.palm.localEulerAngles); float difference = Vector3.Angle(hand.palm.localEulerAngles, FACING_CAMERA); if (difference < 8.0f && leftHand.activeSelf) { if (selectorsMade) { //Update the position, rotation, and color if (hue) { hue.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f; hue.transform.rotation = hand.GetPalmRotation(); } if (alpha) { alpha.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f; alpha.transform.rotation = hand.GetPalmRotation(); } if (saturation) { saturation.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f; saturation.transform.rotation = hand.GetPalmRotation(); } } else { //Spawn in the light, 3 selectors, and sphere. //update each position, rotation, and color if (huePrefab) { hue = (GameObject)Instantiate(huePrefab, hand.GetPalmPosition() + hand.GetPalmNormal() * 0.15f, hand.GetPalmRotation()); } if (alphaPrefab) { alpha = (GameObject)Instantiate(alphaPrefab); } if (saturationPrefab) { saturation = (GameObject)Instantiate(saturationPrefab); } selectorsMade = true; lhc.BroadcastMessage("setInterface", true); } } else { if (selectorsMade) { if (!leftHand.activeSelf || difference >= 8.0f) { if (hue) { Destroy(hue); } if (saturation) { Destroy(saturation); } if (alpha) { Destroy(alpha); } selectorsMade = false; } lhc.BroadcastMessage("setInterface", false); } } }
void Update() { if (!MenuController.username.Equals("nosave")) { double elapsedTime = Time.time - startTime; // only write the time if the game is paused if (ButtonManager.isPaused) { writer.WriteLine(elapsedTime + ",paused"); } else { writer.Write(elapsedTime + ","); // string gazePos = gazePlotter.GetPos() + ","; // remove parentheses // writer.Write(gazePos.Replace("(","").Replace(")","")); string touchPos = touch.GetPos().ToString("F5") + ","; writer.Write(touchPos.Replace("(", "").Replace(")", "")); // get marked button position Vector3 bPos3 = bManager.GetButton().transform.position; Vector2 bPos = new Vector2(bPos3.x, bPos3.y); writer.Write(bPos.ToString("F5").Replace("(", "").Replace(")", "") + ","); // write hand values if a hand exists if (lHand != null) { string palmPos = lHand.GetPalmPosition().ToString("F5") + ","; writer.Write(palmPos.Replace("(", "").Replace(")", "")); foreach (FingerModel lFinger in lFingers) { //string type = lFinger.fingerType.ToString(); //type = "l" + type.Substring(4).ToLower(); string fingerPos = lFinger.GetTipPosition().ToString("F5") + ","; writer.Write(fingerPos.Replace("(", "").Replace(")", "")); } } else { //writer.Write(",,,,,,,,,,,,,,,,,,"); for (int i = 0; i < 18; i++) { writer.Write(float.NaN + ","); } } if (rHand != null) { string palmPos = rHand.GetPalmPosition().ToString("F5") + ","; writer.Write(palmPos.Replace("(", "").Replace(")", "")); int i = 0; foreach (FingerModel rFinger in rFingers) { //string type = rFinger.fingerType.ToString(); //type = "r" + type.Substring(4).ToLower(); // counter so that last entry doesn't have an extra comma string fingerPos; if (i == 4) { fingerPos = rFinger.GetTipPosition().ToString("F5"); } else { fingerPos = rFinger.GetTipPosition().ToString("F5") + ","; } writer.Write(fingerPos.Replace("(", "").Replace(")", "")); i++; } } else { //writer.Write(",,,,,,,,,,,,,,,,,"); for (int i = 0; i < 17; i++) { writer.Write(float.NaN + ","); } writer.Write(float.NaN); } writer.WriteLine(); } } }
void UpdateBolts(HandModel leftHand, HandModel rightHand){ if (currentThunderBolt && IsCastingStarted) currentThunderBolt.SetPosition (leftHand.GetPalmPosition (), rightHand.GetPalmPosition ()); }