Table of Contents

Class World

Namespace
Alis.Core.Physic.Dynamics
Assembly
Alis.dll

The world class manages all physics entities, dynamic simulation, and asynchronous queries.

public class World

Inheritance

Inherited Members

Constructors

World()

Initializes a new instance of the Alis.Core.Physic.Dynamics.World class.

public World()

World(Vector2)

Initializes a new instance of the Alis.Core.Physic.Dynamics.World class.

public World(Vector2 gravity)

Parameters

gravity Vector2

The gravity.

World(IBroadPhase)

Initializes a new instance of the Alis.Core.Physic.Dynamics.World class.

public World(IBroadPhase broadPhase)

Parameters

broadPhase IBroadPhase

Fields

BodyAdded

Fires whenever a body has been added

public BodyDelegate BodyAdded

Field Value

BodyDelegate

BodyList

Get the world body list.

internal readonly BodyCollection BodyList

Field Value

BodyCollection

BodyRemoved

Fires whenever a body has been removed

public BodyDelegate BodyRemoved

Field Value

BodyDelegate

ContactManager

Get the contact manager for testing.

internal readonly ContactManager ContactManager

Field Value

ContactManager

ControllerAdded

Fires every time a controller is added to the World.

public ControllerDelegate ControllerAdded

Field Value

ControllerDelegate

ControllerList

The controller list

internal readonly ControllerCollection ControllerList

Field Value

ControllerCollection

ControllerRemoved

Fires every time a controlelr is removed form the World.

public ControllerDelegate ControllerRemoved

Field Value

ControllerDelegate

FixtureAdded

Fires whenever a fixture has been added

public FixtureDelegate FixtureAdded

Field Value

FixtureDelegate

FixtureRemoved

Fires whenever a fixture has been removed

public FixtureDelegate FixtureRemoved

Field Value

FixtureDelegate

JointAdded

Fires whenever a joint has been added

public JointDelegate JointAdded

Field Value

JointDelegate

JointList

Get the world joint list.

internal readonly JointCollection JointList

Field Value

JointCollection

JointRemoved

Fires whenever a joint has been removed

public JointDelegate JointRemoved

Field Value

JointDelegate

Tag

Set the user data. Use this to store your application specific data.

public object Tag

Field Value

object

_gravity

The gravity

private Vector2 _gravity

Field Value

Vector2

_input

The toi input

private TOIInput _input

Field Value

TOIInput

_invDt0

The inv dt

private float _invDt0

Field Value

float

_queryCallbackCache

The query callback cache

private readonly BroadPhaseQueryCallback _queryCallbackCache

Field Value

BroadPhaseQueryCallback

_queryDelegateTmp

The query delegate tmp

private QueryReportFixtureDelegate _queryDelegateTmp

Field Value

QueryReportFixtureDelegate

_rayCastCallbackCache

The ray cast callback cache

private readonly BroadPhaseRayCastCallback _rayCastCallbackCache

Field Value

BroadPhaseRayCastCallback

_rayCastDelegateTmp

The ray cast delegate tmp

private RayCastReportFixtureDelegate _rayCastDelegateTmp

Field Value

RayCastReportFixtureDelegate

_stack

The body

private Body[] _stack

Field Value

Body[]

_stepComplete

The step complete

private bool _stepComplete

Field Value

bool

_subStepping

This is only for debugging the solver

private const bool _subStepping = false

Field Value

bool

_testPointDelegateCache

The test point delegate cache

private readonly QueryReportFixtureDelegate _testPointDelegateCache

Field Value

QueryReportFixtureDelegate

_testPointFixtureTmp

The test point fixture tmp

private Fixture _testPointFixtureTmp

Field Value

Fixture

_testPointPointTmp

The test point point tmp

private Vector2 _testPointPointTmp

Field Value

Vector2

_warmStarting

This is only for debugging the solver

private const bool _warmStarting = true

Field Value

bool

_watch

The stopwatch

private readonly Stopwatch _watch

Field Value

Stopwatch

_worldHasNewFixture

The world has new fixture

internal bool _worldHasNewFixture

Field Value

bool

Properties

AddRemoveTime

Gets the value of the add remove time

public TimeSpan AddRemoveTime { get; }

Property Value

TimeSpan

ContactCount

Get the number of contacts (each may have 0 or more contact points).

public int ContactCount { get; }

Property Value

int

ContactList

Get the world contact list. ContactList is the head of a circular linked list. Use Contact.Next to get the next contact in the world list. A contact equal to ContactList indicates the end of the list.

public ContactListHead ContactList { get; }

Property Value

ContactListHead

Examples

for (Contact c = World.ContactList.Next; c != World..ContactList; c = c.Next)

ContactsUpdateTime

Gets or sets the value of the contacts update time

public TimeSpan ContactsUpdateTime { get; private set; }

Property Value

TimeSpan

ContinuousPhysicsTime

Gets or sets the value of the continuous physics time

public TimeSpan ContinuousPhysicsTime { get; private set; }

Property Value

TimeSpan

ControllersUpdateTime

Gets or sets the value of the controllers update time

public TimeSpan ControllersUpdateTime { get; private set; }

Property Value

TimeSpan

Enabled

If false, the whole simulation stops. It still processes added and removed geometries.

public bool Enabled { get; set; }

Property Value

bool

Gravity

Change the global gravity vector.

public Vector2 Gravity { get; set; }

Property Value

Vector2

IsLocked

Is the world locked (in the middle of a time step).

public bool IsLocked { get; private set; }

Property Value

bool

Island

Gets the value of the island

public Island Island { get; }

Property Value

Island

NewContactsTime

Gets or sets the value of the new contacts time

public TimeSpan NewContactsTime { get; private set; }

Property Value

TimeSpan

ProxyCount

Get the number of broad-phase proxies.

public int ProxyCount { get; }

Property Value

int

SolveUpdateTime

Gets or sets the value of the solve update time

public TimeSpan SolveUpdateTime { get; private set; }

Property Value

TimeSpan

UpdateTime

Gets or sets the value of the update time

public TimeSpan UpdateTime { get; private set; }

Property Value

TimeSpan

Methods

Add(Body)

Add a rigid body. Warning: This method is locked during callbacks.

public virtual void Add(Body body)

Parameters

body Body

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Add(Joint)

Create a joint to constrain bodies together. This may cause the connected bodies to cease colliding. Warning: This method is locked during callbacks.

public void Add(Joint joint)

Parameters

joint Joint

The joint.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Add(Controller)

Warning: This method is locked during callbacks.

public void Add(Controller controller)

Parameters

controller Controller

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Clear()

Warning: This method is locked during callbacks.

public void Clear()

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

ClearForces()

Call this after you are done with time steps to clear the forces. You normally call this after each call to Step, unless you are performing sub-steps. By default, forces will be automatically cleared, so you don't need to call this function.

public void ClearForces()

CreateBody(Vector2, float, BodyType)

Creates the body using the specified position

public virtual Body CreateBody(Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateCapsule(float, float, int, float, int, float, Vector2, float, BodyType)

Creates the capsule using the specified height

public Body CreateCapsule(float height, float topRadius, int topEdges, float bottomRadius, int bottomEdges, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

height float

The height

topRadius float

The top radius

topEdges int

The top edges

bottomRadius float

The bottom radius

bottomEdges int

The bottom edges

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateCapsule(float, float, float, Vector2, float, BodyType)

Creates the capsule using the specified height

public Body CreateCapsule(float height, float endRadius, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

height float

The height

endRadius float

The end radius

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateChain(Vector2, Vector2, float, float, int, float, bool)

Creates a chain.

public Path CreateChain(Vector2 start, Vector2 end, float linkWidth, float linkHeight, int numberOfLinks, float linkDensity, bool attachRopeJoint)

Parameters

start Vector2

The start.

end Vector2

The end.

linkWidth float

The width.

linkHeight float

The height.

numberOfLinks int

The number of links.

linkDensity float

The link density.

attachRopeJoint bool

Creates a rope joint between start and end. This enforces the length of the rope. Said in another way: it makes the rope less bouncy.

Returns

Path

CreateChainShape(Vertices, Vector2)

Creates the chain shape using the specified vertices

public Body CreateChainShape(Vertices vertices, Vector2 position = default)

Parameters

vertices Vertices

The vertices

position Vector2

The position

Returns

Body

The body

CreateCircle(float, float, Vector2, BodyType)

Creates the circle using the specified radius

public Body CreateCircle(float radius, float density, Vector2 position = default, BodyType bodyType = BodyType.Static)

Parameters

radius float

The radius

density float

The density

position Vector2

The position

bodyType BodyType

The body type

Returns

Body

The body

CreateCompoundPolygon(List<Vertices>, float, Vector2, float, BodyType)

Creates the compound polygon using the specified list

public Body CreateCompoundPolygon(List<Vertices> list, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

list List<Vertices>

The list

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateEdge(Vector2, Vector2)

Creates the edge using the specified start

public Body CreateEdge(Vector2 start, Vector2 end)

Parameters

start Vector2

The start

end Vector2

The end

Returns

Body

The body

CreateEllipse(float, float, int, float, Vector2, float, BodyType)

Creates the ellipse using the specified x radius

public Body CreateEllipse(float xRadius, float yRadius, int edges, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

xRadius float

The radius

yRadius float

The radius

edges int

The edges

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateGear(float, int, float, float, float, Vector2, float, BodyType)

Creates the gear using the specified radius

public Body CreateGear(float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

radius float

The radius

numberOfTeeth int

The number of teeth

tipPercentage float

The tip percentage

toothHeight float

The tooth height

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateLineArc(float, int, float, bool, Vector2, float, BodyType)

Creates the line arc using the specified radians

public Body CreateLineArc(float radians, int sides, float radius, bool closed = false, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

radians float

The radians

sides int

The sides

radius float

The radius

closed bool

The closed

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateLoopShape(Vertices, Vector2)

Creates the loop shape using the specified vertices

public Body CreateLoopShape(Vertices vertices, Vector2 position = default)

Parameters

vertices Vertices

The vertices

position Vector2

The position

Returns

Body

The body

CreatePolygon(Vertices, float, Vector2, float, BodyType)

Creates the polygon using the specified vertices

public Body CreatePolygon(Vertices vertices, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

vertices Vertices

The vertices

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateRectangle(float, float, float, Vector2, float, BodyType)

Creates the rectangle using the specified width

public Body CreateRectangle(float width, float height, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

width float

The width

height float

The height

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

Exceptions

ArgumentOutOfRangeException

height Height must be more than 0 meters

ArgumentOutOfRangeException

width Width must be more than 0 meters

CreateRoundedRectangle(float, float, float, float, int, float, Vector2, float, BodyType)

Creates the rounded rectangle using the specified width

public Body CreateRoundedRectangle(float width, float height, float xRadius, float yRadius, int segments, float density, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

width float

The width

height float

The height

xRadius float

The radius

yRadius float

The radius

segments int

The segments

density float

The density

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

CreateSolidArc(float, float, int, float, Vector2, float, BodyType)

Creates the solid arc using the specified density

public Body CreateSolidArc(float density, float radians, int sides, float radius, Vector2 position = default, float rotation = 0, BodyType bodyType = BodyType.Static)

Parameters

density float

The density

radians float

The radians

sides int

The sides

radius float

The radius

position Vector2

The position

rotation float

The rotation

bodyType BodyType

The body type

Returns

Body

The body

QueryAABB(QueryReportFixtureDelegate, AABB)

Query the world for all fixtures that potentially overlap the provided AABB. Inside the callback: Return true: Continues the query Return false: Terminate the query

public void QueryAABB(QueryReportFixtureDelegate callback, AABB aabb)

Parameters

callback QueryReportFixtureDelegate

A user implemented callback class.

aabb AABB

The aabb query box.

QueryAABB(QueryReportFixtureDelegate, ref AABB)

Query the world for all fixtures that potentially overlap the provided AABB. Inside the callback: Return true: Continues the query Return false: Terminate the query

public void QueryAABB(QueryReportFixtureDelegate callback, ref AABB aabb)

Parameters

callback QueryReportFixtureDelegate

A user implemented callback class.

aabb AABB

The aabb query box.

QueryAABBCallback(int)

Describes whether this instance query aabb callback

private bool QueryAABBCallback(int proxyId)

Parameters

proxyId int

The proxy id

Returns

bool

The bool

RayCast(RayCastReportFixtureDelegate, Vector2, Vector2)

Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you get the closest point, any point, or n-points. The ray-cast ignores shapes that contain the starting point. Inside the callback: return -1: ignore this fixture and continue return 0: terminate the ray cast return fraction: clip the ray to this point return 1: don't clip the ray and continue

public void RayCast(RayCastReportFixtureDelegate callback, Vector2 point1, Vector2 point2)

Parameters

callback RayCastReportFixtureDelegate

A user implemented callback class.

point1 Vector2

The ray starting point.

point2 Vector2

The ray ending point.

RayCastCallback(ref RayCastInput, int)

Rays the cast callback using the specified ray cast input

private float RayCastCallback(ref RayCastInput rayCastInput, int proxyId)

Parameters

rayCastInput RayCastInput

The ray cast input

proxyId int

The proxy id

Returns

float

The float

Remove(Body)

Destroy a rigid body. Warning: This automatically deletes all associated shapes and joints. Warning: This method is locked during callbacks.

public virtual void Remove(Body body)

Parameters

body Body

The body.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Remove(Joint)

Destroy a joint. This may cause the connected bodies to begin colliding. Warning: This method is locked during callbacks.

public void Remove(Joint joint)

Parameters

joint Joint

The joint.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Remove(Controller)

Warning: This method is locked during callbacks.

public void Remove(Controller controller)

Parameters

controller Controller

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

ShiftOrigin(Vector2)

public void ShiftOrigin(Vector2 newOrigin)

Parameters

newOrigin Vector2

Solve(ref TimeStep)

Solves the step

private void Solve(ref TimeStep step)

Parameters

step TimeStep

The step

SolveTOI(ref TimeStep, ref SolverIterations)

Solves the toi using the specified step

private void SolveTOI(ref TimeStep step, ref SolverIterations iterations)

Parameters

step TimeStep

The step

iterations SolverIterations

The iterations

Step(TimeSpan)

Take a time step. This performs collision detection, integration, and consraint solution.

public void Step(TimeSpan dt)

Parameters

dt TimeSpan

The amount of time to simulate, this should not vary.

Step(TimeSpan, ref SolverIterations)

Take a time step. This performs collision detection, integration, and consraint solution.

public void Step(TimeSpan dt, ref SolverIterations iterations)

Parameters

dt TimeSpan

The amount of time to simulate, this should not vary.

iterations SolverIterations

Step(float)

Take a time step. This performs collision detection, integration, and consraint solution. Warning: This method is locked during callbacks.

public void Step(float dt)

Parameters

dt float

The amount of time to simulate in seconds, this should not vary.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Step(float, ref SolverIterations)

Take a time step. This performs collision detection, integration, and consraint solution. Warning: This method is locked during callbacks.

public void Step(float dt, ref SolverIterations iterations)

Parameters

dt float

The amount of time to simulate in seconds, this should not vary.

iterations SolverIterations

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

TestPoint(Vector2)

Tests the point using the specified point

public Fixture TestPoint(Vector2 point)

Parameters

point Vector2

The point

Returns

Fixture

The test point fixture tmp

TestPointCallback(Fixture)

Describes whether this instance test point callback

private bool TestPointCallback(Fixture fixture)

Parameters

fixture Fixture

The fixture

Returns

bool

The bool