载入中...
搜索中...
未找到
eve::physics::Body类 参考

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.h 第 21 行定义.

构造及析构函数说明

◆ Body() [1/2]

eve::physics::Body::Body ( World *  world,
b2Body *  body,
int  id,
PhysicsBodyHandle  runtimeHandle 
)

Internal: wraps a Box2D body (use World::newBody).

在文件 Body.cpp 第 35 行定义.

◆ ~Body()

◆ Body() [2/2]

eve::physics::Body::Body ( const Body &  )
delete

成员函数说明

◆ applyAngularImpulse()

void eve::physics::Body::applyAngularImpulse ( float  impulse)

Instantaneous angular impulse.

在文件 Body.cpp 第 185 行定义.

◆ applyForce()

void eve::physics::Body::applyForce ( float  fx,
float  fy 
)

Force (pixels/s² * kg) applied at the center of mass.

在文件 Body.cpp 第 167 行定义.

引用了 eve::physics::World::toMeters().

◆ applyForceAt()

void eve::physics::Body::applyForceAt ( float  fx,
float  fy,
float  x,
float  y 
)

Force applied at a world pixel position.

在文件 Body.cpp 第 173 行定义.

引用了 eve::physics::World::toMeters(), x , 以及 y.

◆ applyLinearImpulse()

void eve::physics::Body::applyLinearImpulse ( float  ix,
float  iy 
)

Instantaneous linear impulse.

在文件 Body.cpp 第 179 行定义.

引用了 eve::physics::World::toMeters().

◆ destroy()

void eve::physics::Body::destroy ( )

◆ getAngle()

float eve::physics::Body::getAngle ( ) const

Returns the angle.

在文件 Body.cpp 第 120 行定义.

◆ getAngularVelocity()

float eve::physics::Body::getAngularVelocity ( ) const

Returns the angular velocity.

在文件 Body.cpp 第 162 行定义.

◆ getId()

int eve::physics::Body::getId ( ) const
inline

Stable id used by contact/impact events.

在文件 Body.h 第 32 行定义.

被这些函数引用 eve::physics::Joint2D::getBodyAId(), eve::physics::Joint2D::getBodyBId() , 以及 eve::physics::Fixture::getBodyId().

◆ getLinearSpeed()

float eve::physics::Body::getLinearSpeed ( ) const

Magnitude of the linear velocity.

在文件 Body.cpp 第 140 行定义.

引用了 eve::physics::World::toPixels().

◆ getLinearVelocityX()

float eve::physics::Body::getLinearVelocityX ( ) const

Returns the linear velocity x.

在文件 Body.cpp 第 130 行定义.

引用了 eve::physics::World::toPixels().

◆ getLinearVelocityY()

float eve::physics::Body::getLinearVelocityY ( ) const

Returns the linear velocity y.

在文件 Body.cpp 第 135 行定义.

引用了 eve::physics::World::toPixels().

◆ getMass()

float eve::physics::Body::getMass ( ) const

Mass in kilograms (Box2D units).

在文件 Body.cpp 第 145 行定义.

◆ getType()

std::string eve::physics::Body::getType ( ) const

Returns the type.

在文件 Body.cpp 第 195 行定义.

◆ getWorld() [1/2]

World * eve::physics::Body::getWorld ( )
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.

在文件 Body.h 第 176 行定义.

◆ getWorld() [2/2]

const World * eve::physics::Body::getWorld ( ) const
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.

在文件 Body.h 第 185 行定义.

◆ getWorldCenterX()

float eve::physics::Body::getWorldCenterX ( ) const

World center of mass in pixels.

在文件 Body.cpp 第 147 行定义.

引用了 eve::physics::World::toPixels().

◆ getWorldCenterY()

float eve::physics::Body::getWorldCenterY ( ) const

Returns the world center y.

在文件 Body.cpp 第 152 行定义.

引用了 eve::physics::World::toPixels().

◆ getX()

float eve::physics::Body::getX ( ) const

Returns the x.

在文件 Body.cpp 第 105 行定义.

引用了 eve::physics::World::toPixels().

◆ getY()

float eve::physics::Body::getY ( ) const

Returns the y.

在文件 Body.cpp 第 110 行定义.

引用了 eve::physics::World::toPixels().

◆ invalidate()

void eve::physics::Body::invalidate ( )

Internal: marks the wrapper invalid after world destruction.

在文件 Body.cpp 第 65 行定义.

引用了 eve::RuntimeHandle< PhysicsBodyHandleTag >::invalid().

被这些函数引用 destroy().

◆ isActive()

bool eve::physics::Body::isActive ( ) const

True when active.

在文件 Body.cpp 第 212 行定义.

◆ isAwake()

bool eve::physics::Body::isAwake ( ) const

True when awake.

在文件 Body.cpp 第 226 行定义.

◆ isBullet()

bool eve::physics::Body::isBullet ( ) const

True when bullet.

在文件 Body.cpp 第 219 行定义.

◆ isFixedRotation()

bool eve::physics::Body::isFixedRotation ( ) const

True when fixed rotation.

在文件 Body.cpp 第 205 行定义.

◆ isValid()

bool eve::physics::Body::isValid ( ) const
inlinenoexcept

True while both the wrapper and its owning Box2D world are live.

在文件 Body.h 第 160 行定义.

◆ 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.

参数
verticesAt least two finite vertices for a chain or three for a loop.
loopWhether to connect the final vertex back to the first.
frictionSurface friction.
restitutionSurface restitution.
返回
Borrowed fixture owned by the world.
异常
eve::Exceptionwhen the body is dead or vertices are malformed/degenerate.

在文件 Body.cpp 第 305 行定义.

引用了 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.

在文件 Body.cpp 第 256 行定义.

引用了 Fixture, radius, raw(), restitution, shape , 以及 eve::physics::World::toMeters().

被这些函数引用 eve::vehicle::VehiclePhysics::attach2D().

◆ 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.

参数
verticesThree to eight finite convex vertices as x0,y0,x1,y1,... .
densityMass density.
frictionSurface friction.
restitutionSurface restitution.
返回
Borrowed fixture owned by the world.
异常
eve::Exceptionwhen 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.

在文件 Body.cpp 第 276 行定义.

引用了 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.

在文件 Body.cpp 第 228 行定义.

引用了 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.

在文件 Body.cpp 第 233 行定义.

引用了 Fixture, height, offsetX, offsetY, raw(), restitution, shape, eve::physics::World::toMeters() , 以及 width.

被这些函数引用 eve::pixelworld_physics::PixelFragmentBody::create() , 以及 newRectangleFixture().

◆ operator=()

Body & eve::physics::Body::operator= ( const Body &  )
delete

◆ raw() [1/2]

b2Body * eve::physics::Body::raw ( )
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.

在文件 Body.h 第 194 行定义.

被这些函数引用 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]

const b2Body * eve::physics::Body::raw ( ) const
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.

在文件 Body.h 第 203 行定义.

◆ runtimeHandle()

PhysicsBodyHandle eve::physics::Body::runtimeHandle ( ) const
inlinenoexcept

Returns the process-local solver handle used by PhysicsLink.

返回
Generation-qualified handle; it becomes stale on destruction.

在文件 Body.h 第 166 行定义.

◆ setActive()

void eve::physics::Body::setActive ( bool  active)

Disables/enables the body and its fixtures.

在文件 Body.cpp 第 207 行定义.

引用了 active.

◆ setAngle()

void eve::physics::Body::setAngle ( float  radians)

Rotation in radians.

在文件 Body.cpp 第 115 行定义.

◆ setAngularVelocity()

void eve::physics::Body::setAngularVelocity ( float  omega)

Angular velocity in radians/s.

在文件 Body.cpp 第 157 行定义.

◆ setAwake()

void eve::physics::Body::setAwake ( bool  awake)

Wakes / sleeps the body manually.

在文件 Body.cpp 第 221 行定义.

引用了 awake.

◆ setBullet()

void eve::physics::Body::setBullet ( bool  bullet)

CCD bullet mode (recommended for fast small bodies).

在文件 Body.cpp 第 214 行定义.

引用了 bullet.

◆ setFixedRotation()

void eve::physics::Body::setFixedRotation ( bool  fixed)

Locks rotation so the body cannot spin.

在文件 Body.cpp 第 200 行定义.

◆ setLinearVelocity()

void eve::physics::Body::setLinearVelocity ( float  vx,
float  vy 
)

Linear velocity in pixels/s.

在文件 Body.cpp 第 125 行定义.

引用了 eve::physics::World::toMeters(), vx , 以及 vy.

◆ setPosition()

void eve::physics::Body::setPosition ( float  x,
float  y 
)

Position in pixels.

在文件 Body.cpp 第 100 行定义.

引用了 eve::physics::World::toMeters(), x , 以及 y.

◆ setType()

void eve::physics::Body::setType ( const std::string &  bodyType)

"static" | "kinematic" | "dynamic".

在文件 Body.cpp 第 190 行定义.

友元及相关函数文档

◆ Fixture

friend class Fixture
friend

在文件 Body.h 第 211 行定义.

被这些函数引用 newChainFixture(), newCircleFixture(), newPolygonFixture() , 以及 newRectangleFixtureAt().

◆ World

friend class World
friend

在文件 Body.h 第 210 行定义.

◆ WorldSnapshotAccess

friend struct WorldSnapshotAccess
friend

在文件 Body.h 第 209 行定义.


该类的文档由以下文件生成: