public void Vector2_Truncate_Test() { var a = new Vector2(10, 10); var b = a.Truncate(5); Assert.AreEqual(5f, b.Length(), 0.001f); }
public void Move(GameTime time) { TimeElapsed = time.ElapsedGameTime; Vector2 OldPos = Position; Vector2 SteeringForce; SteeringForce = m_Steering.Calculate(this); //Acceleration = Force/Mass Vector2 acceleration; Vector2.Divide(ref SteeringForce, Mass, out acceleration); //update velocity Velocity += Vector2.Multiply(acceleration, (float)time.ElapsedGameTime.TotalSeconds); //make sure vehicle does not exceed maximum velocity Velocity = Velocity.Truncate(MaxSpeed); //update the position Position += Vector2.Multiply(Velocity, (float)time.ElapsedGameTime.TotalSeconds); //update the heading if the vehicle has a non zero velocity if (Velocity.LengthSquared() > 0.00000001) { Heading = Vector2.Normalize(Velocity); Side = Heading.Perpendicular(); } EntityUtils.EnforceNonPenetrationConstraint(this, World.GameEntities); World.CheckBounds(this); //update the vehicle's current cell if space partitioning is turned on //if (Steering()->isSpacePartitioningOn()) //{ // World()->CellSpace()->UpdateEntity(this, OldPos); //} //if (isSmoothingOn()) //{ // m_vSmoothedHeading = m_pHeadingSmoother->Update(Heading()); //} }