Click or drag to resize
DigitalRuneForceEffect Class
Applies a force onto rigid 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 abstract class ForceEffect

The ForceEffect type exposes the following members.

Constructors
  NameDescription
Protected methodForceEffect
Initializes a new instance of the ForceEffect class.
Top
Methods
  NameDescription
Protected methodStatic memberAddForce(RigidBody, Vector3F)
Applies a force to the rigid body at the center of mass.
Protected methodStatic memberAddForce(RigidBody, Vector3F, Vector3F)
Applies a force to the rigid body.
Protected methodStatic memberAddTorque
Applies a torque to the rigid body at the center of mass.
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.
Protected methodOnApply
Called when the simulation wants this force effect to apply forces to rigid bodies.
Protected methodOnDisabled
Called when this force effect was disabled.
Protected methodOnEnabled
Called when this force effect was enabled.
Protected methodOnRemoveFromSimulation
Called when this force effect is removed from a simulation.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyEnabled
Gets or sets a value indicating whether this ForceEffect is enabled.
Public propertySimulation
Gets the simulation to which this force effect belongs.
Top
Remarks

If a force effect is added to a Simulation (see ForceEffects), it will be called during a simulation time step to apply forces to the rigid bodies of the simulation.

Self-Removal: It is allowed that a force effect instance removes itself at any time from the Simulation. This can be used to create one-shot effects - a force effect that applies forces and automatically removes itself from the simulation in OnApply.

Order of events: The force effect has three special OnXxx methods that will be used in this order:

OnAddToSimulation Is called when the force effect instance was added to the ForceEffects collection of a Simulation. Before this method is called, the property Simulation is . When this method is called, the property Simulation is set to the simulation.
OnApply Is called when the simulation wants the force effect to apply its forces to the rigid bodies. OnApply can be called after OnAddToSimulation, but never before. The property Simulation is always initialized when OnApply is called. OnApply is only called if the force effect is Enabled.
OnRemoveFromSimulation Is called before the force effect instance is removed from the ForceEffects collection of Simulation. When this method is called, the property Simulation is still set. After OnRemoveFromSimulation the property Simulation is . OnApply can only be called between OnAddToSimulation and OnRemoveFromSimulation.

Applying Forces: A ForceEffect must not call RigidBody.AddForce(Vector3F) or other force related methods of the RigidBody directly. Those methods are reserved for the user. The reason is: If a user applies a force with RigidBody.AddForce(Vector3F), the added force is constant for the whole duration of Simulation.Update(TimeSpan). If the simulation divides one call to Update(TimeSpan) in several sub time steps, the same user force is applied in all sub time steps. But force effects are called by the simulation in each sub time step. They can set a different force in each sub time step. Therefore, force effects must use a different set of methods and these methods are AddForce(RigidBody, Vector3F, Vector3F), AddForce(RigidBody, Vector3F) and AddTorque(RigidBody, Vector3F) of this class.

To sum up: Classes derived from ForceEffect must use the AddForce/AddTorque methods of the ForceEffect base class to apply forces to rigid bodies.

See Also