GetPalmRotation() public method

public GetPalmRotation ( ) : Quaternion
return Quaternion
示例#1
0
 void updateColorSelectionBar()
 {
     if (hue && hue.activeSelf)
     {
         hue.transform.position = leftHandModel.GetPalmPosition() + leftHandModel.GetPalmNormal() * 0.15f;
         hue.transform.rotation = leftHandModel.GetPalmRotation();
     }
 }
    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 void UpdatePalmRotation()
    {
        HandModel hand_model = GetComponent <HandModel>();

        palm_rotation_ = Quaternion.Slerp(palm_rotation_, hand_model.GetPalmRotation(),
                                          1.0f - rotationFiltering);
    }
示例#4
0
    protected void UpdatePalmRotation()
    {
        HandModel handModel = this.GetComponent <HandModel>();

        // apply some smoothing to avoid abrupt changes
        this.PalmRotation = Quaternion.Slerp(this.PalmRotation, handModel.GetPalmRotation(),
                                             1.0f - this.RotationFiltering);
    }
示例#5
0
    IEnumerator Fire(HandModel currentHand)
    {
        canFire = false;
        //Debug.Log (canFire);

        GameObject justFired = Instantiate (ammo, currentHand.transform.position + currentHand.GetPalmNormal() * offset , currentHand.GetPalmRotation()) as GameObject;
        justFired.GetComponent<moveProjectile> ().target = target;
        //justFired.GetComponent<moveProjectile> ().force = Quaternion.LookRotation( handController.transform.forward, Vector3.down).eulerAngles;
        yield return new WaitForSeconds (delay);
            canFire = true;
    }
示例#6
0
    // 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;
                }
            }
        }
    }
示例#7
0
    protected void StartPinch(Vector3 pinch_position)
    {
        HandModel hand_model = GetComponent <HandModel>();

        if (active_object_ != null)
        {
            IgnoreCollisions(active_object_.gameObject, true);

            palm_rotation_      = hand_model.GetPalmRotation();
            rotation_from_palm_ = Quaternion.Inverse(palm_rotation_) * active_object_.transform.rotation;
            current_pinch_      = active_object_.transform.position;

            GrabbableObject grabbable = active_object_.GetComponent <GrabbableObject>();
            if (grabbable == null || grabbable.rotateQuickly)
            {
                last_max_angular_velocity_ = active_object_.rigidbody.maxAngularVelocity;
                active_object_.rigidbody.maxAngularVelocity = Mathf.Infinity;
            }

            if (grabbable != null)
            {
                grabbable.OnGrab();

                if (grabbable.preferredOrientation)
                {
                    Vector3 palm_vector = grabbable.palmOrientation;
                    if (hand_model.GetLeapHand().IsLeft)
                    {
                        palm_vector = Vector3.Scale(palm_vector, new Vector3(-1, 1, 1));
                    }

                    Quaternion relative_rotation = Quaternion.Inverse(palm_rotation_) *
                                                   active_object_.transform.rotation;
                    Vector3    axis_in_palm    = relative_rotation * grabbable.objectOrientation;
                    Quaternion axis_correction = Quaternion.FromToRotation(axis_in_palm, palm_vector);
                    if (Vector3.Dot(axis_in_palm, palm_vector) < 0)
                    {
                        axis_correction = Quaternion.FromToRotation(axis_in_palm, -palm_vector);
                    }

                    rotation_from_palm_ = axis_correction * relative_rotation;
                }
            }
        }
    }
示例#8
0
    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;
                }
            }
        }
    }
示例#9
0
    void Update()
    {
        if (leap_hand == null)
        {
            return;
        }

        Vector3 centroid = GetCentroidFingers();

        if (command == CommandGesture.NULL)
        {
            if (isComandGrab(centroid, JoyConfig.Config.DistanceGrab))
            {
                command = CommandGesture.Grab;
            }
        }
        else
        {
            switch (command)
            {
            case CommandGesture.Grab:
                if (!isComandGrab(centroid, JoyConfig.Config.DistanceRelease))
                {
                    command = CommandGesture.NULL;
                    MoveTool.MoveHome();
                }
                else
                {
                    Tool.transform.rotation = hand_model.GetPalmRotation();
                    FingerModel midle = hand_model.fingers[2];
                    MoveTool.MoveTo(midle.GetJointPosition(1));
                }
                break;

            default:
                break;
            }
        }
    }
示例#10
0
    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();
            }
        }
    }
    protected void StartPinch()
    {
        // Only pinch if we're hovering over an object.
        if (active_object_ == null)
        {
            return;
        }



        HandModel hand_model = GetComponent <HandModel>();

        Debug.Log("Start pinch");


        Leap.Utils.IgnoreCollisions(gameObject, active_object_.gameObject, true);
        GrabbableObject grabbable = active_object_.GetComponent <GrabbableObject>();

        // Setup initial position and rotation conditions.
        palm_rotation_       = hand_model.GetPalmRotation();
        object_pinch_offset_ = Vector3.zero;

        // If we don't center the object, find the closest point in the collider for our grab point.
        if (grabbable == null || !grabbable.centerGrabbedObject)
        {
            Vector3 delta_position = active_object_.transform.position - current_pinch_position_;

            Ray        pinch_ray = new Ray(current_pinch_position_, delta_position);
            RaycastHit pinch_hit;

            // If we raycast hits the object, we're outside the collider so grab the hit point.
            // If not, we're inside the collider so just use the pinch position.
            if (active_object_.Raycast(pinch_ray, out pinch_hit, grabObjectDistance))
            {
                object_pinch_offset_ = active_object_.transform.position - pinch_hit.point;
            }
            else
            {
                object_pinch_offset_ = active_object_.transform.position - current_pinch_position_;
            }
        }

        filtered_pinch_position_ = active_object_.transform.position - object_pinch_offset_;
        object_pinch_offset_     = Quaternion.Inverse(active_object_.transform.rotation) *
                                   object_pinch_offset_;
        rotation_from_palm_ = Quaternion.Inverse(palm_rotation_) * active_object_.transform.rotation;

        // If we can rotate the object quickly, increase max angular velocity for now.
        if (grabbable == null || grabbable.rotateQuickly)
        {
            last_max_angular_velocity_ = active_object_.rigidbody.maxAngularVelocity;
            active_object_.rigidbody.maxAngularVelocity = Mathf.Infinity;
        }

        if (grabbable != null)
        {
            // Notify grabbable object that it was grabbed.
            grabbable.OnGrab();

            if (grabbable.useAxisAlignment)
            {
                // If this option is enabled we only want to align the object axis with the palm axis
                // so we'll cancel out any rotation about the aligned axis.
                Vector3 palm_vector = grabbable.rightHandAxis;
                if (hand_model.GetLeapHand().IsLeft)
                {
                    palm_vector = Vector3.Scale(palm_vector, new Vector3(-1, 1, 1));
                }

                Vector3    axis_in_palm    = rotation_from_palm_ * grabbable.objectAxis;
                Quaternion axis_correction = Quaternion.FromToRotation(axis_in_palm, palm_vector);
                if (Vector3.Dot(axis_in_palm, palm_vector) < 0)
                {
                    axis_correction = Quaternion.FromToRotation(axis_in_palm, -palm_vector);
                }

                rotation_from_palm_ = axis_correction * rotation_from_palm_;
            }
        }
    }
示例#12
0
    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;
            }
        }
    }
    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;
                }
            }
        }
    }
示例#14
0
    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);
            }
        }
    }
示例#15
0
    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;
            }
        }
    }
示例#16
0
    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;
    }
示例#17
0
    protected void StartGrasp()
    {
        // Only grasp if we're hovering over an object.
        if (this.ActiveObject == null)
        {
            return;
        }

        HandModel       handModel = this.GetComponent <HandModel>();
        GraspableObject graspable = this.ActiveObject.GetComponent <GraspableObject>();

        Leap.Utils.IgnoreCollisions(this.gameObject, this.ActiveObject.gameObject, true);

        // Setup initial position and rotation conditions.
        this.PalmRotation = handModel.GetPalmRotation();
        this.GraspOffset  = Vector3.zero;

        // If we don't center the object, find the closest point in the collider for our grab point.
        if (graspable == null || !graspable.CenterGraspedObject)
        {
            Vector3 deltaPosition = ActiveObject.transform.position - this.CurrentGraspCenter;

            Ray        graspRay = new Ray(this.CurrentGraspCenter, deltaPosition);
            RaycastHit graspHit;

            // If the raycast hits the object, we are outside the collider so grab the hit point.
            // If not, we are inside the collider so just use the grasp position.
            if (ActiveObject.Raycast(graspRay, out graspHit, GraspObjectDistance))
            {
                this.GraspOffset = this.ActiveObject.transform.position - graspHit.point;
            }
            else
            {
                this.GraspOffset = this.ActiveObject.transform.position - CurrentGraspCenter;
            }
        }

        this.SmoothedGraspPosition = this.ActiveObject.transform.position - this.GraspOffset;
        this.GraspOffset           = Quaternion.Inverse(this.ActiveObject.transform.rotation) * GraspOffset;
        this.RotationFromPalm      = Quaternion.Inverse(this.PalmRotation) * this.ActiveObject.transform.rotation;

        // If we can rotate the object quickly, increase max angular velocity for now.
        if (graspable == null || graspable.RotateQuickly)
        {
            this.ObjectMaxAngularVelocity = this.ActiveObject.GetComponent <Rigidbody>().maxAngularVelocity;
            this.ActiveObject.GetComponent <Rigidbody>().maxAngularVelocity = Mathf.Infinity;
        }

        if (graspable != null)
        {
            // Notify grabbable object that it was grabbed.
            if (graspable.GetResponseTime() < 0L)
            {
                if (handModel != null)
                {
                    Vector3 normal     = handModel.GetPalmNormal();
                    float   angleLeft  = Vector3.Angle(normal, Vector3.left);
                    float   angleRight = Vector3.Angle(normal, Vector3.right);
                    if (GraspController.Verbose)
                    {
                        Debug.LogWarning("hand normal: " + normal + ", to right: " + angleRight + ", to left: " + angleLeft);
                    }
                    if (angleLeft < angleRight)
                    {
                        graspable.setGraspDirection(GraspableObject.GraspDirection.UPRIGHT);
                    }
                    else
                    {
                        graspable.setGraspDirection(GraspableObject.GraspDirection.ROTATED);
                    }
                }
                else
                {
                    if (GraspController.Verbose)
                    {
                        Debug.LogWarning("no hand found...");
                    }
                }
            }
            graspable.OnGrasp(this.gameObject);

            if (graspable.UseAxisAlignment)
            {
                // If this option is enabled we only want to align the object axis with the palm axis,
                // hence we cancel out any rotation about the aligned axis.
                Vector3 palmVector = graspable.RightHandAxis;
                if (handModel.GetLeapHand().IsLeft)
                {
                    palmVector = Vector3.Scale(palmVector, new Vector3(-1, 1, 1));
                }
                Vector3    axisInPalm     = this.RotationFromPalm * graspable.ObjectAxis;
                Quaternion axisCorrection = Quaternion.FromToRotation(axisInPalm, palmVector);
                if (Vector3.Dot(axisInPalm, palmVector) < 0)
                {
                    axisCorrection = Quaternion.FromToRotation(axisInPalm, -palmVector);
                }
                this.RotationFromPalm = axisCorrection * this.RotationFromPalm;
            }
        }
    }