protected override void PickupObject(SteamVR_Action_Boolean fromaction, SteamVR_Input_Sources fromsource) { if (primaryHand.hoveringInteractable) { Takeable takeable = primaryHand.hoveringInteractable.GetComponent <Takeable>(); if (takeable.preTaskObject) { takeable.takeObject(primaryHand); return; } grabbedObject = takeable; initTorsoPosition = hmd.transform.position - new Vector3(0, 0.25f, 0); initObjDistance = getDistanceFromTorso(grabbedObject.transform.position); initHandDistance = getDistanceFromTorso(primaryHand.transform.position); initHandPosition = primaryHand.transform.position; vectorOffset = grabbedObject.transform.position - (initTorsoPosition + initObjDistance * ((initHandPosition - initTorsoPosition) / initHandDistance)); renderedRay.gameObject.SetActive(false); lastScaledHandPos = primaryHand.transform.position; initHandRot = primaryHand.transform.rotation; initObjRot = grabbedObject.transform.rotation; takeable.takeObject(primaryHand); } else { base.PickupObject(fromaction, fromsource); } }
private void GrabOrReleaseObject() { // grab object of both grab buttons are pressed if (pickupPressedPrimaryHand && pickupPressedSecondaryHand) { // Record a miss if no object is selected if (selectionSphere.hoveringInteractable == null) { TaskController.Instance.ObjectSelected(null, null, primaryHand); return; } // set grabbed object grabbedObject = selectionSphere.hoveringInteractable.GetComponent <Takeable>(); // disable hover effect primaryHand.HoverLock(null); // set parent of the grabbed object to the selection sphere if it is not a pre task object if (!grabbedObject.preTaskObject) { originalParent = grabbedObject.transform.parent; grabbedObject.transform.SetParent(selectionSphere.transform); } // handle object grabbing (start time measurement etc.) grabbedObject.takeObject(primaryHand); } // release object if currently grabbed else if (grabbedObject != null) { ReleaseObject(); } }
private void Update() { if (!useController && leapServiceProvider.CurrentFrame.Hands.Count > 0) { if (primaryHand.mainRenderModel) { primaryHand.mainRenderModel.gameObject.SetActive(false); } primaryHand.hoverSphereTransform.position = leapServiceProvider.CurrentFrame.Hands[0].PalmPosition.ToVector3(); primaryHand.hoverSphereTransform.rotation = leapServiceProvider.CurrentFrame.Hands[0].Rotation.ToQuaternion(); if (leapServiceProvider.CurrentFrame.Hands[0].GrabStrength > 0.9f) { if (!isGrabbing) { grabbedThisFrame = true; isGrabbing = true; } } else { isGrabbing = false; } if (grabbedThisFrame && grabbedObject == null) { if (primaryHand.hoveringInteractable != null) { Takeable toGrab = primaryHand.hoveringInteractable.GetComponent <Takeable>(); if (toGrab != null) { toGrab.takeObject(primaryHand); if (!TaskController.Instance.IsSelectionTask()) { grabbedObject = toGrab; originalParent = grabbedObject.transform.parent; grabbedObject.transform.SetParent(primaryHand.hoverSphereTransform); } } } else { TaskController.Instance.ObjectSelected(null, null, primaryHand); } } else if (!isGrabbing) { if (grabbedObject != null) { grabbedObject.transform.SetParent(originalParent); grabbedObject.ReleaseObject(); grabbedObject = null; } } } grabbedThisFrame = false; }
/// <summary> /// Grabs the targetable object if it is not a pre selection object. /// </summary> private void Grab() { if (TaskController.Instance.currentGameObjects.Count == 0) { return; } if (Time.realtimeSinceStartup - lastFullGrabTime <= rotationModeTimeWindow) { rotationMode = true; rotationLever.gameObject.SetActive(true); } Takeable takeable = TaskController.Instance.currentGameObjects[0].GetComponent <Takeable>(); takeable.takeObject(primaryHand); if (!takeable.preTaskObject && takeable.GetComponent <Interactable>() != null) { currentTakeable = takeable; startGrabObjectPosition = currentTakeable.transform.position; barMaterial.SetMainColorAlpha(1); if (!rotationMode) { translationLever.gameObject.SetActive(true); } } else { // disable grab until the next release so the start task object is // not grabbed directly after the pre selection task object is grabbed grabDisabled = true; } startGrabHandPosition = GetHandPos(); }