Пример #1
0
    //-------------------------------------------------
    // Called every Update() while a Hand is hovering over this object
    //-------------------------------------------------
    private void HandHoverUpdate(ValveVR.Hand hand)
    {
        ValveVR.GrabTypes startingGrabType = hand.GetGrabStarting();
        bool isGrabEnding = hand.IsGrabEnding(this.gameObject);

        if (interactable.attachedToHand == null && startingGrabType != ValveVR.GrabTypes.None)
        {
            // Save our position/rotation so that we can restore it when we detach
            //oldPosition = transform.position;
            //oldRotation = transform.rotation;

            // Call this to continue receiving HandHoverUpdate messages,
            // and prevent the hand from hovering over anything else
            hand.HoverLock(interactable);

            // Attach this object to the hand
            hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
        }
        else if (isGrabEnding)
        {
            // Detach this object from the hand
            hand.DetachObject(gameObject);

            // Call this to undo HoverLock
            hand.HoverUnlock(interactable);

            // Restore position/rotation
            //transform.position = oldPosition;
            //transform.rotation = oldRotation;
        }
    }
Пример #2
0
        //-------------------------------------------------
        private void HidePointer()
        {
            if (visible)
            {
                pointerHideStartTime = Time.time;
            }

            visible = false;
            if (pointerHand)
            {
                if (ShouldOverrideHoverLock())
                {
                    //Restore the original hovering interactable on the hand
                    if (originalHoverLockState == true)
                    {
                        pointerHand.HoverLock(originalHoveringInteractable);
                    }
                    else
                    {
                        pointerHand.HoverUnlock(null);
                    }
                }

                //Stop looping sound
                loopingAudioSource.Stop();
                PlayAudioClip(pointerAudioSource, pointerStopSound);
            }
            teleportPointerObject.SetActive(false);

            teleportArc.Hide();

            foreach (TeleportMarkerBase teleportMarker in teleportMarkers)
            {
                if (teleportMarker != null && teleportMarker.markerActive && teleportMarker.gameObject != null)
                {
                    teleportMarker.gameObject.SetActive(false);
                }
            }

            destinationReticleTransform.gameObject.SetActive(false);
            invalidReticleTransform.gameObject.SetActive(false);
            offsetReticleTransform.gameObject.SetActive(false);

            if (playAreaPreviewTransform != null)
            {
                playAreaPreviewTransform.gameObject.SetActive(false);
            }

            if (onActivateObjectTransform.gameObject.activeSelf)
            {
                onActivateObjectTransform.gameObject.SetActive(false);
                //Debug.Log("-------------------------------");
            }
            onDeactivateObjectTransform.gameObject.SetActive(true);

            pointerHand = null;
        }
Пример #3
0
 //-------------------------------------------------
 void OnDisable()
 {
     if (handHoverLocked)
     {
         handHoverLocked.HideGrabHint();
         handHoverLocked.HoverUnlock(interactable);
         handHoverLocked = null;
     }
 }
Пример #4
0
		//-------------------------------------------------
		void OnDisable()
		{
			if ( handHoverLocked )
			{
				ControllerButtonHints.HideButtonHint( handHoverLocked, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger );
				handHoverLocked.HoverUnlock( GetComponent<Interactable>() );
				handHoverLocked = null;
			}
		}
Пример #5
0
        //-------------------------------------------------
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            rigidbody.interpolation = hadInterpolation;
        }
Пример #6
0
        //-------------------------------------------------
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            ReleaseObject();
        }
Пример #7
0
        //-------------------------------------------------
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(GetComponent <Interactable>());

//            UpdateStationaryPosition(this.transform.localPosition);
        }
Пример #8
0
        //-------------------------------------------------
        private void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.isKinematic   = false;
            rb.interpolation = RigidbodyInterpolation.Interpolate;
            // AQUI ESTOY TRABAJANDO -- OBJECTOS KINEMATICOS
            if (gameObject.tag == "KeyObject")
            {
                rb.isKinematic   = true;
                rb.interpolation = RigidbodyInterpolation.None;
            }

            Vector3 position        = Vector3.zero;
            Vector3 velocity        = Vector3.zero;
            Vector3 angularVelocity = Vector3.zero;

            if (hand.controller == null)
            {
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                position        = velocityEstimator.transform.position;
            }
            else
            {
                velocity        = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity);
                angularVelocity = Player.instance.trackingOriginTransform.TransformVector(hand.controller.angularVelocity);
                position        = hand.transform.position;
            }

            Vector3 r = transform.TransformPoint(rb.centerOfMass) - position;

            rb.velocity        = velocity + Vector3.Cross(angularVelocity, r);
            rb.angularVelocity = angularVelocity;

            // Make the object travel at the release velocity for the amount
            // of time it will take until the next fixed update, at which
            // point Unity physics will take over
            float timeUntilFixedUpdate = (Time.fixedDeltaTime + Time.fixedTime) - Time.time;

            transform.position += timeUntilFixedUpdate * velocity;
            float   angle = Mathf.Rad2Deg * angularVelocity.magnitude;
            Vector3 axis  = angularVelocity.normalized;

            transform.rotation *= Quaternion.AngleAxis(angle * timeUntilFixedUpdate, axis);
        }
Пример #9
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            //Debug.Log(hand.gameObject.name + " Hover Update");

            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool      isGrabStarting   = startingGrabType != GrabTypes.None;
            bool      isGrabbing       = hand.IsGrabbing();
            bool      isGrabEnding     = hand.IsGrabbingWithType(grabbedWithType) == false;


            if (isGrabStarting || (grabbingHand == null && isGrabbing))               // Grab Start
            //Debug.Log("    Grab Start! (" + Time.frameCount + ")");
            //if (grabbingHand != null) { // Another hand has already grabbed -> switch hands
            //	Debug.Log("    (switching hands)");
            //}

            {
                lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform);

                if (hoverLock)
                {
                    hand.HoverLock(interactable);
                    handHoverLocked = hand;
                }

                driving         = true;
                grabbedWithType = hand.GetBestGrabbingType(GrabTypes.Grip);
                grabbingHand    = hand;
                isGrabEnding    = false;
            }
            else if (isGrabEnding && grabbingHand == hand)                 // Grab End
            //Debug.Log("    Grab End! (" + Time.frameCount + ")");

            {
                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }

                driving         = false;
                grabbedWithType = GrabTypes.None;
                grabbingHand    = null;
            }

            if (grabbingHand == hand)
            {
                //Debug.Log("    Grab Update!");
                ComputeAngle(hand);
                UpdateAll();
            }
        }
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool      isGrabEnding     = hand.IsGrabbingWithType(grabbedWithType) == false;

            if (grabbedWithType == GrabTypes.None && startingGrabType != GrabTypes.None)
            {
                grabbedWithType = startingGrabType;
                // Trigger was just pressed
                lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform);

                if (hoverLock)
                {
                    hand.HoverLock(interactable);
                    handHoverLocked = hand;
                }

                driving = true;

                DriveBegin?.Invoke();

                ComputeAngle(hand);
                UpdateAll();

                hand.HideGrabHint();
            }
            else if (grabbedWithType != GrabTypes.None && isGrabEnding)
            {
                // Trigger was just released
                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }

                driving = false;

                DriveEnd?.Invoke();

                grabbedWithType = GrabTypes.None;
            }

            if (driving && isGrabEnding == false && hand.hoveringInteractable == this.interactable)
            {
                ComputeAngle(hand);
                UpdateAll();
            }
        }
Пример #11
0
        protected virtual void HandAttachedUpdate(Hand hand)
        {
            ComputeAngle(hand);
            UpdateAll();

            if (hand.IsGrabEnding(this.gameObject))
            {
                hand.DetachObject(gameObject);

                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }
            }
        }
Пример #12
0
        private void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.isKinematic   = false;
            rb.interpolation = RigidbodyInterpolation.Interpolate;

            Vector3 position        = Vector3.zero;
            Vector3 velocity        = Vector3.zero;
            Vector3 angularVelocity = Vector3.zero;

            if (hand.controller == null)
            {
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                position        = velocityEstimator.transform.position;
            }
            else
            {
                velocity        = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity);
                angularVelocity = Player.instance.trackingOriginTransform.TransformVector(hand.controller.angularVelocity);
                position        = hand.transform.position;
            }

            Vector3 r = transform.TransformPoint(rb.centerOfMass) - position;

            rb.velocity        = velocity + Vector3.Cross(angularVelocity, r);
            rb.angularVelocity = angularVelocity;

            float timeUntilFixedUpdate = (Time.fixedDeltaTime + Time.fixedTime) - Time.time;

            transform.position += timeUntilFixedUpdate * velocity;
            float   angle = Mathf.Rad2Deg * angularVelocity.magnitude;
            Vector3 axis  = angularVelocity.normalized;

            transform.rotation *= Quaternion.AngleAxis(angle * timeUntilFixedUpdate, axis);

            Invoke("StartFetching", 1);
        }
Пример #13
0
        /// <summary>
        /// Hide the pointer
        /// </summary>
        private void HidePointer()
        {
            if (visible)
            {
                pointerHideStartTime = Time.time;
            }

            visible = false;
            if (pointerHand)
            {
                if (ShouldOverrideHoverLock())
                {
                    //Restore the original hovering interactable on the hand
                    if (originalHoverLockState == true)
                    {
                        pointerHand.HoverLock(originalHoveringInteractable);
                    }
                    else
                    {
                        pointerHand.HoverUnlock(null);
                    }
                }
            }
            teleportPointerObject.SetActive(false);

            foreach (TeleportMarkerBase teleportMarker in teleportMarkers)
            {
                if (teleportMarker != null && teleportMarker.markerActive && teleportMarker.gameObject != null)
                {
                    teleportMarker.gameObject.SetActive(false);
                }
            }

            destinationReticleTransform.gameObject.SetActive(false);
            invalidReticleTransform.gameObject.SetActive(false);
            offsetReticleTransform.gameObject.SetActive(false);

            if (playAreaPreviewTransform != null)
            {
                playAreaPreviewTransform.gameObject.SetActive(false);
            }


            pointerHand = null;
        }
Пример #14
0
        //-------------------------------------------------
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            if (scalingObject != null)
            {
                scalingObject = null;
                return;
            }
            if (!Grabbed)
            {
                return;
            }
            Grabbed = false;

            grabbedObject.transform.parent = null;

            //update color panel
            HSVColorPanel.instance.SelectedObject = null;

            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            rigidbody.interpolation = hadInterpolation;

            //if collides with head, attach it, otherwise fall on ground
            if (grabbedObject.GetComponent <HairObject>().AttachedAtHead)
            {
                grabbedObject.GetComponent <HairObject>().Grabbed = false;
                grabbedObject.GetComponent <HairObject>().ToggleRigidBody(false);

                grabbedObject.transform.parent = grabbedObject.GetComponent <HairObject>().ParentTransform;
            }
            else
            {
                Vector3 velocity;
                Vector3 angularVelocity;

                GetReleaseVelocities(hand, out velocity, out angularVelocity);

                rigidbody.velocity        = velocity;
                rigidbody.angularVelocity = angularVelocity;
            }
        }
Пример #15
0
        //-------------------------------------------------
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            rigidbody.interpolation = hadInterpolation;

            Vector3 velocity;
            Vector3 angularVelocity;

            GetReleaseVelocities(hand, out velocity, out angularVelocity);

            rigidbody.velocity        = velocity;
            rigidbody.angularVelocity = angularVelocity;
        }
Пример #16
0
        private void HandHoverUpdate(Hand hand)
        {
            if (hand.GetStandardInteractionButtonDown())
            {
                if (hand.currentAttachedObject != gameObject)
                {
                    hand.HoverLock(GetComponent <Interactable>());

                    hand.AttachObject(gameObject, attachmentFlags);
                }
            }
            else if (hand.GetStandardInteractionButtonUp())
            {
                hand.DetachObject(gameObject);

                hand.HoverUnlock(GetComponent <Interactable>());
            }
        }
Пример #17
0
 // Token: 0x060021DB RID: 8667 RVA: 0x000A7928 File Offset: 0x000A5B28
 private void HandHoverUpdate(Hand hand)
 {
     if (hand.GetStandardInteractionButtonDown() || (hand.controller != null && hand.controller.GetPressDown(EVRButtonId.k_EButton_Grip)))
     {
         if (hand.currentAttachedObject != base.gameObject)
         {
             this.oldPosition = base.transform.position;
             this.oldRotation = base.transform.rotation;
             hand.HoverLock(base.GetComponent <Interactable>());
             hand.AttachObject(base.gameObject, this.attachmentFlags, "");
             return;
         }
         hand.DetachObject(base.gameObject, true);
         hand.HoverUnlock(base.GetComponent <Interactable>());
         base.transform.position = this.oldPosition;
         base.transform.rotation = this.oldRotation;
     }
 }
Пример #18
0
 // Token: 0x06005CDE RID: 23774 RVA: 0x00206C54 File Offset: 0x00205054
 private void HandHoverUpdate(Hand hand)
 {
     if (hand.GetStandardInteractionButtonDown())
     {
         hand.HoverLock(base.GetComponent <Interactable>());
         this.initialMappingOffset = this.linearMapping.value - this.CalculateLinearMapping(hand.transform);
         this.sampleCount          = 0;
         this.mappingChangeRate    = 0f;
     }
     if (hand.GetStandardInteractionButtonUp())
     {
         hand.HoverUnlock(base.GetComponent <Interactable>());
         this.CalculateMappingChangeRate();
     }
     if (hand.GetStandardInteractionButton())
     {
         this.UpdateLinearMapping(hand.transform);
     }
 }
Пример #19
0
        private void OnDetachedFromHand(Hand hand)
        {
            this.attached = false;
            this.onDetachFromHand.Invoke();
            hand.HoverUnlock(null);
            if (this.BypassDetached)
            {
                return;
            }
            Rigidbody component = base.GetComponent <Rigidbody>();

            component.isKinematic   = false;
            component.interpolation = RigidbodyInterpolation.Interpolate;
            Vector3 b      = Vector3.zero;
            Vector3 a      = Vector3.zero;
            Vector3 vector = Vector3.zero;

            if (hand.controller == null)
            {
                this.velocityEstimator.FinishEstimatingVelocity();
                a      = this.velocityEstimator.GetVelocityEstimate();
                vector = this.velocityEstimator.GetAngularVelocityEstimate();
                b      = this.velocityEstimator.transform.position;
            }
            else
            {
                a      = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity);
                vector = Player.instance.trackingOriginTransform.TransformVector(hand.controller.angularVelocity);
                b      = hand.transform.position;
            }
            Vector3 rhs = base.transform.TransformPoint(component.centerOfMass) - b;

            component.velocity        = a + Vector3.Cross(vector, rhs);
            component.angularVelocity = vector;
            float num = Time.fixedDeltaTime + Time.fixedTime - Time.time;

            base.transform.position += num * a;
            float   num2       = 57.29578f * vector.magnitude;
            Vector3 normalized = vector.normalized;

            base.transform.rotation *= Quaternion.AngleAxis(num2 * num, normalized);
        }
Пример #20
0
 private void HandHoverUpdate(Hand hand)
 {
     if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)))
     {
         if (hand.currentAttachedObject != gameObject)
         {
             hand.HoverLock(GetComponent <Interactable>());
             hand.AttachObject(gameObject, attachmentFlags);
             GetComponentInChildren <Collider>().gameObject.layer = LayerMask.NameToLayer("IgnoreTeleport");
             hand.GetComponentInChildren <HandControllerState>().gameObject.SetActive(false);
         }
         else
         {
             hand.DetachObject(gameObject);
             hand.HoverUnlock(GetComponent <Interactable>());
             GetComponentInChildren <Collider>().gameObject.layer = LayerMask.NameToLayer("Default");
             hand.GetComponentInChildren <HandControllerState>(true).gameObject.SetActive(true);
         }
     }
 }
Пример #21
0
        //-------------------------------------------------
        // Called every Update() while a Hand is hovering over this object
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)))
            {
                if (hand.currentAttachedObject != gameObject)
                {
                    hand.HoverLock(GetComponent <Interactable>());

                    // Attach this object to the hand
                    hand.AttachObject(gameObject, attachmentFlags);
                }
                else
                {
                    // Detach this object from the hand
                    hand.DetachObject(gameObject);

                    // Call this to undo HoverLock
                    hand.HoverUnlock(GetComponent <Interactable>());
                }
            }
        }
        protected override void OnDetachedFromHand(Hand hand)
        {
            GameObject flashlight = GameObject.Find("Light_flashlight");

            flashlight.GetComponent <Light>().enabled = false;
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            rigidbody.interpolation = hadInterpolation;

            Vector3 velocity;
            Vector3 angularVelocity;

            GetReleaseVelocities(hand, out velocity, out angularVelocity);

            rigidbody.velocity        = velocity;
            rigidbody.angularVelocity = angularVelocity;
        }
Пример #23
0
        private void HandHoverUpdate(Hand hand)
        {
            UnityEngine.Debug.Log("Hover");
            if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)))
            {
                if (hand.currentAttachedObject != gameObject)
                {
                    UnityEngine.Debug.Log("Attatch");
                    //Orienting to hand
                    this.transform.position = hand.transform.position;
                    this.transform.rotation = Quaternion.Euler(hand.transform.rotation.eulerAngles + grabOrientation);

                    //Locking for detatchment
                    hand.HoverLock(GetComponent <Interactable>());
                    hand.AttachObject(gameObject, attatchmentFlags);

                    //Used for velocity gathering
                    isActive = true;

                    //Connecting to hand with Joint
                    //CreateHandJoint();
                    //handJoint.connectedBody = hand.GetComponent<Rigidbody>();
                }
            }
            else if (hand.GetStandardInteractionButtonUp() || ((hand.controller != null) && hand.controller.GetPressUp(Valve.VR.EVRButtonId.k_EButton_Grip)))
            {
                if (hand.currentAttachedObject == gameObject)
                {
                    UnityEngine.Debug.Log("Detatch");
                    hand.DetachObject(gameObject);

                    hand.HoverUnlock(GetComponent <Interactable> ());

                    isActive = false;

                    //Disconnecting handJoint
                    //Destroy(handJoint);
                }
            }
        }
Пример #24
0
        //-------------------------------------------------
        protected virtual void OnAttachedToHand(Hand hand)
        {
            Debug.Log("<b>[SteamVR Interaction]</b> Pickup: " + hand.GetGrabStarting().ToString());
            lastUsedHand = hand;



            hadInterpolation = this.rigidbody.interpolation;

            attached = true;

            onPickUp.Invoke();

            if (!hoverLockIfGrabbed)
            {
                hand.HoverUnlock(null);
            }
            else
            {
                hand.HoverLock(null);
            }

            rigidbody.interpolation = RigidbodyInterpolation.None;

            velocityEstimator.BeginEstimatingVelocity();

            attachTime     = Time.time;
            attachPosition = transform.position;
            attachRotation = transform.rotation;
            if (hand.m_IndexFingerCollider != null)
            {
                hand.m_IndexFingerCollider.enabled = false;
            }

            if (dontLetGoOnInputUp)
            {
                m_inputUpIgnored = 0;
            }
        }
Пример #25
0
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            //if ( onDetachedFromHand != null )
            //	onDetachedFromHand.Invoke( hand );

            attachedToHand = null;


            attached = false;
            //onDetachFromHand.Invoke();
            hand.HoverUnlock(null);

            rb.interpolation = hadInterpolation;

            Vector3 velocity;
            Vector3 angularVelocity;

            GetReleaseVelocities(hand, out velocity, out angularVelocity);

            rb.velocity        = velocity;
            rb.angularVelocity = angularVelocity;
        }
Пример #26
0
        //-------------------------------------------------
        protected virtual void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            rigidbody.interpolation = hadInterpolation;

            Vector3 velocity;
            Vector3 angularVelocity;

            //GetReleaseVelocities(hand, out velocity, out angularVelocity);

            //rigidbody.velocity = velocity;
            //rigidbody.angularVelocity = angularVelocity;
            //Set yinitial
            //yinitial = gameObject.GetComponent
            GetComponent <Throw>().yinitial = gameObject.transform.position.y;
            GetComponent <Throw>().thrown   = true;
        }
Пример #27
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool      isGrabEnding     = hand.IsGrabEnding(this.gameObject);

            if (startingGrabType != GrabTypes.None)
            {
                // Trigger was just pressed
                lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform);

                if (hoverLock)
                {
                    hand.HoverLock(interactable);
                    handHoverLocked = hand;
                }

                driving = true;

                ComputeAngle(hand);
                UpdateAll();

                hand.HideGrabHint();
            }

            if (isGrabEnding)
            {
                // Trigger was just released
                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }
            }
            else if (driving && isGrabEnding == false && hand.hoveringInteractable == this.interactable)
            {
                ComputeAngle(hand);
                UpdateAll();
            }
        }
Пример #28
0
        //-------------------------------------------------
        private void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.isKinematic   = false;
            rb.interpolation = RigidbodyInterpolation.Interpolate;

            Vector3 position        = Vector3.zero;
            Vector3 velocity        = Vector3.zero;
            Vector3 angularVelocity = Vector3.zero;

            velocityEstimator.FinishEstimatingVelocity();
            velocity        = velocityEstimator.GetVelocityEstimate();
            angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
            position        = velocityEstimator.transform.position;

            Vector3 r = transform.TransformPoint(rb.centerOfMass) - position;

            rb.velocity        = velocity + Vector3.Cross(angularVelocity, r);
            rb.angularVelocity = angularVelocity;

            // Make the object travel at the release velocity for the amount
            // of time it will take until the next fixed update, at which
            // point Unity physics will take over
            float timeUntilFixedUpdate = (Time.fixedDeltaTime + Time.fixedTime) - Time.time;

            transform.position += timeUntilFixedUpdate * velocity;
            float   angle = Mathf.Rad2Deg * angularVelocity.magnitude;
            Vector3 axis  = angularVelocity.normalized;

            transform.rotation *= Quaternion.AngleAxis(angle * timeUntilFixedUpdate, axis);
        }
Пример #29
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (hand.GetStandardInteractionButtonDown())
            {
                hand.HoverLock(GetComponent <Interactable>());

                initialMappingOffset = linearMapping.value - CalculateLinearMapping(hand.transform);
                sampleCount          = 0;
                mappingChangeRate    = 0.0f;
            }

            if (hand.GetStandardInteractionButtonUp())
            {
                hand.HoverUnlock(GetComponent <Interactable>());

                CalculateMappingChangeRate();
            }

            if (hand.GetStandardInteractionButton())
            {
                UpdateLinearMapping(hand.transform);
            }
        }
Пример #30
0
        //-------------------------------------------------
        // Called every Update() while a Hand is hovering over this object
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)))
            {
                if (hand.currentAttachedObject != gameObject)
                {
                    // Save our position/rotation so that we can restore it when we detach
                    oldPosition = transform.position;
                    oldRotation = transform.rotation;

                    // Call this to continue receiving HandHoverUpdate messages,
                    // and prevent the hand from hovering over anything else
                    hand.HoverLock(GetComponent <Interactable>());

                    // Attach this object to the hand
                    hand.AttachObject(gameObject, attachmentFlags);
//					if (this.gameObject.tag == "Strip") {
//						Joint joint4 = GameObject.Find.name ("joint4");
//
//						Joint fixedJoint = joint4.gameObject.AddComponent<FixedJoint>();
//						fixedJoint.connectedBody = hand;
//					}
                }
                else
                {
                    // Detach this object from the hand
                    hand.DetachObject(gameObject);

                    // Call this to undo HoverLock
                    hand.HoverUnlock(GetComponent <Interactable>());

                    // Restore position/rotation
                    transform.position = oldPosition;
                    transform.rotation = oldRotation;
                }
            }
        }