2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFixture/newCircleFixture. 更多...
#include <Body.h>
Public 成员函数 | |
| Body (World *world, b2Body *body, int id, PhysicsBodyHandle runtimeHandle) | |
| Internal: wraps a Box2D body (use World::newBody). | |
| ~Body () | |
| Body. | |
| Body (const Body &)=delete | |
| Body & | operator= (const Body &)=delete |
| int | getId () const |
| Stable id used by contact/impact events. | |
| void | setPosition (float x, float y) |
| Position in pixels. | |
| float | getX () const |
| Returns the x. | |
| float | getY () const |
| Returns the y. | |
| void | setAngle (float radians) |
| Rotation in radians. | |
| float | getAngle () const |
| Returns the angle. | |
| void | setLinearVelocity (float vx, float vy) |
| Linear velocity in pixels/s. | |
| float | getLinearVelocityX () const |
| Returns the linear velocity x. | |
| float | getLinearVelocityY () const |
| Returns the linear velocity y. | |
| float | getLinearSpeed () const |
| Magnitude of the linear velocity. | |
| float | getMass () const |
| Mass in kilograms (Box2D units). | |
| float | getWorldCenterX () const |
| World center of mass in pixels. | |
| float | getWorldCenterY () const |
| Returns the world center y. | |
| void | setAngularVelocity (float omega) |
| Angular velocity in radians/s. | |
| float | getAngularVelocity () const |
| Returns the angular velocity. | |
| void | applyForce (float fx, float fy) |
| Force (pixels/s² * kg) applied at the center of mass. | |
| void | applyForceAt (float fx, float fy, float x, float y) |
| Force applied at a world pixel position. | |
| void | applyLinearImpulse (float ix, float iy) |
| Instantaneous linear impulse. | |
| void | applyAngularImpulse (float impulse) |
| Instantaneous angular impulse. | |
| void | setType (const std::string &bodyType) |
| "static" | "kinematic" | "dynamic". | |
| std::string | getType () const |
| Returns the type. | |
| void | setFixedRotation (bool fixed) |
| Locks rotation so the body cannot spin. | |
| bool | isFixedRotation () const |
| True when fixed rotation. | |
| void | setActive (bool active) |
| Disables/enables the body and its fixtures. | |
| bool | isActive () const |
| True when active. | |
| void | setBullet (bool bullet) |
| CCD bullet mode (recommended for fast small bodies). | |
| bool | isBullet () const |
| True when bullet. | |
| void | setAwake (bool awake) |
| Wakes / sleeps the body manually. | |
| bool | isAwake () const |
| True when awake. | |
| Fixture * | newRectangleFixture (float width, float height, float density=1.f, float friction=0.2f, float restitution=0.f) |
| Creates a rectangle fixture in pixel-space units. | |
| Fixture * | newRectangleFixtureAt (float width, float height, float offsetX, float offsetY, float density=1.f, float friction=0.2f, float restitution=0.f) |
| Creates an offset rectangle fixture in pixel-space units. | |
| Fixture * | newCircleFixture (float radius, float density=1.f, float friction=0.2f, float restitution=0.f) |
| Creates a circular fixture in pixel-space units. | |
| Fixture * | newPolygonFixture (const std::vector< float > &vertices, float density=1.f, float friction=0.2f, float restitution=0.f) |
| Create a bounded convex polygon fixture from packed local pixel-space XY vertices. | |
| Fixture * | newChainFixture (const std::vector< float > &vertices, bool loop=false, float friction=0.2f, float restitution=0.f) |
| Create an open chain or closed loop from packed local pixel-space XY vertices. | |
| void | destroy () |
| Destroys the body inside its world. | |
| bool | isValid () const noexcept |
| True while both the wrapper and its owning Box2D world are live. | |
| PhysicsBodyHandle | runtimeHandle () const noexcept |
| Returns the process-local solver handle used by PhysicsLink. | |
| World * | getWorld () |
| Returns the owning world, or null after invalidation. | |
| const World * | getWorld () const |
| Returns the owning world as a read-only borrowed pointer. | |
| b2Body * | raw () |
| Exposes the underlying Box2D body for tightly-scoped backend integration. | |
| const b2Body * | raw () const |
| Exposes the underlying Box2D body for read-only backend integration. | |
| void | invalidate () |
| Internal: marks the wrapper invalid after world destruction. | |
友元 | |
| struct | WorldSnapshotAccess |
| class | World |
| class | Fixture |
详细描述
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFixture/newCircleFixture.
构造及析构函数说明
◆ Body() [1/2]
| eve::physics::Body::Body | ( | World * | world, |
| b2Body * | body, | ||
| int | id, | ||
| PhysicsBodyHandle | runtimeHandle | ||
| ) |
Internal: wraps a Box2D body (use World::newBody).
◆ ~Body()
| eve::physics::Body::~Body | ( | ) |
◆ Body() [2/2]
|
delete |
成员函数说明
◆ applyAngularImpulse()
| void eve::physics::Body::applyAngularImpulse | ( | float | impulse | ) |
◆ applyForce()
| void eve::physics::Body::applyForce | ( | float | fx, |
| float | fy | ||
| ) |
Force (pixels/s² * kg) applied at the center of mass.
◆ applyForceAt()
| void eve::physics::Body::applyForceAt | ( | float | fx, |
| float | fy, | ||
| float | x, | ||
| float | y | ||
| ) |
Force applied at a world pixel position.
引用了 eve::physics::World::toMeters(), x , 以及 y.
◆ applyLinearImpulse()
| void eve::physics::Body::applyLinearImpulse | ( | float | ix, |
| float | iy | ||
| ) |
◆ destroy()
| void eve::physics::Body::destroy | ( | ) |
Destroys the body inside its world.
引用了 f, eve::physics::World::forgetBody(), eve::physics::World::forgetFixture(), eve::RuntimeHandle< PhysicsBodyHandleTag >::invalid(), invalidate() , 以及 eve::physics::World::raw().
被这些函数引用 eve::physics::World::destroyBody().
◆ getAngle()
◆ getAngularVelocity()
| float eve::physics::Body::getAngularVelocity | ( | ) | const |
◆ getId()
|
inline |
Stable id used by contact/impact events.
被这些函数引用 eve::physics::Joint2D::getBodyAId(), eve::physics::Joint2D::getBodyBId() , 以及 eve::physics::Fixture::getBodyId().
◆ getLinearSpeed()
| float eve::physics::Body::getLinearSpeed | ( | ) | const |
◆ getLinearVelocityX()
| float eve::physics::Body::getLinearVelocityX | ( | ) | const |
◆ getLinearVelocityY()
| float eve::physics::Body::getLinearVelocityY | ( | ) | const |
◆ getMass()
| float eve::physics::Body::getMass | ( | ) | const |
◆ getType()
◆ getWorld() [1/2]
|
inline |
Returns the owning world, or null after invalidation.
- 返回
- Borrowed nullable World pointer; ownership remains with the world registry. @ownership Body does not own the world and callers must not delete it. @lifetime Valid until world destruction; use PhysicsWorldHandle for cross-frame identity. @thread Call on the owning physics thread. @reentrancy The accessor invokes no callbacks and is not valid across world mutation.
◆ getWorld() [2/2]
|
inline |
Returns the owning world as a read-only borrowed pointer.
- 返回
- Borrowed nullable World pointer. @ownership Body does not own the world; callers must not delete it. @lifetime Valid until world destruction; use PhysicsWorldHandle for cross-frame identity. @thread Call on the owning physics thread. @reentrancy The accessor invokes no callbacks and is not valid across world mutation.
◆ getWorldCenterX()
| float eve::physics::Body::getWorldCenterX | ( | ) | const |
◆ getWorldCenterY()
| float eve::physics::Body::getWorldCenterY | ( | ) | const |
◆ getX()
| float eve::physics::Body::getX | ( | ) | const |
◆ getY()
| float eve::physics::Body::getY | ( | ) | const |
◆ invalidate()
| void eve::physics::Body::invalidate | ( | ) |
Internal: marks the wrapper invalid after world destruction.
引用了 eve::RuntimeHandle< PhysicsBodyHandleTag >::invalid().
被这些函数引用 destroy().
◆ isActive()
◆ isAwake()
◆ isBullet()
◆ isFixedRotation()
| bool eve::physics::Body::isFixedRotation | ( | ) | const |
◆ isValid()
|
inlinenoexcept |
◆ newChainFixture()
| Fixture * eve::physics::Body::newChainFixture | ( | const std::vector< float > & | vertices, |
| bool | loop = false, |
||
| float | friction = 0.2f, |
||
| float | restitution = 0.f |
||
| ) |
Create an open chain or closed loop from packed local pixel-space XY vertices.
- 参数
-
vertices At least two finite vertices for a chain or three for a loop. loop Whether to connect the final vertex back to the first. friction Surface friction. restitution Surface restitution.
- 返回
- Borrowed fixture owned by the world.
- 异常
-
eve::Exception when the body is dead or vertices are malformed/degenerate.
引用了 count, Fixture, index, loop, point, points, raw(), restitution, shape, eve::physics::World::toMeters() , 以及 vertices.
被这些函数引用 eve::pixelworld_physics::PixelTerrainCollisionCache::sync().
◆ newCircleFixture()
| Fixture * eve::physics::Body::newCircleFixture | ( | float | radius, |
| float | density = 1.f, |
||
| float | friction = 0.2f, |
||
| float | restitution = 0.f |
||
| ) |
Creates a circular fixture in pixel-space units.
- 返回
- Borrowed nullable fixture owned by this body/world. @ownership The Box2D world owns the fixture; callers must destroy it through this API. @lifetime Valid until fixture/body/world destruction; do not retain across structural mutation. @thread Call on the owning physics thread. @reentrancy Creation does not invoke user callbacks; do not re-enter world mutation while using the result.
引用了 Fixture, radius, raw(), restitution, shape , 以及 eve::physics::World::toMeters().
◆ newPolygonFixture()
| Fixture * eve::physics::Body::newPolygonFixture | ( | const std::vector< float > & | vertices, |
| float | density = 1.f, |
||
| float | friction = 0.2f, |
||
| float | restitution = 0.f |
||
| ) |
Create a bounded convex polygon fixture from packed local pixel-space XY vertices.
- 参数
-
vertices Three to eight finite convex vertices as x0,y0,x1,y1,... . density Mass density. friction Surface friction. restitution Surface restitution.
- 返回
- Borrowed fixture owned by the world.
- 异常
-
eve::Exception when the body is dead or vertices are malformed/degenerate.
- 返回
- Borrowed pointer to a fixture owned by this body. @lifetime Valid until the fixture or owning body is destroyed.
引用了 Fixture, index, points, raw(), restitution, shape, eve::physics::World::toMeters() , 以及 vertices.
◆ newRectangleFixture()
| Fixture * eve::physics::Body::newRectangleFixture | ( | float | width, |
| float | height, | ||
| float | density = 1.f, |
||
| float | friction = 0.2f, |
||
| float | restitution = 0.f |
||
| ) |
Creates a rectangle fixture in pixel-space units.
- 返回
- Borrowed nullable fixture owned by this body/world. @ownership The Box2D world owns the fixture; callers must destroy it through this API. @lifetime Valid until fixture/body/world destruction; do not retain across structural mutation. @thread Call on the owning physics thread. @reentrancy Creation does not invoke user callbacks; do not re-enter world mutation while using the result.
引用了 height, newRectangleFixtureAt(), restitution , 以及 width.
◆ newRectangleFixtureAt()
| Fixture * eve::physics::Body::newRectangleFixtureAt | ( | float | width, |
| float | height, | ||
| float | offsetX, | ||
| float | offsetY, | ||
| float | density = 1.f, |
||
| float | friction = 0.2f, |
||
| float | restitution = 0.f |
||
| ) |
Creates an offset rectangle fixture in pixel-space units.
- 返回
- Borrowed nullable fixture owned by this body/world. @ownership The Box2D world owns the fixture; callers must destroy it through this API. @lifetime Valid until fixture/body/world destruction; do not retain across structural mutation. @thread Call on the owning physics thread. @reentrancy Creation does not invoke user callbacks; do not re-enter world mutation while using the result.
引用了 Fixture, height, offsetX, offsetY, raw(), restitution, shape, eve::physics::World::toMeters() , 以及 width.
被这些函数引用 eve::pixelworld_physics::PixelFragmentBody::create() , 以及 newRectangleFixture().
◆ operator=()
◆ raw() [1/2]
|
inline |
Exposes the underlying Box2D body for tightly-scoped backend integration.
- 返回
- Borrowed nullable backend pointer; never transfer or store it across simulation steps. @ownership Box2D World owns the body; Body is only its wrapper. @lifetime Valid until Body::destroy(), world destruction, or invalidate(). @thread Call only on the owning physics thread. @reentrancy Does not invoke callbacks; callers must not mutate the world re-entrantly.
被这些函数引用 eve::physics::Fixture::destroy(), newChainFixture(), newCircleFixture(), eve::physics::World::newDistanceJoint(), eve::physics::World::newGearJoint(), eve::physics::World::newMotorJoint(), newPolygonFixture(), eve::physics::World::newPrismaticJoint(), newRectangleFixtureAt(), eve::physics::World::newRevoluteJoint(), eve::physics::World::newWeldJoint(), eve::physics::World::newWheelJoint(), eve::physics::Fixture::setDensity() , 以及 eve::physics::Fixture::~Fixture().
◆ raw() [2/2]
|
inline |
Exposes the underlying Box2D body for read-only backend integration.
- 返回
- Borrowed nullable backend pointer. @ownership Box2D World owns the body; callers must not delete it. @lifetime Valid until Body::destroy(), world destruction, or invalidate(). @thread Call only on the owning physics thread. @reentrancy Does not invoke callbacks and is invalid across world mutation.
◆ runtimeHandle()
|
inlinenoexcept |
Returns the process-local solver handle used by PhysicsLink.
- 返回
- Generation-qualified handle; it becomes stale on destruction.
◆ setActive()
| void eve::physics::Body::setActive | ( | bool | active | ) |
◆ setAngle()
◆ setAngularVelocity()
| void eve::physics::Body::setAngularVelocity | ( | float | omega | ) |
◆ setAwake()
| void eve::physics::Body::setAwake | ( | bool | awake | ) |
◆ setBullet()
| void eve::physics::Body::setBullet | ( | bool | bullet | ) |
◆ setFixedRotation()
| void eve::physics::Body::setFixedRotation | ( | bool | fixed | ) |
◆ setLinearVelocity()
| void eve::physics::Body::setLinearVelocity | ( | float | vx, |
| float | vy | ||
| ) |
Linear velocity in pixels/s.
引用了 eve::physics::World::toMeters(), vx , 以及 vy.
◆ setPosition()
| void eve::physics::Body::setPosition | ( | float | x, |
| float | y | ||
| ) |
◆ setType()
| void eve::physics::Body::setType | ( | const std::string & | bodyType | ) |
友元及相关函数文档
◆ Fixture
|
friend |
◆ World
◆ WorldSnapshotAccess
|
friend |
该类的文档由以下文件生成: