Class Simulation
public class Simulation : IDisposable
- Inheritance
-
Simulation
- Implements
- Extension Methods
Fields
DisableSimulation
Totally disable the simulation if set to true
public static bool DisableSimulation
Field Value
OnSimulationCreation
Temporary solution to inject engine flags
public static Simulation.OnSimulationCreationDelegate OnSimulationCreation
Field Value
Properties
ColliderShapesRenderGroup
public RenderGroup ColliderShapesRenderGroup { get; set; }
Property Value
ColliderShapesRendering
Enables or disables the rendering of collider shapes
public bool ColliderShapesRendering { set; }
Property Value
ContinuousCollisionDetection
public bool ContinuousCollisionDetection { get; set; }
Property Value
CurrentCollisions
Every pair of components currently colliding with each other
public ICollection<Collision> CurrentCollisions { get; }
Property Value
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
Gravity
Gets or sets the gravity.
public Vector3 Gravity { get; set; }
Property Value
- Vector3
The gravity.
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly
IncludeStaticAgainstStaticCollisions
Should static - static collisions of StaticColliderComponent yield PhysicsComponent.NewCollision() and added to PhysicsComponent.Collisions ?
public bool IncludeStaticAgainstStaticCollisions { get; set; }
Property Value
Remarks
Regardless of the state of this value you can still retrieve static-static collisions through CurrentCollisions.
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.
[Obsolete("Value is ignored, use MaxTickDuration instead")]
public int MaxSubSteps { get; set; }
Property Value
MaxTickDuration
public float MaxTickDuration { get; set; }
Property Value
SpeculativeContactRestitution
public bool SpeculativeContactRestitution { get; set; }
Property Value
Methods
AddConstraint(Constraint)
Adds the constraint to the engine processing pipeline.
public void AddConstraint(Constraint constraint)
Parameters
constraintConstraintThe constraint.
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly
AddConstraint(Constraint, bool)
Adds the constraint to the engine processing pipeline.
public void AddConstraint(Constraint constraint, bool disableCollisionsBetweenLinkedBodies)
Parameters
constraintConstraintThe constraint.
disableCollisionsBetweenLinkedBodiesboolif set to
true[disable collisions between linked bodies].
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly
ClearForces()
public void ClearForces()
CreateConstraint(ConstraintTypes, RigidbodyComponent, Matrix, bool)
Creates the constraint.
public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA = false)
Parameters
typeConstraintTypesThe type.
rigidBodyARigidbodyComponentThe rigid body a.
frameAMatrixThe frame a.
useReferenceFrameAboolif set to
true[use reference frame a].
Returns
Exceptions
- 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, bool)
Creates the constraint.
public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA = false)
Parameters
typeConstraintTypesThe type.
rigidBodyARigidbodyComponentThe rigid body a.
rigidBodyBRigidbodyComponentThe rigid body b.
frameAMatrixThe frame a.
frameBMatrixThe frame b.
useReferenceFrameAboolif set to
true[use reference frame a].
Returns
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid
CreateHingeConstraint(RigidbodyComponent, Vector3, Vector3, RigidbodyComponent, Vector3, Vector3, bool)
Creates a hinge constraint using a specialized constructor.
public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, RigidbodyComponent rigidBodyB, Vector3 pivotInB, Vector3 axisInB, bool useReferenceFrameA = false)
Parameters
rigidBodyARigidbodyComponentThe rigid body a.
pivotInAVector3Pivot point in body a.
axisInAVector3Axis in body a.
rigidBodyBRigidbodyComponentThe rigid body b.
pivotInBVector3Pivot point in body b.
axisInBVector3Axis in body b.
useReferenceFrameAboolif set to
true[use reference frame a].
Returns
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid
CreateHingeConstraint(RigidbodyComponent, Vector3, Vector3, bool)
Creates a hinge constraint using a specialized constructor.
public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, bool useReferenceFrameA = false)
Parameters
rigidBodyARigidbodyComponentThe rigid body a.
pivotInAVector3Pivot point in body a.
axisInAVector3Axis in body a.
useReferenceFrameAboolif set to
true[use reference frame a].
Returns
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly or RigidBody must be valid
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
OnSimulationBegin(SimulationArgs)
protected virtual void OnSimulationBegin(Simulation.SimulationArgs e)
Parameters
OnSimulationEnd(SimulationArgs)
protected virtual void OnSimulationEnd(Simulation.SimulationArgs e)
Parameters
Raycast(Vector3, Vector3, CollisionFilterGroups, CollisionFilterGroupFlags, bool, EFlags)
Raycasts and returns the closest hit
public HitResult Raycast(Vector3 from, Vector3 to, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false, EFlags eFlags = EFlags.None)
Parameters
fromVector3The starting point of this raycast
toVector3The end point of this raycast
filterGroupCollisionFilterGroupsThe collision group of this raycast
filterFlagsCollisionFilterGroupFlagsThe collision group that this raycast can collide with
hitTriggersboolWhether this test should collide with PhysicsTriggerComponentBase
eFlagsEFlagsFlags that control how this ray test is performed
Returns
- HitResult
The result of this test
Raycast(Vector3, Vector3, out HitResult, CollisionFilterGroups, CollisionFilterGroupFlags, bool, EFlags)
Raycasts, returns true when it hit something
public bool Raycast(Vector3 from, Vector3 to, out HitResult result, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false, EFlags eFlags = EFlags.None)
Parameters
fromVector3The starting point of this raycast
toVector3The end point of this raycast
resultHitResultInformation about this test
filterGroupCollisionFilterGroupsThe collision group of this raycast
filterFlagsCollisionFilterGroupFlagsThe collision group that this raycast can collide with
hitTriggersboolWhether this test should collide with PhysicsTriggerComponentBase
eFlagsEFlagsFlags that control how this ray test is performed
Returns
- bool
True if the test collided with an object in the simulation
RaycastPenetrating(Vector3, Vector3, ICollection<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags, bool, EFlags)
Raycasts penetrating any shape the ray encounters. Filtering by CollisionGroup
public void RaycastPenetrating(Vector3 from, Vector3 to, ICollection<HitResult> resultsOutput, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false, EFlags eFlags = EFlags.None)
Parameters
fromVector3The starting point of this raycast
toVector3The end point of this raycast
resultsOutputICollection<HitResult>The collection to add intersections to
filterGroupCollisionFilterGroupsThe collision group of this raycast
filterFlagsCollisionFilterGroupFlagsThe collision group that this raycast can collide with
hitTriggersboolWhether this test should collide with PhysicsTriggerComponentBase
eFlagsEFlagsFlags that control how this ray test is performed
RemoveConstraint(Constraint)
Removes the constraint from the engine processing pipeline.
public void RemoveConstraint(Constraint constraint)
Parameters
constraintConstraintThe constraint.
Exceptions
- Exception
Cannot perform this action when the physics engine is set to CollisionsOnly
ShapeSweep(ColliderShape, Matrix, Matrix, CollisionFilterGroups, CollisionFilterGroupFlags, bool)
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)-1, bool hitTriggers = false)
Parameters
shapeColliderShapeThe shape used when testing collisions with colliders in the simulation
fromMatrixThe starting point of this sweep
toMatrixThe end point of this sweep
filterGroupCollisionFilterGroupsThe collision group of this shape sweep
filterFlagsCollisionFilterGroupFlagsThe collision group that this shape sweep can collide with
hitTriggersboolWhether this test should collide with PhysicsTriggerComponentBase
Returns
- HitResult
The result of this test
Exceptions
- ArgumentException
This kind of shape cannot be used for a ShapeSweep.
ShapeSweepPenetrating(ColliderShape, Matrix, Matrix, ICollection<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags, bool)
Performs a sweep test using a collider shape and never stops until "to"
public void ShapeSweepPenetrating(ColliderShape shape, Matrix from, Matrix to, ICollection<HitResult> resultsOutput, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false)
Parameters
shapeColliderShapeThe shape against which colliders in the simulation will be tested
fromMatrixThe starting point of this sweep
toMatrixThe end point of this sweep
resultsOutputICollection<HitResult>The collection to add hit results to
filterGroupCollisionFilterGroupsThe collision group of this shape sweep
filterFlagsCollisionFilterGroupFlagsThe collision group that this shape sweep can collide with
hitTriggersboolWhether this test should collide with PhysicsTriggerComponentBase
Exceptions
- ArgumentException
This kind of shape cannot be used for a ShapeSweep.
Events
PostTick
Called right after processing a tick of the physics simulation, this may never occur before many updates, or occur multiple times between updates depending on this Simulation properties
public event Simulation.SimulationTickEvent PostTick
Event Type
PreTick
Called right before processing a tick of the physics simulation, this may never occur before many updates, or occur multiple times between updates depending on this Simulation properties
public event Simulation.SimulationTickEvent PreTick
Event Type
SimulationBegin
Called before the physics simulation. This event might not be fired by the main thread.
[Obsolete("The simulation is not guaranteed to tick following this call, use PreTick instead. This is the same thing as Update")]
public event EventHandler<Simulation.SimulationArgs> SimulationBegin
Event Type
SimulationEnd
Called after the physics simulation. This event might not be fired by the main thread.
[Obsolete("The simulation is not guaranteed to have ticked before this call, use PostTick instead. This is the same thing as Update")]
public event EventHandler<Simulation.SimulationArgs> SimulationEnd