Ejemplo n.º 1
0
        //-------------------------------------------------
        protected virtual void OnHandHoverBegin(Hand hand)
        {
            bool showHint = false;

            // "Catch" the throwable by holding down the interaction button instead of pressing it.
            // Only do this if the throwable is moving faster than the prescribed threshold speed,
            // and if it isn't attached to another hand
            if (!attached && catchingSpeedThreshold != -1)
            {
                float catchingThreshold = catchingSpeedThreshold * SteamVR_Utils.GetLossyScale(Player.instance.trackingOriginTransform);

                GrabTypes bestGrabType = hand.GetBestGrabbingType();

                if (bestGrabType != GrabTypes.None)
                {
                    if (rigidbody.velocity.magnitude >= catchingThreshold)
                    {
                        hand.AttachObject(gameObject, bestGrabType, attachmentFlags);
                        showHint = false;
                    }
                }
            }

            if (showHint)
            {
                hand.ShowGrabHint();
            }
        }
Ejemplo n.º 2
0
        private void Start()
        {
            colliders = GetComponentsInChildren <Collider>();

            if (physicMaterial_lowfriction == null)
            {
                physicMaterial_lowfriction = new PhysicMaterial("hand_lowFriction");
                physicMaterial_lowfriction.dynamicFriction = 0;
                physicMaterial_lowfriction.staticFriction  = 0;
                physicMaterial_lowfriction.bounciness      = 0;
                physicMaterial_lowfriction.bounceCombine   = PhysicMaterialCombine.Minimum;
                physicMaterial_lowfriction.frictionCombine = PhysicMaterialCombine.Minimum;
            }

            if (physicMaterial_highfriction == null)
            {
                physicMaterial_highfriction = new PhysicMaterial("hand_highFriction");
                physicMaterial_highfriction.dynamicFriction = 1f;
                physicMaterial_highfriction.staticFriction  = 1f;
                physicMaterial_highfriction.bounciness      = 0;
                physicMaterial_highfriction.bounceCombine   = PhysicMaterialCombine.Minimum;
                physicMaterial_highfriction.frictionCombine = PhysicMaterialCombine.Average;
            }

            SetPhysicMaterial(physicMaterial_lowfriction);

            scale = SteamVR_Utils.GetLossyScale(hand.transform);
        }
Ejemplo n.º 3
0
        //-------------------------------------------------
        protected override void OnHandHoverBegin(Hand hand)
        {
            base.OnHandHoverBegin(hand);
            bool showHint = true;

            // "Catch" the throwable by holding down the interaction button instead of pressing it.
            // Only do this if the throwable is moving faster than the prescribed threshold speed,
            // and if it isn't attached to another hand
            if (!attached && parameters.catchingSpeedThreshold != -1)
            {
                float catchingThreshold = parameters.catchingSpeedThreshold * SteamVR_Utils.GetLossyScale(Player.instance.transform);

                bool grabbing = Player.instance.input_manager.GetGrip(hand);

                if (grabbing)
                {
                    if (rb.velocity.magnitude >= catchingThreshold)
                    {
                        hand.AttachGrabbable(this);
                        showHint = false;
                    }
                }
            }

            if (showHint)
            {
                Player.instance.input_manager.ShowGrabHint(hand);
            }
        }
Ejemplo n.º 4
0
    protected override void OnDrawGizmos()
    {
        if (useHoverSphere && hoverSphereTransform != null)
        {
            Gizmos.color = Color.green;
            float scaledHoverRadius = hoverSphereRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(hoverSphereTransform));
            Gizmos.DrawWireSphere(hoverSphereTransform.position, scaledHoverRadius / 2);
        }

        if (useControllerHoverComponent && mainRenderModel != null && mainRenderModel.IsControllerVisibile())
        {
            // draw gizmo to verify that it matches the size and shape of the drumstick accurately
            if (drumstick != null)
            {
                Gizmos.color = Color.blue;
                Vector3 drumstickPosition = drumstick.transform.position;
                float   drumstickSize     = drumstick.transform.lossyScale.x;
                Gizmos.DrawWireSphere(drumstickPosition, drumstickSize / 2);
            }
            else
            {
                Gizmos.color = Color.blue;
                float scaledHoverRadius = controllerHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
                Gizmos.DrawWireSphere(mainRenderModel.GetControllerPosition(controllerHoverComponent), scaledHoverRadius / 2);
            }
        }

        if (useFingerJointHover && mainRenderModel != null && mainRenderModel.IsHandVisibile())
        {
            Gizmos.color = Color.yellow;
            float scaledHoverRadius = fingerJointHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
            Gizmos.DrawWireSphere(mainRenderModel.GetBonePosition((int)fingerJointHover), scaledHoverRadius / 2);
        }
    }
Ejemplo n.º 5
0
    protected override void UpdateHovering()
    {
        if ((noSteamVRFallbackCamera == null) && (isActive == false))
        {
            return;
        }

        if (hoverLocked)
        {
            return;
        }

        if (applicationLostFocusObject.activeSelf)
        {
            return;
        }

        float        closestDistance     = float.MaxValue;
        Interactable closestInteractable = null;

        if (useHoverSphere)
        {
            float scaledHoverRadius = hoverSphereRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(hoverSphereTransform));
            CheckHoveringForTransform(hoverSphereTransform.position, scaledHoverRadius, ref closestDistance, ref closestInteractable, Color.green);
        }

        if (useControllerHoverComponent && mainRenderModel != null && mainRenderModel.IsControllerVisibile())
        {
            float scaledHoverRadius = controllerHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));

            // substitute drumstick object in place of SteamVR's HoverPoint
            if (drumstick != null)
            {
                // get position and radius of drumstick
                Vector3 drumstickPosition = drumstick.transform.position;
                float   drumstickRadius   = drumstick.transform.lossyScale.x / 2f;

                // use SteamVR's method to detect if interactable component overlaps with drumstick size and position
                CheckHoveringForTransform(drumstickPosition, drumstickRadius, ref closestDistance, ref closestInteractable, Color.blue);
            }
            else
            {
                Debug.LogError("Drumsticks not detected. Defaulting to SteamVR hover component.");
                CheckHoveringForTransform(mainRenderModel.GetControllerPosition(controllerHoverComponent), scaledHoverRadius / 2f, ref closestDistance, ref closestInteractable, Color.blue);
            }
        }

        if (useFingerJointHover && mainRenderModel != null && mainRenderModel.IsHandVisibile())
        {
            float scaledHoverRadius = fingerJointHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
            CheckHoveringForTransform(mainRenderModel.GetBonePosition((int)fingerJointHover), scaledHoverRadius / 2f, ref closestDistance, ref closestInteractable, Color.yellow);
        }

        // Hover on this one
        hoveringInteractable = closestInteractable;
    }
Ejemplo n.º 6
0
        protected virtual void UpdateHovering()
        {
            if (isActive == false)
            {
                return;
            }

            if (hoverLocked)
            {
                return;
            }

            if (applicationLostFocusObject.activeSelf)
            {
                Debug.Log("lost focus" + name);
                return;
            }

            float        closestDistance     = float.MaxValue;
            Interactable closestInteractable = null;

            if (useHoverSphere)
            {
                float scaledHoverRadius = hoverSphereRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(hoverSphereTransform));
                CheckHoveringForTransform(hoverSphereTransform.position, scaledHoverRadius, ref closestDistance, ref closestInteractable, Color.green);
            }

            if (mainRenderModel != null)
            {
                if (mainRenderModel.IsControllerVisibile())
                {
                    float scaledHoverRadius = controllerHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
                    CheckHoveringForTransform(mainRenderModel.GetControllerPosition(controllerHoverComponent), scaledHoverRadius / 2f, ref closestDistance, ref closestInteractable, Color.blue);
                }

                if (useFingerJointHover && mainRenderModel.IsHandVisibile())
                {
                    float scaledHoverRadius = fingerJointHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
                    CheckHoveringForTransform(mainRenderModel.GetBonePosition((int)fingerJointHover), scaledHoverRadius / 2f, ref closestDistance, ref closestInteractable, Color.yellow);
                }
            }


            // Hover on this one
            hoveringInteractable = closestInteractable;
        }
Ejemplo n.º 7
0
        protected void UpdateAttachedVelocity(AttachedObject attachedObjectInfo)
        {
            Transform attach_trans = transform;

            float scale = SteamVR_Utils.GetLossyScale(attach_trans);

            float maxVelocityChange        = MaxVelocityChange * scale;
            float velocityMagic            = VelocityMagic;
            float angularVelocityMagic     = AngularVelocityMagic;
            float maxAngularVelocityChange = MaxAngularVelocityChange * scale;

            Vector3 targetItemPosition = attach_trans.TransformPoint(hand_attachment_offset_helper.localPosition);

            Vector3 positionDelta  = (targetItemPosition - attachedObjectInfo.attachedRigidbody.position);
            Vector3 velocityTarget = (positionDelta * velocityMagic * Time.deltaTime);

            if (float.IsNaN(velocityTarget.x) == false && float.IsInfinity(velocityTarget.x) == false)
            {
                attachedObjectInfo.attachedRigidbody.velocity = Vector3.MoveTowards(attachedObjectInfo.attachedRigidbody.velocity, velocityTarget, maxVelocityChange);
            }


            Quaternion targetItemRotation = attach_trans.rotation * hand_attachment_offset_helper.localRotation;

            Quaternion rotationDelta = targetItemRotation * Quaternion.Inverse(attachedObjectInfo.attachedObject.transform.rotation);


            float   angle;
            Vector3 axis;

            rotationDelta.ToAngleAxis(out angle, out axis);

            if (angle > 180)
            {
                angle -= 360;
            }

            if (angle != 0 && float.IsNaN(axis.x) == false && float.IsInfinity(axis.x) == false)
            {
                Vector3 angularTarget = angle * axis * angularVelocityMagic * Time.deltaTime;

                attachedObjectInfo.attachedRigidbody.angularVelocity = Vector3.MoveTowards(attachedObjectInfo.attachedRigidbody.angularVelocity, angularTarget, maxAngularVelocityChange);
            }
        }
Ejemplo n.º 8
0
        protected virtual void OnDrawGizmos()
        {
            if (useHoverSphere)
            {
                Gizmos.color = Color.green;
                float scaledHoverRadius = hoverSphereRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(hoverSphereTransform));
                Gizmos.DrawWireSphere(hoverSphereTransform.position, scaledHoverRadius / 2);
            }

            if (mainRenderModel != null && mainRenderModel.IsControllerVisibile())
            {
                Gizmos.color = Color.blue;
                float scaledHoverRadius = controllerHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
                Gizmos.DrawWireSphere(mainRenderModel.GetControllerPosition(controllerHoverComponent), scaledHoverRadius / 2 + .01f);
            }

            if (useFingerJointHover && mainRenderModel != null && mainRenderModel.IsHandVisibile())
            {
                Gizmos.color = Color.yellow;
                float scaledHoverRadius = fingerJointHoverRadius * Mathf.Abs(SteamVR_Utils.GetLossyScale(this.transform));
                Gizmos.DrawWireSphere(mainRenderModel.GetBonePosition((int)fingerJointHover), scaledHoverRadius / 2 + .02f);
            }
        }