예제 #1
0
        private void DoPIDMoveTarget(float timeStep, uint frameNum)
        {
            float tau;

            OpenMetaverse.Vector3 target;
            float gtau;

            lock (_properties)
            {
                tau    = _properties.MoveTargetTau;
                target = _properties.MoveTarget;
                gtau   = _properties.GrabTargetTau;
            }

            // Grab overrides move to target
            if (gtau != 0)
            {
                return;
            }

            if (tau > MIN_TAU)
            {
                //i had a whole elaborate setup here to do this.. turns out the linden
                //implementation was much simpler
                OpenMetaverse.Vector3 distance = target - _position;

                if (distance.LengthSquared() <= AT_TARGET_TOLERANCE_SQUARED)
                {
                    if (_velocity != OpenMetaverse.Vector3.Zero)
                    {
                        StopLinearMovement();
                        return;
                    }
                }

                ChangeGravityIfNeeded();
                _dynActor.AddForce(PhysUtil.OmvVectorToPhysx((distance * (1.0f / tau)) - _velocity), PhysX.ForceMode.VelocityChange, true);
            }
            else // Check for stop move to target - need to turn gravity back on if buoyancy isn't enabled
            if ((target == OpenMetaverse.Vector3.Zero) && (tau == 0.0f))
            {
                ChangeGravityIfNeeded();
            }
        }
예제 #2
0
        private bool DoGrabTarget(float timeStep, uint frameNum)
        {
            float tau;

            OpenMetaverse.Vector3 target;
            lock (_properties)
            {
                tau    = _properties.GrabTargetTau;
                target = _properties.GrabTarget;
            }

            if (tau > MIN_TAU)
            {
                _dynActor.AddTorque(PhysUtil.OmvVectorToPhysx(-_angularVelocity * 0.9f), PhysX.ForceMode.VelocityChange, false);
                OpenMetaverse.Vector3 distance = target - _position;

                if (distance.LengthSquared() <= AT_TARGET_TOLERANCE_SQUARED)
                {
                    if (_velocity != OpenMetaverse.Vector3.Zero)
                    {
                        StopLinearMovement();
                        return(true);
                    }
                }

                _grabDisableGravity = true;
                ChangeGravityIfNeeded();
                _dynActor.AddForce(PhysUtil.OmvVectorToPhysx((distance * (1.0f / tau)) - _velocity), PhysX.ForceMode.VelocityChange, true);
            }
            else
            {
                // Check for stop move to grab - need to turn gravity back on if buoyancy isn't enabled
                if (tau == 0.0f)
                {
                    _grabDisableGravity = false;
                    ChangeGravityIfNeeded();
                    return(false);
                }
            }
            return(true);
        }
예제 #3
0
        private void DecayForces(float secondsSinceLastSync)
        {
            if (_vForces != OpenMetaverse.Vector3.Zero)
            {
                if (_vTarget != OpenMetaverse.Vector3.Zero)
                {

                    if (!_flying)
                    {
                        //user movement instantly cancels any x or y axis movement, but
                        //it does not cancel z axis movement while jumping. This allows the user to have
                        //a nice jump while walking
                        _vForces.X = 0f;
                        _vForces.Y = 0f;
                    }
                    else
                    {
                        _vForces = OpenMetaverse.Vector3.Zero;
                    }
                }
                else
                {
                    //decay velocity in relation to velocity to badly mimic drag
                    OpenMetaverse.Vector3 decayForce;
                    if (_collidingGround)
                    {
                        decayForce = OpenMetaverse.Vector3.Multiply(_vForces, 2.0f * secondsSinceLastSync);
                    }
                    else
                    {
                        decayForce = OpenMetaverse.Vector3.Multiply(_vForces, 1.0f * secondsSinceLastSync);
                    }

                    _vForces -= decayForce;

                    if (_vForces.LengthSquared() < MIN_FORCE_MAG_BEFORE_ZEROING_SQUARED)
                    {
                        _vForces = OpenMetaverse.Vector3.Zero;
                    }
                }
            }
        }