|
Axmol 3.0.0-89d6d9a
|
A Rigidbody2D affected by physics2d. More...
#include <Rigidbody2D.h>
Public Member Functions | |
| virtual Collider2D * | addCollider (Collider2D *collider, bool addMassAndMoment=true) |
| Add a collider to body. | |
| void | removeCollider (Collider2D *collider, bool reduceMassAndMoment=true) |
| Remove a collider from body. | |
| void | removeCollider (int tag, bool reduceMassAndMoment=true) |
| Remove a collider from body. | |
| void | removeAllColliders (bool reduceMassAndMoment=true) |
| Remove all colliders. | |
| const Vector< Collider2D * > & | getColliders () const |
| Get the body colliders. | |
| Collider2D * | getFirstCollider () const |
| Get the first collider of the body colliders. | |
| Collider2D * | getCollider (int tag) const |
| get the collider of the body. | |
| virtual void | applyForce (const Vec2 &force, const Vec2 &offset=Vec2::zero) |
| Applies a continuous force to body. | |
| virtual void | resetForces () |
| reset all the force applied to body. | |
| virtual void | applyImpulse (const Vec2 &impulse, const Vec2 &offset=Vec2::zero) |
| Applies a immediate force to body. | |
| virtual void | applyTorque (float torque) |
| Applies a torque force to body. | |
| virtual void | setVelocity (const Vec2 &velocity) |
| Set the velocity of a body. | |
| virtual Vec2 | getVelocity () |
| Get the velocity of a body. | |
| virtual void | setAngularVelocity (float velocity) |
| Set the angular velocity in degrees of a body. | |
| virtual Vec2 | getVelocityAtLocalPoint (const Vec2 &point) |
| Get the angular velocity of a body at a local point. | |
| virtual Vec2 | getVelocityAtWorldPoint (const Vec2 &point) |
| get the angular velocity of a body at a world point | |
| virtual float | getAngularVelocity () |
| get the angular velocity in degrees of a body | |
| virtual void | setVelocityLimit (float limit) |
| set the max of velocity | |
| virtual float | getVelocityLimit () |
| get the max of velocity | |
| virtual void | setAngularVelocityLimit (float limit) |
| set the max of angular velocity in degrees | |
| virtual float | getAngularVelocityLimit () |
| get the max of angular velocity in degrees | |
| void | removeFromWorld () |
| remove the body from the world it added to | |
| PhysicsWorld2D * | getWorld () const |
| get the world body added to. | |
| Node * | getNode () const |
| get the node the body set to. | |
| void | setEventEnabled (ContactEventBits events, bool enabled) |
| Enable or disable one or more event types for this collider. | |
| uint64_t | getCategoryBits () const |
| Return bitmask of first collider. | |
| void | setCategoryBits (uint64_t categoryBits) |
| A mask that defines which categories this physics body belongs to. | |
| int | getCollisionMaskBits () const |
| Return bitmask of first collider. | |
| void | setCollisionMaskBits (int maskBits) |
| A mask that defines which categories of physics bodies can collide with this physics body. | |
| void | setGroup (int groupIndex) |
| Set the group of body. | |
| int | getGroup () const |
| Return group of first collider. | |
| Vec2 | getPosition () const |
| get the body position. | |
| float | getRotation () |
| get the body rotation in degrees. | |
| void | setPositionOffset (const Vec2 &position) |
| set body position offset, it's the position witch relative to node | |
| const Vec2 & | getPositionOffset () const |
| get body position offset. | |
| void | setRotationOffset (float rotation) |
| set body rotation offset in degrees, it's the rotation witch relative to node | |
| float | getRotationOffset () const |
| set the body rotation offset in degrees | |
| void | setDynamic () |
| Sets the body type to dynamic (affected by forces, gravity, collisions). | |
| bool | isDynamic () const |
| Checks if the body type is dynamic. | |
| void | setKinematic () |
| Sets the body type to kinematic (not affected by forces, moved by script/animation). | |
| bool | isKinematic () const |
| Checks if the body type is kinematic. | |
| bool | getBodyType () const |
| Get the body type. | |
| void | setBodyType (BodyType bodyType) |
| Set body type. | |
| float | getMass () const |
| Get the body mass. | |
| void | setMass (float mass) |
| Set the body mass Override the body's mass properties. | |
| float | getMoment () const |
| Get the body moment of rotation inertia. | |
| void | setMoment (float moment) |
| Set the body moment of rotation inertia. | |
| float | getLinearDamping () const |
| get linear damping. | |
| void | setLinearDamping (float damping) |
| Set linear damping. | |
| float | getAngularDamping () const |
| Get angular damping. | |
| void | setAngularDamping (float damping) |
| Set angular damping. | |
| bool | isAttached () const |
| Whether the body is attached to physics world. | |
| CollisionDetectionMode | getCollisionDetectionMode () const |
| Gets the current collision detection mode. | |
| void | setCollisionDetectionMode (CollisionDetectionMode mode) |
| Sets the collision detection mode. | |
| void | setEnabled (bool enable) override |
| Set the enable value. | |
| bool | isRotationEnabled () const |
| Whether the body can rotation. | |
| void | setRotationEnabled (bool enabled) |
| Set the body is allow rotation or not. | |
| bool | isGravityEnabled () const |
| Whether this physics body is affected by the physics world's gravitational force. | |
| void | setGravityEnabled (bool enabled) |
| Set the body is affected by the physics world's gravitational force or not. | |
| void | setGravityScale (float scale) |
| Sets the gravity scale factor. | |
| float | getGravityScale () const |
| Gets the current gravity scale factor. | |
| void | setTag (unsigned int tag) |
| Set this body's tag. | |
| unsigned int | getTag () const |
| Get this body's tag. | |
| Vec2 | world2Local (const Vec2 &point) |
| Convert the world point to local. | |
| Vec2 | local2World (const Vec2 &point) |
| Convert the local point to world. | |
| float | getAngleRadians () |
| Gets angle in randius. | |
| b2BodyId | internalHandle () const |
| Get the rigid body of box2d. | |
Static Public Member Functions | |
| static Rigidbody2D * | create () |
| Create a rigibody. | |
| static Rigidbody2D * | createCircle (float radius, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT, const Vec2 &offset=Vec2::zero) |
| Create a body contains a circle. | |
| static Rigidbody2D * | createBox (const Vec2 &size, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT, const Vec2 &offset=Vec2::zero) |
| Create a body contains a box collider. | |
| static Rigidbody2D * | createPolygon (std::span< const Vec2 > points, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT, const Vec2 &offset=Vec2::zero) |
| Create a body contains a polygon collider. | |
| static Rigidbody2D * | createEdgeSegment (const Vec2 &a, const Vec2 &b, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT) |
| Create a body contains a EdgeSegment collider. | |
| static Rigidbody2D * | createEdgeBox (const Vec2 &size, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT, const Vec2 &offset=Vec2::zero) |
| Create a body contains a EdgeBox collider. | |
| static Rigidbody2D * | createEdgePolygon (std::span< const Vec2 > points, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT) |
| Create a body contains a EdgePolygon collider. | |
| static Rigidbody2D * | createEdgeChain (std::span< const Vec2 > points, const PhysicsMaterial2D &material=PHYSICS_MATERIAL_2D_DEFAULT) |
| Create a body contains a EdgeChain collider. | |
A Rigidbody2D affected by physics2d.
It can attach one or more colliders. By default, Box2D automatically computes mass and moment of inertia from the collider shapes and the specified density (default material PHYSICS_MATERIAL_2D_DEFAULT, density = 0.1f), using the formula: mass = density * area.
You can also set a body static/dynamic via setDynamic().
Note: Box2D does not allow changing mass or inertia dynamically once created.
|
static |
Create a rigibody.
The mass and moment automaticall computed by box2d internal
|
static |
Create a body contains a circle.
| radius | A float number, it is the circle's radius. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
| offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a box collider.
| size | Size contains this box's width and height. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
| offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a polygon collider.
| points | Points is an array of Vec2 structs defining a convex hull with a clockwise winding. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
| offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a EdgeSegment collider.
| a | It's the edge's begin position. |
| b | It's the edge's end position. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
|
static |
Create a body contains a EdgeBox collider.
| size | The size contains this box's width and height. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
| offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a EdgePolygon collider.
| points | Points is an array of Vec2 structs defining a convex hull with a clockwise winding. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
|
static |
Create a body contains a EdgeChain collider.
| points | A Vec2 object pointer, it contains an array of points. |
| material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
|
virtual |
Add a collider to body.
| collider | The collider to be added. |
| addMassAndMoment | If this is true, the collider's mass and moment will be added to body. The default is true. |
| void removeCollider | ( | Collider2D * | collider, |
| bool | reduceMassAndMoment = true ) |
Remove a collider from body.
| collider | the collider to be removed. |
| reduceMassAndMoment | If this is true, the body mass and moment will be reduced by collider. The default is true. |
| void removeCollider | ( | int | tag, |
| bool | reduceMassAndMoment = true ) |
Remove a collider from body.
| tag | The tag of the collider to be removed. |
| reduceMassAndMoment | If this is true, the body mass and moment will be reduced by collider. The default is true. |
| void removeAllColliders | ( | bool | reduceMassAndMoment = true | ) |
Remove all colliders.
| reduceMassAndMoment | If this is true, the body mass and moment will be reduced by collider. The default is true. |
|
inline |
Get the body colliders.
|
inline |
Get the first collider of the body colliders.
| Collider2D * getCollider | ( | int | tag | ) | const |
get the collider of the body.
| tag | An integer number that identifies a Collider2D object. |
|
virtual |
Applies a continuous force to body.
| force | The force is applies to this body. |
| offset | A Vec2 object, it is the offset from the body's center of gravity in world coordinates. |
|
virtual |
Applies a immediate force to body.
| impulse | The impulse is applies to this body. |
| offset | A Vec2 object, it is the offset from the body's center of gravity in world coordinates. |
|
virtual |
Applies a torque force to body.
| torque | The torque is applies to this body. |
|
virtual |
Set the velocity of a body.
| velocity | The velocity is set to this body. |
|
virtual |
Set the angular velocity in degrees of a body.
| velocity | The angular velocity is set to this body. |
| void setEventEnabled | ( | ContactEventBits | events, |
| bool | enabled ) |
Enable or disable one or more event types for this collider.
This method allows toggling specific event bits. You can enable or disable a single event or multiple events at once by combining flags.
| events | The event bits to modify. |
| enabled | True to enable the specified events, false to disable them. |
| uint64_t getCategoryBits | ( | ) | const |
Return bitmask of first collider.
| void setCategoryBits | ( | uint64_t | categoryBits | ) |
A mask that defines which categories this physics body belongs to.
Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.
| categoryBits | An integer number, the default value is UINT64_MAX (all bits set). |
| int getCollisionMaskBits | ( | ) | const |
Return bitmask of first collider.
| void setCollisionMaskBits | ( | int | maskBits | ) |
A mask that defines which categories of physics bodies can collide with this physics body.
When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.
| bitmask | An integer number, the default value is UINT64_MAX (all bits set). |
| void setGroup | ( | int | groupIndex | ) |
Set the group of body.
Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index). It have high priority than bit masks.
| int getGroup | ( | ) | const |
Return group of first collider.
| void setMass | ( | float | mass | ) |
Set the body mass Override the body's mass properties.
Normally this is computed automatically using the shape geometry and density. This information is lost if a shape is added or removed or if the body type changes.
|
inline |
Set linear damping.
it is used to simulate fluid or air friction forces on the body.
| damping | The value is 0.0f to 1.0f. |
|
inline |
Set angular damping.
It is used to simulate fluid or air friction forces on the body.
| damping | The value is 0.0f to 1.0f. |
|
override |
Set the enable value.
If the body it isn't enabled, it will not has simulation by world.
| void setGravityScale | ( | float | scale | ) |
Sets the gravity scale factor.
| scale | Multiplier for global gravity (1.0 = normal gravity, 0 disables gravity). |
|
inline |
Gets the current gravity scale factor.
|
inline |
Set this body's tag.
| tag | An integer number that identifies a shape object. |
|
inline |
Get this body's tag.