Exemple #1
0
    public void Grab()
    {
        if (hoveredObject != null)
        {
            grabbedObject = hoveredObject;
            grabbedObject.OnGrab(controller);

            // adding interactions
            controller.OnTriggerDown.AddListener(grabbedObject.OnInteraction);
            controller.OnTriggerUpdated.AddListener(grabbedObject.OnUpdatingInteraction);
            controller.OnTriggerUp.AddListener(grabbedObject.OnStopInteraction);
        }
    }
Exemple #2
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;
                }
            }
        }
    }
Exemple #3
0
 // Update is called once per frame
 void Update()
 {
     if (canGrab && handGrabController.isGrab)
     {
         //抓取
         if (!fj)
         {
             grabbableObject.OnGrab();
             transform.position = handGrabController.thumbTip;
             fj = gameObject.AddComponent <FixedJoint>();
             fj.connectedBody = thumbTip.gameObject.GetComponent <Rigidbody>();
             GameObject.Find("FlowerManager").GetComponent <CreateFlower>().InstanceFlower();
         }
     }
     else
     {
         //断开
         if (fj)
         {
             Destroy(fj);
         }
     }
 }
    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_;
            }
        }
    }