Simulation Class
Namespace: Stride.PhysicsAssembly: Stride.Physics.dll
public class Simulation : IDisposable
| Name | Description | |
|---|---|---|
| Fields | ||
| DisableSimulation | Totally disable the simulation if set to true |
|
| OnSimulationCreation | Temporary solution to inject engine flags |
|
| Properties | ||
| ColliderShapesRenderGroup | ||
| ColliderShapesRendering | Enables or disables the rendering of collider shapes |
|
| ContinuousCollisionDetection | ||
| FixedTimeStep | By decreasing the size of fixedTimeStep, you are increasing the “resolution” of the simulation. Default is 1.0f / 60.0f or 60fps |
|
| Gravity | Gets or sets the gravity. |
|
| MaxSubSteps | The maximum number of steps that the Simulation is allowed to take each tick. If the engine is running slow (large deltaTime), then you must increase the number of maxSubSteps to compensate for this, otherwise your simulation is “losing” time. It's important that frame DeltaTime is always less than MaxSubSteps*FixedTimeStep, otherwise you are losing time. |
|
| SpeculativeContactRestitution | ||
| Methods | ||
| AddConstraint(Constraint) | Adds the constraint to the engine processing pipeline. |
|
| AddConstraint(Constraint, Boolean) | Adds the constraint to the engine processing pipeline. |
|
| ClearForces() | ||
| CreateConstraint(ConstraintTypes, RigidbodyComponent, Matrix, Boolean) | Creates the constraint. |
|
| CreateConstraint(ConstraintTypes, RigidbodyComponent, RigidbodyComponent, Matrix, Matrix, Boolean) | Creates the constraint. |
|
| Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
|
| OnSimulationBegin(Simulation.SimulationArgs) | ||
| OnSimulationEnd(Simulation.SimulationArgs) | ||
| Raycast(Vector3, Vector3, CollisionFilterGroups, CollisionFilterGroupFlags) | Raycasts and returns the closest hit |
|
| Raycast(Vector3, Vector3, out HitResult, CollisionFilterGroups, CollisionFilterGroupFlags) | Raycasts, returns true when it hit something |
|
| RaycastPenetrating(Vector3, Vector3, IList<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags) | Raycasts penetrating any shape the ray encounters. Filtering by CollisionGroup |
|
| RemoveConstraint(Constraint) | Removes the constraint from the engine processing pipeline. |
|
| ShapeSweep(ColliderShape, Matrix, Matrix, CollisionFilterGroups, CollisionFilterGroupFlags) | Performs a sweep test using a collider shape and returns the closest hit |
|
| ShapeSweepPenetrating(ColliderShape, Matrix, Matrix, IList<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags) | Performs a sweep test using a collider shape and never stops until "to" |
|
| Events | ||
| SimulationBegin | Called right before the physics simulation. This event might not be fired by the main thread. |
|
| SimulationEnd | Called right after the physics simulation. This event might not be fired by the main thread. |
|
Fields
DisableSimulation
Totally disable the simulation if set to true
public static bool DisableSimulation
Field Value
| Type | Description |
|---|---|
| System.Boolean |
OnSimulationCreation
Temporary solution to inject engine flags
public static Simulation.OnSimulationCreationDelegate OnSimulationCreation
Field Value
| Type | Description |
|---|---|
| Simulation.OnSimulationCreationDelegate |
Properties
ColliderShapesRenderGroup
public RenderGroup ColliderShapesRenderGroup { get; set; }
Property Value
| Type | Description |
|---|---|
| RenderGroup |
ColliderShapesRendering
Enables or disables the rendering of collider shapes
public bool ColliderShapesRendering { set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
ContinuousCollisionDetection
public bool ContinuousCollisionDetection { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
FixedTimeStep
By decreasing the size of fixedTimeStep, you are increasing the “resolution” of the simulation. Default is 1.0f / 60.0f or 60fps
public float FixedTimeStep { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Gravity
Gets or sets the gravity.
public Vector3 Gravity { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 | The gravity. |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Cannot perform this action when the physics engine is set to CollisionsOnly or Cannot perform this action when the physics engine is set to CollisionsOnly |
MaxSubSteps
The maximum number of steps that the Simulation is allowed to take each tick. If the engine is running slow (large deltaTime), then you must increase the number of maxSubSteps to compensate for this, otherwise your simulation is “losing” time. It's important that frame DeltaTime is always less than MaxSubSteps*FixedTimeStep, otherwise you are losing time.
public int MaxSubSteps { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
SpeculativeContactRestitution
public bool SpeculativeContactRestitution { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
AddConstraint(Constraint)
Adds the constraint to the engine processing pipeline.
public void AddConstraint(Constraint constraint)
Parameters
| Type | Name | Description |
|---|---|---|
| Constraint | constraint | The constraint. |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Cannot perform this action when the physics engine is set to CollisionsOnly |
AddConstraint(Constraint, Boolean)
Adds the constraint to the engine processing pipeline.
public void AddConstraint(Constraint constraint, bool disableCollisionsBetweenLinkedBodies)
Parameters
| Type | Name | Description |
|---|---|---|
| Constraint | constraint | The constraint. |
| System.Boolean | disableCollisionsBetweenLinkedBodies | if set to |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Cannot perform this action when the physics engine is set to CollisionsOnly |
ClearForces()
public void ClearForces()
CreateConstraint(ConstraintTypes, RigidbodyComponent, Matrix, Boolean)
Creates the constraint.
public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA = false)
Parameters
| Type | Name | Description |
|---|---|---|
| ConstraintTypes | type | The type. |
| RigidbodyComponent | rigidBodyA | The rigid body a. |
| Matrix | frameA | The frame a. |
| System.Boolean | useReferenceFrameA | if set to |
Returns
| Type | Description |
|---|---|
| Constraint |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid or A Gear constraint always needs two rigidbodies to be created. |
CreateConstraint(ConstraintTypes, RigidbodyComponent, RigidbodyComponent, Matrix, Matrix, Boolean)
Creates the constraint.
public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA = false)
Parameters
| Type | Name | Description |
|---|---|---|
| ConstraintTypes | type | The type. |
| RigidbodyComponent | rigidBodyA | The rigid body a. |
| RigidbodyComponent | rigidBodyB | The rigid body b. |
| Matrix | frameA | The frame a. |
| Matrix | frameB | The frame b. |
| System.Boolean | useReferenceFrameA | if set to |
Returns
| Type | Description |
|---|---|
| Constraint |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
OnSimulationBegin(Simulation.SimulationArgs)
protected virtual void OnSimulationBegin(Simulation.SimulationArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| Simulation.SimulationArgs | e |
OnSimulationEnd(Simulation.SimulationArgs)
protected virtual void OnSimulationEnd(Simulation.SimulationArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| Simulation.SimulationArgs | e |
Raycast(Vector3, Vector3, CollisionFilterGroups, CollisionFilterGroupFlags)
Raycasts and returns the closest hit
public HitResult Raycast(Vector3 from, Vector3 to, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = CollisionFilterGroupFlags.AllFilter | (CollisionFilterGroupFlags)-65536)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | From. |
| Vector3 | to | To. |
| CollisionFilterGroups | filterGroup | The collision group of this raycast |
| CollisionFilterGroupFlags | filterFlags | The collision group that this raycast can collide with |
Returns
| Type | Description |
|---|---|
| HitResult | The list with hit results. |
Raycast(Vector3, Vector3, out HitResult, CollisionFilterGroups, CollisionFilterGroupFlags)
Raycasts, returns true when it hit something
public bool Raycast(Vector3 from, Vector3 to, out HitResult result, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = CollisionFilterGroupFlags.AllFilter | (CollisionFilterGroupFlags)-65536)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | From. |
| Vector3 | to | To. |
| HitResult | result | Raycast info |
| CollisionFilterGroups | filterGroup | The collision group of this raycast |
| CollisionFilterGroupFlags | filterFlags | The collision group that this raycast can collide with |
Returns
| Type | Description |
|---|---|
| System.Boolean | The list with hit results. |
RaycastPenetrating(Vector3, Vector3, IList<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags)
Raycasts penetrating any shape the ray encounters. Filtering by CollisionGroup
public void RaycastPenetrating(Vector3 from, Vector3 to, IList<HitResult> resultsOutput, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = CollisionFilterGroupFlags.AllFilter | (CollisionFilterGroupFlags)-65536)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | From. |
| Vector3 | to | To. |
| System.Collections.Generic.IList<HitResult> | resultsOutput | The list to fill with results. |
| CollisionFilterGroups | filterGroup | The collision group of this raycast |
| CollisionFilterGroupFlags | filterFlags | The collision group that this raycast can collide with |
RemoveConstraint(Constraint)
Removes the constraint from the engine processing pipeline.
public void RemoveConstraint(Constraint constraint)
Parameters
| Type | Name | Description |
|---|---|---|
| Constraint | constraint | The constraint. |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | Cannot perform this action when the physics engine is set to CollisionsOnly |
ShapeSweep(ColliderShape, Matrix, Matrix, CollisionFilterGroups, CollisionFilterGroupFlags)
Performs a sweep test using a collider shape and returns the closest hit
public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = CollisionFilterGroupFlags.AllFilter | (CollisionFilterGroupFlags)-65536)
Parameters
| Type | Name | Description |
|---|---|---|
| ColliderShape | shape | The shape. |
| Matrix | from | From. |
| Matrix | to | To. |
| CollisionFilterGroups | filterGroup | The collision group of this shape sweep |
| CollisionFilterGroupFlags | filterFlags | The collision group that this shape sweep can collide with |
Returns
| Type | Description |
|---|---|
| HitResult |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | This kind of shape cannot be used for a ShapeSweep. |
ShapeSweepPenetrating(ColliderShape, Matrix, Matrix, IList<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags)
Performs a sweep test using a collider shape and never stops until "to"
public void ShapeSweepPenetrating(ColliderShape shape, Matrix from, Matrix to, IList<HitResult> resultsOutput, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = CollisionFilterGroupFlags.AllFilter | (CollisionFilterGroupFlags)-65536)
Parameters
| Type | Name | Description |
|---|---|---|
| ColliderShape | shape | The shape. |
| Matrix | from | From. |
| Matrix | to | To. |
| System.Collections.Generic.IList<HitResult> | resultsOutput | The list to fill with results. |
| CollisionFilterGroups | filterGroup | The collision group of this shape sweep |
| CollisionFilterGroupFlags | filterFlags | The collision group that this shape sweep can collide with |
Exceptions
| Type | Condition |
|---|---|
| System.Exception | This kind of shape cannot be used for a ShapeSweep. |
Events
SimulationBegin
Called right before the physics simulation. This event might not be fired by the main thread.
public event EventHandler<Simulation.SimulationArgs> SimulationBegin
Event Type
| Type | Description |
|---|---|
| System.EventHandler<Simulation.SimulationArgs> |
SimulationEnd
Called right after the physics simulation. This event might not be fired by the main thread.
public event EventHandler<Simulation.SimulationArgs> SimulationEnd
Event Type
| Type | Description |
|---|---|
| System.EventHandler<Simulation.SimulationArgs> |