ForceEffect Class |
Namespace: DigitalRune.Physics.ForceEffects
The ForceEffect type exposes the following members.
Name | Description | |
---|---|---|
ForceEffect |
Initializes a new instance of the ForceEffect class.
|
Name | Description | |
---|---|---|
AddForce(RigidBody, Vector3F) |
Applies a force to the rigid body at the center of mass.
| |
AddForce(RigidBody, Vector3F, Vector3F) |
Applies a force to the rigid body.
| |
AddTorque |
Applies a torque to the rigid body at the center of mass.
| |
Equals | (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnAddToSimulation |
Called when this force effect is added to a simulation.
| |
OnApply |
Called when the simulation wants this force effect to apply forces to rigid bodies.
| |
OnDisabled |
Called when this force effect was disabled.
| |
OnEnabled |
Called when this force effect was enabled.
| |
OnRemoveFromSimulation |
Called when this force effect is removed from a simulation.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
Enabled |
Gets or sets a value indicating whether this ForceEffect is enabled.
| |
Simulation |
Gets the simulation to which this force effect belongs.
|
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.