Table of Contents

Class Body

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

The body class

public class Body

Inheritance

Inherited Members

Constructors

Body()

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

public Body()

Fields

ControllerFilter

The all

public ControllerFilter ControllerFilter

Field Value

ControllerFilter

FixtureList

Gets all the fixtures attached to this body.

internal readonly FixtureCollection FixtureList

Field Value

FixtureCollection

Tag

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

public object Tag

Field Value

object

_angularDamping

The angular damping

private float _angularDamping

Field Value

float

_angularVelocity

The angular velocity

internal float _angularVelocity

Field Value

float

_awake

The awake

private bool _awake

Field Value

bool

_bodyType

The body type

private BodyType _bodyType

Field Value

BodyType

_enabled

The enabled

internal bool _enabled

Field Value

bool

_fixedRotation

The fixed rotation

private bool _fixedRotation

Field Value

bool

_force

The force

internal Vector2 _force

Field Value

Vector2

_inertia

The inertia

private float _inertia

Field Value

float

_invI

The inv

internal float _invI

Field Value

float

_invMass

The inv mass

internal float _invMass

Field Value

float

_island

The island

internal bool _island

Field Value

bool

_linearDamping

The linear damping

private float _linearDamping

Field Value

float

_linearVelocity

The linear velocity

internal Vector2 _linearVelocity

Field Value

Vector2

_lock

The lock

internal int _lock

Field Value

int

_lockOrder

The lock order

internal int _lockOrder

Field Value

int

_mass

The mass

private float _mass

Field Value

float

_sleepTime

The sleep time

internal float _sleepTime

Field Value

float

_sleepingAllowed

The sleeping allowed

private bool _sleepingAllowed

Field Value

bool

_sweep

The sweep

internal Sweep _sweep

Field Value

Sweep

_torque

The torque

internal float _torque

Field Value

float

_world

The world

internal World _world

Field Value

World

_xf

The xf

internal Transform _xf

Field Value

Transform

onCollisionEventHandler

The on collision event handler

internal OnCollisionEventHandler onCollisionEventHandler

Field Value

OnCollisionEventHandler

onSeparationEventHandler

The on separation event handler

internal OnSeparationEventHandler onSeparationEventHandler

Field Value

OnSeparationEventHandler

Properties

AngularDamping

Gets or sets the angular damping.

public float AngularDamping { get; set; }

Property Value

float

AngularVelocity

Gets or sets the angular velocity. Radians/second.

public float AngularVelocity { get; set; }

Property Value

float

Awake

Set the sleep state of the body. A sleeping body has very low CPU cost.

public bool Awake { get; set; }

Property Value

bool

BodyType

Gets or sets the body type. Warning: This property is readonly during callbacks.

public BodyType BodyType { get; set; }

Property Value

BodyType

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

ContactList

Get the list of all contacts attached to this body. Warning: this list changes during the time step and you may miss some collisions if you don't use callback events.

public ContactEdge ContactList { get; internal set; }

Property Value

ContactEdge

Enabled

Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a b2World object and remains in the body list. Warning: This property is readonly during callbacks.

public bool Enabled { get; set; }

Property Value

bool

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

FixedRotation

Set this body to have fixed rotation. This causes the mass to be reset.

public bool FixedRotation { get; set; }

Property Value

bool

IgnoreCCD

Gets or sets the value of the ignore ccd

public bool IgnoreCCD { get; set; }

Property Value

bool

IgnoreGravity

Gets or sets a value indicating whether this body ignores gravity.

public bool IgnoreGravity { get; set; }

Property Value

bool

Inertia

Get or set the rotational inertia of the body about the local origin. usually in kg-m^2. Warning: This property is readonly during callbacks.

public float Inertia { get; set; }

Property Value

float

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

IsBullet

Gets or sets a value indicating whether this body should be included in the CCD solver.

public bool IsBullet { get; set; }

Property Value

bool

IslandIndex

public int IslandIndex { get; internal set; }

Property Value

int

Remarks

Deprecated in version 1.6

JointList

Get the list of all joints attached to this body.

public JointEdge JointList { get; internal set; }

Property Value

JointEdge

LinearDamping

Gets or sets the linear damping.

public float LinearDamping { get; set; }

Property Value

float

LinearVelocity

Get or sets the linear velocity of the center of mass. Property has no effect on Alis.Core.Physic.Dynamics.BodyType.Static bodies.

public Vector2 LinearVelocity { get; set; }

Property Value

Vector2

LocalCenter

Get the local position of the center of mass. Warning: This property is readonly during callbacks.

public Vector2 LocalCenter { get; set; }

Property Value

Vector2

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Mass

Gets or sets the mass. Usually in kilograms (kg). Warning: This property is readonly during callbacks.

public float Mass { get; set; }

Property Value

float

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Position

Get the world body origin position.

public Vector2 Position { get; set; }

Property Value

Vector2

Revolutions

Gets the total number revolutions the body has made.

public float Revolutions { get; }

Property Value

float

Rotation

Get the angle in radians.

public float Rotation { get; set; }

Property Value

float

SleepingAllowed

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

public bool SleepingAllowed { get; set; }

Property Value

bool

World

Get the parent World of this body. This is null if the body is not attached.

public World World { get; }

Property Value

World

WorldCenter

Get the world position of the center of mass.

public Vector2 WorldCenter { get; }

Property Value

Vector2

Methods

Add(Fixture)

Warning: This method is locked during callbacks.

public void Add(Fixture fixture)

Parameters

fixture Fixture

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

Advance(float)

Advances the alpha

internal void Advance(float alpha)

Parameters

alpha float

The alpha

ApplyAngularImpulse(float)

Apply an angular impulse.

public void ApplyAngularImpulse(float impulse)

Parameters

impulse float

The angular impulse in units of kgmm/s.

ApplyForce(Vector2, Vector2)

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.

public void ApplyForce(Vector2 force, Vector2 point)

Parameters

force Vector2

The world force vector, usually in Newtons (N).

point Vector2

The world position of the point of application.

ApplyForce(ref Vector2)

Applies a force at the center of mass.

public void ApplyForce(ref Vector2 force)

Parameters

force Vector2

The force.

ApplyForce(Vector2)

Applies a force at the center of mass.

public void ApplyForce(Vector2 force)

Parameters

force Vector2

The force.

ApplyForce(ref Vector2, ref Vector2)

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.

public void ApplyForce(ref Vector2 force, ref Vector2 point)

Parameters

force Vector2

The world force vector, usually in Newtons (N).

point Vector2

The world position of the point of application.

ApplyLinearImpulse(Vector2)

Apply an impulse at a point. This immediately modifies the velocity. This wakes up the body.

public void ApplyLinearImpulse(Vector2 impulse)

Parameters

impulse Vector2

The world impulse vector, usually in N-seconds or kg-m/s.

ApplyLinearImpulse(Vector2, Vector2)

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.

public void ApplyLinearImpulse(Vector2 impulse, Vector2 point)

Parameters

impulse Vector2

The world impulse vector, usually in N-seconds or kg-m/s.

point Vector2

The world position of the point of application.

ApplyLinearImpulse(ref Vector2)

Apply an impulse at a point. This immediately modifies the velocity. This wakes up the body.

public void ApplyLinearImpulse(ref Vector2 impulse)

Parameters

impulse Vector2

The world impulse vector, usually in N-seconds or kg-m/s.

ApplyLinearImpulse(ref Vector2, ref Vector2)

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.

public void ApplyLinearImpulse(ref Vector2 impulse, ref Vector2 point)

Parameters

impulse Vector2

The world impulse vector, usually in N-seconds or kg-m/s.

point Vector2

The world position of the point of application.

ApplyTorque(float)

Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.

public void ApplyTorque(float torque)

Parameters

torque float

The torque about the z-axis (out of the screen), usually in N-m.

Clone(World)

Makes a clone of the body. Fixtures and therefore shapes are not included. Use DeepClone() to clone the body, as well as fixtures and shapes.

public Body Clone(World world = null)

Parameters

world World

Returns

Body

CreateChainShape(Vertices)

Creates the chain shape using the specified vertices

public Fixture CreateChainShape(Vertices vertices)

Parameters

vertices Vertices

The vertices

Returns

Fixture

The fixture

CreateCircle(float, float)

Creates the circle using the specified radius

public Fixture CreateCircle(float radius, float density)

Parameters

radius float

The radius

density float

The density

Returns

Fixture

The fixture

Exceptions

ArgumentOutOfRangeException

radius Radius must be more than 0 meters

CreateCircle(float, float, Vector2)

Creates the circle using the specified radius

public Fixture CreateCircle(float radius, float density, Vector2 offset)

Parameters

radius float

The radius

density float

The density

offset Vector2

The offset

Returns

Fixture

The fixture

Exceptions

ArgumentOutOfRangeException

radius Radius must be more than 0 meters

CreateCompoundPolygon(List<Vertices>, float)

Creates the compound polygon using the specified list

public List<Fixture> CreateCompoundPolygon(List<Vertices> list, float density)

Parameters

list List<Vertices>

The list

density float

The density

Returns

List<Fixture>

The res

CreateEdge(Vector2, Vector2)

Creates the edge using the specified start

public Fixture CreateEdge(Vector2 start, Vector2 end)

Parameters

start Vector2

The start

end Vector2

The end

Returns

Fixture

The fixture

CreateEllipse(float, float, int, float)

Creates the ellipse using the specified x radius

public Fixture CreateEllipse(float xRadius, float yRadius, int edges, float density)

Parameters

xRadius float

The radius

yRadius float

The radius

edges int

The edges

density float

The density

Returns

Fixture

The fixture

Exceptions

ArgumentOutOfRangeException

xRadius X-radius must be more than 0

ArgumentOutOfRangeException

yRadius Y-radius must be more than 0

CreateFixture(Shape)

Creates a fixture and attach it to this body. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step. Warning: This method is locked during callbacks.

public virtual Fixture CreateFixture(Shape shape)

Parameters

shape Shape

The shape.

Returns

Fixture

CreateLineArc(float, int, float, bool)

Creates the line arc using the specified radians

public Fixture CreateLineArc(float radians, int sides, float radius, bool closed)

Parameters

radians float

The radians

sides int

The sides

radius float

The radius

closed bool

The closed

Returns

Fixture

The fixture

CreateLoopShape(Vertices)

Creates the loop shape using the specified vertices

public Fixture CreateLoopShape(Vertices vertices)

Parameters

vertices Vertices

The vertices

Returns

Fixture

The fixture

CreatePolygon(Vertices, float)

Creates the polygon using the specified vertices

public Fixture CreatePolygon(Vertices vertices, float density)

Parameters

vertices Vertices

The vertices

density float

The density

Returns

Fixture

The fixture

Exceptions

ArgumentOutOfRangeException

vertices Too few points to be a polygon

CreateProxies()

Create all proxies.

internal void CreateProxies()

CreateRectangle(float, float, float, Vector2)

Creates the rectangle using the specified width

public Fixture CreateRectangle(float width, float height, float density, Vector2 offset)

Parameters

width float

The width

height float

The height

density float

The density

offset Vector2

The offset

Returns

Fixture

The fixture

CreateSolidArc(float, float, int, float)

Creates the solid arc using the specified density

public List<Fixture> CreateSolidArc(float density, float radians, int sides, float radius)

Parameters

density float

The density

radians float

The radians

sides int

The sides

radius float

The radius

Returns

List<Fixture>

A list of fixture

DeepClone(World)

Clones the body and all attached fixtures and shapes. Simply said, it makes a complete copy of the body.

public Body DeepClone(World world = null)

Parameters

world World

Returns

Body

DestroyContacts()

Destroy the attached contacts.

private void DestroyContacts()

DestroyProxies()

Destroy all proxies.

internal void DestroyProxies()

GetLinearVelocityFromLocalPoint(Vector2)

Get the world velocity of a local point.

public Vector2 GetLinearVelocityFromLocalPoint(Vector2 localPoint)

Parameters

localPoint Vector2

A point in local coordinates.

Returns

Vector2

The world velocity of a point.

GetLinearVelocityFromLocalPoint(ref Vector2)

Get the world velocity of a local point.

public Vector2 GetLinearVelocityFromLocalPoint(ref Vector2 localPoint)

Parameters

localPoint Vector2

A point in local coordinates.

Returns

Vector2

The world velocity of a point.

GetLinearVelocityFromWorldPoint(Vector2)

Get the world linear velocity of a world point attached to this body.

public Vector2 GetLinearVelocityFromWorldPoint(Vector2 worldPoint)

Parameters

worldPoint Vector2

A point in world coordinates.

Returns

Vector2

The world velocity of a point.

GetLinearVelocityFromWorldPoint(ref Vector2)

Get the world linear velocity of a world point attached to this body.

public Vector2 GetLinearVelocityFromWorldPoint(ref Vector2 worldPoint)

Parameters

worldPoint Vector2

A point in world coordinates.

Returns

Vector2

The world velocity of a point.

GetLocalPoint(ref Vector2)

Gets a local point relative to the body's origin given a world point. Note that the vector only takes the rotation into account, not the position.

public Vector2 GetLocalPoint(ref Vector2 worldPoint)

Parameters

worldPoint Vector2

A point in world coordinates.

Returns

Vector2

The corresponding local point relative to the body's origin.

GetLocalPoint(Vector2)

Gets a local point relative to the body's origin given a world point.

public Vector2 GetLocalPoint(Vector2 worldPoint)

Parameters

worldPoint Vector2

A point in world coordinates.

Returns

Vector2

The corresponding local point relative to the body's origin.

GetLocalVector(ref Vector2)

Gets a local vector given a world vector. Note that the vector only takes the rotation into account, not the position.

public Vector2 GetLocalVector(ref Vector2 worldVector)

Parameters

worldVector Vector2

A vector in world coordinates.

Returns

Vector2

The corresponding local vector.

GetLocalVector(Vector2)

Gets a local vector given a world vector. Note that the vector only takes the rotation into account, not the position.

public Vector2 GetLocalVector(Vector2 worldVector)

Parameters

worldVector Vector2

A vector in world coordinates.

Returns

Vector2

The corresponding local vector.

GetTransform()

Get the body transform for the body's origin.

public Transform GetTransform()

Returns

Transform

GetTransform(out Transform)

Get the body transform for the body's origin.

public void GetTransform(out Transform transform)

Parameters

transform Transform

The transform of the body's origin.

GetWorldPoint(ref Vector2)

Get the world coordinates of a point given the local coordinates.

public Vector2 GetWorldPoint(ref Vector2 localPoint)

Parameters

localPoint Vector2

A point on the body measured relative the the body's origin.

Returns

Vector2

The same point expressed in world coordinates.

GetWorldPoint(Vector2)

Get the world coordinates of a point given the local coordinates.

public Vector2 GetWorldPoint(Vector2 localPoint)

Parameters

localPoint Vector2

A point on the body measured relative the the body's origin.

Returns

Vector2

The same point expressed in world coordinates.

GetWorldVector(ref Vector2)

Get the world coordinates of a vector given the local coordinates. Note that the vector only takes the rotation into account, not the position.

public Vector2 GetWorldVector(ref Vector2 localVector)

Parameters

localVector Vector2

A vector fixed in the body.

Returns

Vector2

The same vector expressed in world coordinates.

GetWorldVector(Vector2)

Get the world coordinates of a vector given the local coordinates.

public Vector2 GetWorldVector(Vector2 localVector)

Parameters

localVector Vector2

A vector fixed in the body.

Returns

Vector2

The same vector expressed in world coordinates.

Remove(Fixture)

Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed. Warning: This method is locked during callbacks.

public virtual void Remove(Fixture fixture)

Parameters

fixture Fixture

The fixture to be removed.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

ResetDynamics()

Resets the dynamics of this body. Sets torque, force and linear/angular velocity to 0

public void ResetDynamics()

ResetMassData()

This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass.

public void ResetMassData()

SetCollidesWith(Category)

Warning: This method applies the value on existing Fixtures. It's not a property of Body.

public void SetCollidesWith(Category category)

Parameters

category Category

Remarks

Deprecated in version 1.6

SetCollisionCategories(Category)

Warning: This method applies the value on existing Fixtures. It's not a property of Body.

public void SetCollisionCategories(Category category)

Parameters

category Category

Remarks

Deprecated in version 1.6

SetCollisionGroup(short)

Warning: This method applies the value on existing Fixtures. It's not a property of Body.

public void SetCollisionGroup(short collisionGroup)

Parameters

collisionGroup short

Remarks

Deprecated in version 1.6

SetFriction(float)

Set friction on all fixtures. Warning: This method applies the value on existing Fixtures. It's not a property of Body.

public void SetFriction(float friction)

Parameters

friction float

Remarks

Deprecated in version 1.6

SetIsSensor(bool)

Warning: This method applies the value on existing Fixtures. It's not a property of Body.

public void SetIsSensor(bool isSensor)

Parameters

isSensor bool

Remarks

Deprecated in version 1.6

SetRestitution(float)

Set restitution on all fixtures. Warning: This method applies the value on existing Fixtures. It's not a property of Body.

public void SetRestitution(float restitution)

Parameters

restitution float

Remarks

Deprecated in version 1.6

SetTransform(ref Vector2, float)

Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior. Warning: This method is locked during callbacks.

public void SetTransform(ref Vector2 position, float rotation)

Parameters

position Vector2

The world position of the body's local origin.

rotation float

The world rotation in radians.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

SetTransform(Vector2, float)

Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior. Warning: This method is locked during callbacks.

public void SetTransform(Vector2 position, float rotation)

Parameters

position Vector2

The world position of the body's local origin.

rotation float

The world rotation in radians.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

SetTransformIgnoreContacts(ref Vector2, float)

For teleporting a body without considering new contacts immediately. Warning: This method is locked during callbacks.

public void SetTransformIgnoreContacts(ref Vector2 position, float angle)

Parameters

position Vector2

The position.

angle float

The angle.

Exceptions

InvalidOperationException

Thrown when the world is Locked/Stepping.

ShouldCollide(Body)

This is used to prevent connected bodies from colliding. It may lie, depending on the collideConnected flag.

internal bool ShouldCollide(Body other)

Parameters

other Body

The other body.

Returns

bool

SynchronizeFixtures()

Synchronizes the fixtures

internal void SynchronizeFixtures()

SynchronizeTransform()

Synchronizes the transform

internal void SynchronizeTransform()

OnCollision

The on collision

public event OnCollisionEventHandler OnCollision

Event Type

OnCollisionEventHandler

OnSeparation

The on separation

public event OnSeparationEventHandler OnSeparation

Event Type

OnSeparationEventHandler