Click or drag to resize
DigitalRuneBuoyancy Class
Applies a buoyancy force to create swimming bodies.
Inheritance Hierarchy

Namespace: DigitalRune.Physics.ForceEffects
Assembly: DigitalRune.Physics (in DigitalRune.Physics.dll) Version: 1.10.0.0 (1.10.0.14427)
Syntax
public class Buoyancy : ForceField

The Buoyancy type exposes the following members.

Constructors
  NameDescription
Public methodBuoyancy
Initializes a new instance of the Buoyancy class.
Public methodBuoyancy(IAreaOfEffect)
Initializes a new instance of the Buoyancy class.
Top
Methods
  NameDescription
Public methodApply
Applies the force effect to the specified body.
(Overrides ForceFieldApply(RigidBody).)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnAddToSimulation
Called when this force effect is added to a simulation.
(Inherited from ForceEffect.)
Protected methodOnApply
Called when the simulation wants this force effect to apply forces to rigid bodies.
(Inherited from ForceField.)
Protected methodOnDisabled
Called when this force effect was disabled.
(Inherited from ForceEffect.)
Protected methodOnEnabled
Called when this force effect was enabled.
(Inherited from ForceEffect.)
Protected methodOnRemoveFromSimulation
Called when this force effect is removed from a simulation.
(Inherited from ForceEffect.)
Public methodStatic memberPrepare
Prepares the specified rigid body for the buoyancy effect.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyAngularDrag
Gets or sets the angular drag coefficient.
Public propertyAreaOfEffect
Gets or sets the area of effect.
(Inherited from ForceField.)
Public propertyDensity
Gets or sets the density of the liquid.
Public propertyEnabled
Gets or sets a value indicating whether this ForceEffect is enabled.
(Inherited from ForceEffect.)
Public propertyGravity
Gets or sets the gravity acceleration.
Public propertyLinearDrag
Gets or sets the linear drag coefficient.
Public propertySimulation
Gets the simulation to which this force effect belongs.
(Inherited from ForceEffect.)
Public propertySurface
Gets or sets the water surface plane (in world space).
Public propertyVelocity
Gets or sets the linear velocity of the water.
Top
Remarks

This force field applies a buoyancy force to create the effect of rigid bodies swimming in water. The force effect is applied to all bodies in the AreaOfEffect. Typically this will be an GeometricAreaOfEffect: A collision object models the area of the water, e.g. a box can be used to model a swimming pool and all bodies touching this box are subject to the buoyancy effect. But the area of effect does not define the plane of the water surface - this is defined using the property Surface. The area of effect could also be a GlobalAreaOfEffect which means that simply all rigid bodies in a simulation are subject to the buoyancy force. Forces are only applied if a part of the body is below the water surface.

Since this effect uses a Plane to model the water surface, it cannot be used to model uneven water surface (waves, waterfalls, etc.).

This effects also applies a drag force (damping of movement) on the swimming bodies. The strength of the damping depends on LinearDrag and AngularDrag. To find good values for these coefficients, you can use following approach: First, set the coefficients to 0 and drop an average body into the water. The body will fall into the water and shoot back out. Repeat the experiment with increasing LinearDrag values until you have a good value. Then drop rotating bodies in the water and increase the AngularDrag until rotational damping fits your needs.

This force effect stores additional information in the rigid bodies. This additional information is computed when a rigid body starts to touch the water. The computation of this information can take some time, which can be a problem if many bodies are dropped into the water simultaneously. To avoid this problem, the method Prepare(RigidBody) can be called to compute the additional information ahead of time (e.g. when the game level is loading). If there are several instances of Buoyancy in a simulation, it is sufficient to call Prepare(RigidBody) only once per rigid body. The buoyancy information is shared between Buoyancy instances.

See Also