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
constraint
ConstraintThe 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
constraint
ConstraintThe constraint.
disableCollisionsBetweenLinkedBodies
boolif 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
type
ConstraintTypesThe type.
rigidBodyA
RigidbodyComponentThe rigid body a.
frameA
MatrixThe frame a.
useReferenceFrameA
boolif 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
type
ConstraintTypesThe type.
rigidBodyA
RigidbodyComponentThe rigid body a.
rigidBodyB
RigidbodyComponentThe rigid body b.
frameA
MatrixThe frame a.
frameB
MatrixThe frame b.
useReferenceFrameA
boolif 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
rigidBodyA
RigidbodyComponentThe rigid body a.
pivotInA
Vector3Pivot point in body a.
axisInA
Vector3Axis in body a.
rigidBodyB
RigidbodyComponentThe rigid body b.
pivotInB
Vector3Pivot point in body b.
axisInB
Vector3Axis in body b.
useReferenceFrameA
boolif 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
rigidBodyA
RigidbodyComponentThe rigid body a.
pivotInA
Vector3Pivot point in body a.
axisInA
Vector3Axis in body a.
useReferenceFrameA
boolif 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
from
Vector3The starting point of this raycast
to
Vector3The end point of this raycast
filterGroup
CollisionFilterGroupsThe collision group of this raycast
filterFlags
CollisionFilterGroupFlagsThe collision group that this raycast can collide with
hitTriggers
boolWhether this test should collide with PhysicsTriggerComponentBase
eFlags
EFlagsFlags 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
from
Vector3The starting point of this raycast
to
Vector3The end point of this raycast
result
HitResultInformation about this test
filterGroup
CollisionFilterGroupsThe collision group of this raycast
filterFlags
CollisionFilterGroupFlagsThe collision group that this raycast can collide with
hitTriggers
boolWhether this test should collide with PhysicsTriggerComponentBase
eFlags
EFlagsFlags 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
from
Vector3The starting point of this raycast
to
Vector3The end point of this raycast
resultsOutput
ICollection<HitResult>The collection to add intersections to
filterGroup
CollisionFilterGroupsThe collision group of this raycast
filterFlags
CollisionFilterGroupFlagsThe collision group that this raycast can collide with
hitTriggers
boolWhether this test should collide with PhysicsTriggerComponentBase
eFlags
EFlagsFlags that control how this ray test is performed
RemoveConstraint(Constraint)
Removes the constraint from the engine processing pipeline.
public void RemoveConstraint(Constraint constraint)
Parameters
constraint
ConstraintThe 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
shape
ColliderShapeThe shape used when testing collisions with colliders in the simulation
from
MatrixThe starting point of this sweep
to
MatrixThe end point of this sweep
filterGroup
CollisionFilterGroupsThe collision group of this shape sweep
filterFlags
CollisionFilterGroupFlagsThe collision group that this shape sweep can collide with
hitTriggers
boolWhether 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
shape
ColliderShapeThe shape against which colliders in the simulation will be tested
from
MatrixThe starting point of this sweep
to
MatrixThe end point of this sweep
resultsOutput
ICollection<HitResult>The collection to add hit results to
filterGroup
CollisionFilterGroupsThe collision group of this shape sweep
filterFlags
CollisionFilterGroupFlagsThe collision group that this shape sweep can collide with
hitTriggers
boolWhether 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