/// <summary> /// Determines the drag vector on a CollisionObject. /// </summary> /// <param name="obj">The CollisionObject.</param> /// <returns>A vector representing the drag-force.</returns> public static Vector2 DragVector(CollisionObject obj) { float dragY = -0.5f * PhysicsConstants.airDensity * PhysicsConstants.dragCoeff * (float)Math.Pow(obj.GetCollisionBox().Width *PhysicsConstants.metersPerPixel, 2) * (float)Math.Pow(obj.GetSpeed().Y, 3) / Math.Abs(obj.GetSpeed().Y); float dragX = -0.5f * PhysicsConstants.airDensity * PhysicsConstants.dragCoeff * (float)Math.Pow(obj.GetCollisionBox().Height *PhysicsConstants.metersPerPixel, 2) * (float)Math.Pow(obj.GetSpeed().X, 3) / Math.Abs(obj.GetSpeed().X); #region check for NaN if (float.IsNaN(dragY)) { dragY = 0; } if (float.IsNaN(dragX)) { dragX = 0; } #endregion return(new Vector2(dragX / obj.GetMass(), dragY / obj.GetMass()) * (float)Globals.deltaTime.TotalSeconds * PhysicsConstants.metersPerPixel); }
/// <summary> /// Determines the gravity force on a CollisionObject. /// </summary> /// <param name="obj">The object to determine the gravity-force for.</param> /// <returns>A vector representing the gravitational force.</returns> public static Vector2 Gravity(CollisionObject obj) { return(new Vector2(0, PhysicsConstants.gravity * obj.GetMass()) * (float)Globals.deltaTime.TotalSeconds * PhysicsConstants.metersPerPixel); }