GetVelocityEstimate() public method

public GetVelocityEstimate ( ) : Vector3
return Vector3
示例#1
0
        public virtual void GetReleaseVelocities(Rigidbody rigidbody, out Vector3 velocity, out Vector3 angularVelocity)
        {
            Player player = Player.instance;

            switch (player.releaseVelocityStyle)
            {
            case ReleaseStyle.ShortEstimation:
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                break;

            case ReleaseStyle.AdvancedEstimation:
                GetEstimatedPeakVelocities(out velocity, out angularVelocity);
                break;

            case ReleaseStyle.GetFromHand:
                velocity        = GetTrackedObjectVelocity(player.releaseVelocityTimeOffset);
                angularVelocity = GetTrackedObjectAngularVelocity(player.releaseVelocityTimeOffset);
                break;

            default:
            case ReleaseStyle.NoChange:
                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                break;
            }

            if (player.releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                velocity *= player.scaleReleaseVelocity;
            }
        }
示例#2
0
    public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Vector3 angularVelocity)
    {
        if (hand.noSteamVRFallbackCamera && releaseVelocityStyle != ReleaseStyle.NoChange)
        {
            releaseVelocityStyle = ReleaseStyle.ShortEstimation; // only type that works with fallback hand is short estimation.
        }
        switch (releaseVelocityStyle)
        {
        case ReleaseStyle.ShortEstimation:
            velocityEstimator.FinishEstimatingVelocity();
            velocity        = velocityEstimator.GetVelocityEstimate();
            angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
            break;

        case ReleaseStyle.AdvancedEstimation:
            hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
            break;

        case ReleaseStyle.GetFromHand:
            velocity        = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
            angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
            break;

        default:
        case ReleaseStyle.NoChange:
            velocity        = rigidBody.velocity;
            angularVelocity = rigidBody.angularVelocity;
            break;
        }

        if (releaseVelocityStyle != ReleaseStyle.NoChange)
        {
            velocity *= scaleReleaseVelocity;
        }
    }
    void OnDetachedFromHand(VRHand hand)
    {
        attached = false;

        hand.HoverUnlock(null);

        Rigidbody rb = GetComponent <Rigidbody>();

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

        velocityEstimator.FinishEstimatingVelocity();
        Vector3 velocity        = velocityEstimator.GetVelocityEstimate();
        Vector3 angularVelocity = velocityEstimator.GetAngularVelocityEstimate();

        rb.velocity        = velocity;
        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);
    }
示例#4
0
        public virtual void ReleaseObject()
        {
            rb.isKinematic = originalIsKinematic;
            rb.useGravity  = originalUseGravity;

            if (preserveParent)
            {
                transform.parent = originalParent;
            }
            else
            {
                transform.parent = null;
            }

            // Remove stored parent after being dropped in worldspace once as it isn't needed anymore.
            if (transform.parent == null)
            {
                originalParent = null;
            }

            pickedUp = false;

            // Stop estimating the velocity and apply the velocity.
            rb.AddForce(vEstimator.GetVelocityEstimate(), ForceMode.Impulse);
            vEstimator.FinishEstimatingVelocity();
        }
示例#5
0
    public Vector3 GetControllerVelocity()
    {
        //Debug.Log("测量速度的obj: " + controllerAttachPoint.gameObject.name);
        VelocityEstimator vs = GetComponent <VelocityEstimator>();

        return(vs.GetVelocityEstimate());
    }
 /// <summary>
 /// Compares velocity estimations of two velocity estimators. Returns true if EITHER is above threshold.
 /// </summary>
 /// <param name="threshold"></param>
 /// <param name="thisEstimator"></param>
 /// <param name="otherEstimator"></param>
 /// <returns></returns>
 bool CompareVelocityEstimations(float threshold, VelocityEstimator thisEstimator, VelocityEstimator otherEstimator)
 {
     if (thisEstimator.GetVelocityEstimate().magnitude > threshold || otherEstimator.GetVelocityEstimate().magnitude > threshold)
     {
         return(true);
     }
     return(false);
 }
示例#7
0
    void OnTriggerEnter(Collider other)
    {
        velocityEstimator = playerWeapon.GetComponent <VelocityEstimator>();
        playerWeaponSpeed = velocityEstimator.GetVelocityEstimate().magnitude;

        if (other.gameObject.tag == "Player")
        {
            playerScript.health--;
            playerScript.healthSlider.value = playerScript.health;
        }
    }
示例#8
0
    public void setFree()
    {
        isGrabbed = false;

        velocityEstimator.FinishEstimatingVelocity();
        rigidbody.velocity   = velocityEstimator.GetVelocityEstimate();
        rigidbody.useGravity = true;
        //rigidbody.isKinematic = false;

        //recoveryStartTime = Time.time;
        //isRecoveringFromThrow = true;
    }
示例#9
0
 public void Collided()
 {
     print("Collideed");
     ve.FinishEstimatingVelocity();
     velocity      = ve.GetVelocityEstimate();
     stickvelocity = velocity.magnitude;
     if (stickvelocity < 0)
     {
         stickvelocity = stickvelocity * -1;
     }
     ve.BeginEstimatingVelocity();
 }
示例#10
0
    public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Vector3 angularVelocity)
    {
        if (hand.noSteamVRFallbackCamera && releaseVelocityStyle != ReleaseStyle.NoChange)
        {
            releaseVelocityStyle = ReleaseStyle.ShortEstimation; // only type that works with fallback hand is short estimation.
        }
        switch (releaseVelocityStyle)
        {
        case ReleaseStyle.ShortEstimation:
            if (velocityEstimator != null)
            {
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
            }
            else
            {
                Debug.LogWarning("[SteamVR Interaction System] Throwable: No Velocity Estimator component on object but release style set to short estimation. Please add one or change the release style.");

                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
            }
            break;

        case ReleaseStyle.AdvancedEstimation:
            hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
            break;

        case ReleaseStyle.GetFromHand:
            velocity        = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
            angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
            break;

        default:
        case ReleaseStyle.NoChange:
            velocity        = rigidbody.velocity;
            angularVelocity = rigidbody.angularVelocity;
            break;
        }

        if (releaseVelocityStyle != ReleaseStyle.NoChange)
        {
            float scaleFactor = 1.0f;
            if (scaleReleaseVelocityThreshold > 0)
            {
                scaleFactor = Mathf.Clamp01(scaleReleaseVelocityCurve.Evaluate(velocity.magnitude / scaleReleaseVelocityThreshold));
            }

            velocity *= (scaleFactor * scaleReleaseVelocity);
        }
    }
示例#11
0
    void HandAttachedUpdate(Hand hand)
    {
        if (gameObject == hand.currentAttachedObject && shouldBreak)
        {
            Vector3 velocity = velEst.GetVelocityEstimate();
            //Debug.Log("Velocity: " + velocity + velocity.magnitude);

            if (velocity.magnitude > 3.0 && dimerAttached)
            {
                BreakDimer(hand);
                dimerAttached = false;
            }
        }
    }
        private void InheritVelocity()
        {
            VelocityEstimator estimator = this.GetComponent <VelocityEstimator>();

            if (estimator != null)
            {
                estimator.FinishEstimatingVelocity();
                HandVelocity        = estimator.GetVelocityEstimate();
                HandAngularVelocity = estimator.GetAngularVelocityEstimate();

                rb.velocity        = HandVelocity;
                rb.angularVelocity = HandAngularVelocity;
            }
        }
示例#13
0
    public void ToggleRBGravity()
    {
        if (GameManager.Instance.firstPickup)
        {
            GameManager.Instance.ShowHelp(helpMessage, 7);
            GameManager.Instance.firstPickup = false;
        }

        for (int iRb = 0; iRb < rigidbodies.Length; iRb++)
        {
            rigidbodies[iRb].useGravity = !rigidbodies[iRb].useGravity;
            rigidbodies[iRb].AddForce(velEstimator.GetVelocityEstimate() * velMultiplier);
        }
    }
示例#14
0
    void HandAttachedUpdate(Hand hand)
    {
        if (gameObject == hand.currentAttachedObject && shouldBreak)
        {
            Vector3 velocity = velocityEstimator.GetVelocityEstimate();
            //Debug.Log("Velocity: " + velocity + velocity.magnitude);

            if (velocity.magnitude > 10.0 && attachedHand)
            {
                BreakRing(hand);
                attachedHand = null;
            }
        }
    }
示例#15
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;
        Vector3    slicingDirection = endSlicingPoint.position - startSlicingPoint.position;
        bool       hasHit           = Physics.Raycast(startSlicingPoint.position, slicingDirection, out hit, slicingDirection.magnitude + 0.5f, sliceableLayer);

        if (hasHit)
        {
            BrokenOre ore = hit.transform.gameObject.GetComponent <BrokenOre>();
            if (ore.possible)
            {
                Slice(hit.transform.gameObject, hit.point, velocityEstimator.GetVelocityEstimate(), ore);
            }
        }
    }
示例#16
0
    void OnDetachedFromHand(VRHand hand)
    {
        attached = false;

        hand.HoverUnlock(null);

        Rigidbody rb = GetComponent <Rigidbody>();

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

        velocityEstimator.FinishEstimatingVelocity();
        rb.velocity        = velocityEstimator.GetVelocityEstimate();
        rb.angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
    }
示例#17
0
    public void Collided()
    {
        ve.FinishEstimatingVelocity();

        velocity      = ve.GetVelocityEstimate();
        stickvelocity = velocity.magnitude;
        if (stickvelocity < 0)
        {
            stickvelocity = stickvelocity * -1;
        }
        Debug.Log("Velocity: " + stickvelocity);
        ve.BeginEstimatingVelocity();

        hand.controller.TriggerHapticPulse(400);
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.name.StartsWith("Controller"))
        {
            if (other.gameObject != OtherHand && VelocityEstimator.GetVelocityEstimate().magnitude > CollisionVelocityThreshold)
            {
                // particleManager.CmdSpawnParticleSystemByName(HighfiveEffectPrefab.name, other.ClosestPointOnBounds(transform.position));

                // hand.controller.TriggerHapticPulse(2000);

                // TODO: Vibrate this and other game object's controller's haptic!!!

                Instantiate(HighfiveEffectPrefab, other.ClosestPointOnBounds(transform.position), Quaternion.identity);

                if (OnHighFive != null)
                {
                    OnHighFive.Invoke();
                }
            }
        }
    }
示例#19
0
    void OnCollisionEnter(Collision collision)
    {
        velocityEstimator = playerWeapon.GetComponent <VelocityEstimator>();
        playerWeaponSpeed = velocityEstimator.GetVelocityEstimate().magnitude;
        Debug.Log(playerWeaponSpeed);

        if (collision.gameObject.tag == "Weapon" && playerWeaponSpeed > 2)
        {
            if (state == State.Exposed)
            {
                health--;
                healthSlider.value = health;
            }

            else
            {
                health             = health - (1 * 0.5f);
                healthSlider.value = health;
            }
        }
    }
    /**
     * Send bolt on its way after release. Calculations borrowed from Throwable.cs in
     * SteamVR InteractionSystem library.
     */
    public void Release()
    {
        released = true;

        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)) * velocityModifier;
        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);

        Invoke("TimeOut", 5f);
    }
示例#21
0
 //=========================================================================
 public Vector3 GetVelocityEstimate()
 {
     return(estimator.GetVelocityEstimate());
 }
    //----------------------------------------------------------
    //VelocityEstimatorScriptの関数を利用

    //コントローラーの速度(mm/s)取得
    public float GetVelosityMagnitude()
    {
        float VelocityMagnitude = VE.GetVelocityEstimate().magnitude * 1000; //単位: mm/s

        return(VelocityMagnitude);
    }