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
FixtureList
Gets all the fixtures attached to this body.
internal readonly FixtureCollection FixtureList
Field Value
Tag
Set the user data. Use this to store your application specific data.
public object Tag
Field Value
_angularDamping
The angular damping
private float _angularDamping
Field Value
_angularVelocity
The angular velocity
internal float _angularVelocity
Field Value
_awake
The awake
private bool _awake
Field Value
_bodyType
The body type
private BodyType _bodyType
Field Value
_enabled
The enabled
internal bool _enabled
Field Value
_fixedRotation
The fixed rotation
private bool _fixedRotation
Field Value
_force
The force
internal Vector2 _force
Field Value
_inertia
The inertia
private float _inertia
Field Value
_invI
The inv
internal float _invI
Field Value
_invMass
The inv mass
internal float _invMass
Field Value
_island
The island
internal bool _island
Field Value
_linearDamping
The linear damping
private float _linearDamping
Field Value
_linearVelocity
The linear velocity
internal Vector2 _linearVelocity
Field Value
_lock
The lock
internal int _lock
Field Value
_lockOrder
The lock order
internal int _lockOrder
Field Value
_mass
The mass
private float _mass
Field Value
_sleepTime
The sleep time
internal float _sleepTime
Field Value
_sleepingAllowed
The sleeping allowed
private bool _sleepingAllowed
Field Value
_sweep
The sweep
internal Sweep _sweep
Field Value
_torque
The torque
internal float _torque
Field Value
_world
The world
internal World _world
Field Value
_xf
The xf
internal Transform _xf
Field Value
onCollisionEventHandler
The on collision event handler
internal OnCollisionEventHandler onCollisionEventHandler
Field Value
onSeparationEventHandler
The on separation event handler
internal OnSeparationEventHandler onSeparationEventHandler
Field Value
Properties
AngularDamping
Gets or sets the angular damping.
public float AngularDamping { get; set; }
Property Value
AngularVelocity
Gets or sets the angular velocity. Radians/second.
public float AngularVelocity { get; set; }
Property Value
Awake
Set the sleep state of the body. A sleeping body has very low CPU cost.
public bool Awake { get; set; }
Property Value
BodyType
Gets or sets the body type. Warning: This property is readonly during callbacks.
public BodyType BodyType { get; set; }
Property Value
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
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
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
IgnoreCCD
Gets or sets the value of the ignore ccd
public bool IgnoreCCD { get; set; }
Property Value
IgnoreGravity
Gets or sets a value indicating whether this body ignores gravity.
public bool IgnoreGravity { get; set; }
Property Value
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
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
IslandIndex
public int IslandIndex { get; internal set; }
Property Value
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
LinearDamping
Gets or sets the linear damping.
public float LinearDamping { get; set; }
Property Value
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
LocalCenter
Get the local position of the center of mass. Warning: This property is readonly during callbacks.
public Vector2 LocalCenter { get; set; }
Property Value
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
Exceptions
- InvalidOperationException
-
Thrown when the world is Locked/Stepping.
Position
Get the world body origin position.
public Vector2 Position { get; set; }
Property Value
Revolutions
Gets the total number revolutions the body has made.
public float Revolutions { get; }
Property Value
Rotation
Get the angle in radians.
public float Rotation { get; set; }
Property Value
SleepingAllowed
You can disable sleeping on this body. If you disable sleeping, the body will be woken.
public bool SleepingAllowed { get; set; }
Property Value
World
Get the parent World of this body. This is null if the body is not attached.
public World World { get; }
Property Value
WorldCenter
Get the world position of the center of mass.
public Vector2 WorldCenter { get; }
Property Value
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
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
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
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
Returns
CreateEdge(Vector2, Vector2)
Creates the edge using the specified start
public Fixture CreateEdge(Vector2 start, Vector2 end)
Parameters
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
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
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
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
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
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
Returns
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
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
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
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
SynchronizeFixtures()
Synchronizes the fixtures
internal void SynchronizeFixtures()
SynchronizeTransform()
Synchronizes the transform
internal void SynchronizeTransform()
OnCollision
The on collision
public event OnCollisionEventHandler OnCollision
Event Type
OnSeparation
The on separation
public event OnSeparationEventHandler OnSeparation