Esempio n. 1
0
        /// <summary>
        /// Apply a force to the body without increasing it's velocity above a specific limit.
        /// </summary>
        public void ApplyForce(Vector2 force, float maxVelocity)
        {
            if (!IsValidValue(maxVelocity, "max velocity"))
            {
                return;
            }

            Vector2 velocityAddition = force / Mass * (float)Timing.Step;
            Vector2 newVelocity      = FarseerBody.LinearVelocity + velocityAddition;

            float newSpeedSqr = newVelocity.LengthSquared();

            if (newSpeedSqr > maxVelocity * maxVelocity && Vector2.Dot(FarseerBody.LinearVelocity, force) > 0.0f)
            {
                float newSpeed       = (float)Math.Sqrt(newSpeedSqr);
                float maxVelAddition = maxVelocity - newSpeed;
                if (maxVelAddition <= 0.0f)
                {
                    return;
                }
                force = velocityAddition.ClampLength(maxVelAddition) * Mass / (float)Timing.Step;
            }

            if (!IsValidValue(force, "clamped force", -1e10f, 1e10f))
            {
                return;
            }
            FarseerBody.ApplyForce(force);
        }
Esempio n. 2
0
        /// <summary>
        /// Apply an impulse to the body without increasing it's velocity above a specific limit.
        /// </summary>
        public void ApplyLinearImpulse(Vector2 impulse, Vector2 point, float maxVelocity)
        {
            if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f))
            {
                return;
            }
            if (!IsValidValue(point, "point"))
            {
                return;
            }
            if (!IsValidValue(maxVelocity, "max velocity"))
            {
                return;
            }

            Vector2 velocityAddition = impulse / Mass;
            Vector2 newVelocity      = FarseerBody.LinearVelocity + velocityAddition;
            float   newSpeedSqr      = newVelocity.LengthSquared();

            if (newSpeedSqr > maxVelocity * maxVelocity)
            {
                newVelocity = newVelocity.ClampLength(maxVelocity);
            }

            if (!IsValidValue((newVelocity - FarseerBody.LinearVelocity), "new velocity", -1000.0f, 1000.0f))
            {
                return;
            }

            FarseerBody.ApplyLinearImpulse((newVelocity - FarseerBody.LinearVelocity) * Mass, point);
            FarseerBody.AngularVelocity = MathHelper.Clamp(
                FarseerBody.AngularVelocity,
                -NetConfig.MaxPhysicsBodyAngularVelocity,
                NetConfig.MaxPhysicsBodyAngularVelocity);
        }
Esempio n. 3
0
        /// <summary>
        /// Apply an impulse to the body without increasing it's velocity above a specific limit.
        /// </summary>
        public void ApplyLinearImpulse(Vector2 impulse, float maxVelocity)
        {
            if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f))
            {
                return;
            }
            if (!IsValidValue(maxVelocity, "max velocity"))
            {
                return;
            }

            Vector2 velocityAddition = impulse / Mass;
            Vector2 newVelocity      = FarseerBody.LinearVelocity + velocityAddition;
            float   newSpeedSqr      = newVelocity.LengthSquared();

            if (newSpeedSqr > maxVelocity * maxVelocity)
            {
                newVelocity = newVelocity.ClampLength(maxVelocity);
            }

            if (!IsValidValue((newVelocity - FarseerBody.LinearVelocity), "new velocity", -1000.0f, 1000.0f))
            {
                return;
            }

            FarseerBody.ApplyLinearImpulse((newVelocity - FarseerBody.LinearVelocity) * Mass);
        }
Esempio n. 4
0
 public void ApplyTorque(float torque)
 {
     if (!IsValidValue(torque, "torque"))
     {
         return;
     }
     FarseerBody.ApplyTorque(torque);
 }
Esempio n. 5
0
 public void ApplyForce(Vector2 force)
 {
     if (!IsValidValue(force, "force", -1e10f, 1e10f))
     {
         return;
     }
     FarseerBody.ApplyForce(force);
 }
Esempio n. 6
0
 public void ApplyForce(Vector2 force, Vector2 point)
 {
     if (!IsValidValue(force, "force", -1e10f, 1e10f))
     {
         return;
     }
     if (!IsValidValue(point, "point"))
     {
         return;
     }
     FarseerBody.ApplyForce(force, point);
 }
Esempio n. 7
0
        public void ApplyLinearImpulse(Vector2 impulse)
        {
            if (!IsValidValue(impulse / FarseerBody.Mass, "new velocity", -1000f, 1000f))
            {
                return;
            }
            if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f))
            {
                return;
            }

            FarseerBody.ApplyLinearImpulse(impulse);
        }
Esempio n. 8
0
        public void MoveToPos(Vector2 simPosition, float force, Vector2?pullPos = null)
        {
            if (pullPos == null)
            {
                pullPos = FarseerBody.Position;
            }

            if (!IsValidValue(simPosition, "position", -1e10f, 1e10f))
            {
                return;
            }
            if (!IsValidValue(force, "force"))
            {
                return;
            }

            Vector2 vel      = FarseerBody.LinearVelocity;
            Vector2 deltaPos = simPosition - (Vector2)pullPos;

            deltaPos *= force;
            FarseerBody.ApplyLinearImpulse((deltaPos - vel * 0.5f) * FarseerBody.Mass, (Vector2)pullPos);
        }
Esempio n. 9
0
        public bool SetTransformIgnoreContacts(Vector2 simPosition, float rotation, bool setPrevTransform = true)
        {
            System.Diagnostics.Debug.Assert(MathUtils.IsValid(simPosition));
            System.Diagnostics.Debug.Assert(Math.Abs(simPosition.X) < 1000000.0f);
            System.Diagnostics.Debug.Assert(Math.Abs(simPosition.Y) < 1000000.0f);

            if (!IsValidValue(simPosition, "position", -1e10f, 1e10f))
            {
                return(false);
            }
            if (!IsValidValue(rotation, "rotation"))
            {
                return(false);
            }

            FarseerBody.SetTransformIgnoreContacts(ref simPosition, rotation);
            if (setPrevTransform)
            {
                SetPrevTransform(simPosition, rotation);
            }
            return(true);
        }
Esempio n. 10
0
 public void ResetDynamics()
 {
     FarseerBody.ResetDynamics();
 }