Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity, raycasts, AABB queries and contact/impact events. 更多...
#include <World.h>
类 | |
| struct | ContactEvent |
| struct | ImpactEvent |
Public 成员函数 | |
| World (float gravityX, float gravityY, bool sleep, float meter) | |
| Creates a physics world. | |
| ~World () | |
| World (const World &)=delete | |
| World & | operator= (const World &)=delete |
| void | update (float dt) |
| Steps the simulation by dt seconds (5 velocity / 2 position iterations). | |
| void | updateFull (float dt, int velocityIterations, int positionIterations) |
| Steps with explicit iteration counts. | |
| void | setGravity (float gx, float gy) |
| Sets the world gravity vector in pixels/s^2. | |
| float | getGravityX () const |
| float | getGravityY () const |
| void | setMeter (float pixelsPerMeter) |
| Changes the pixels-per-meter conversion. | |
| float | getMeter () const |
| Body * | newBody (const std::string &bodyType, float x, float y) |
| bodyType: "static" | "kinematic" | "dynamic". x/y in pixels. | |
| void | destroyBody (Body *body) |
| Destroys a body (null is ignored). | |
| void | destroy () |
| Destroys the underlying Box2D world and resets event buffers. | |
| void | drawDebug (graphics::Graphics *gfx) |
| Optional: draw fixture AABBs via Graphics::drawSolidRect. | |
| int | rayCast (float x1, float y1, float x2, float y2) |
| Closest raycast in pixel space from (x1,y1) to (x2,y2). Returns hit body id, or -1. Read hit details via getRayHit*. | |
| bool | hasRayHit () const |
| int | getRayHitBodyId () const |
| float | getRayHitX () const |
| float | getRayHitY () const |
| float | getRayHitNormalX () const |
| float | getRayHitNormalY () const |
| float | getRayHitFraction () const |
| Fraction along the segment [0,1] of the closest hit. | |
| int | queryAABB (float x, float y, float w, float h) |
| Query fixtures overlapping an axis-aligned box in pixel space (x,y,w,h). Returns match count; read ids with getQueryBodyId(i). | |
| int | getQueryCount () const |
| int | getQueryBodyId (int index) const |
| int | getBeginContactCount () const |
| int | getBeginContactBodyAId (int index) const |
| int | getBeginContactBodyBId (int index) const |
| std::string | getBeginContactFixtureATag (int index) const |
| std::string | getBeginContactFixtureBTag (int index) const |
| int | getEndContactCount () const |
| int | getEndContactBodyAId (int index) const |
| int | getEndContactBodyBId (int index) const |
| std::string | getEndContactFixtureATag (int index) const |
| std::string | getEndContactFixtureBTag (int index) const |
| int | getImpactCount () const |
| int | getImpactBodyAId (int index) const |
| int | getImpactBodyBId (int index) const |
| std::string | getImpactFixtureATag (int index) const |
| std::string | getImpactFixtureBTag (int index) const |
| float | getImpactPointX (int index) const |
| float | getImpactPointY (int index) const |
| float | getImpactNormalX (int index) const |
| float | getImpactNormalY (int index) const |
| float | getImpactRelativeNormalSpeed (int index) const |
| float | getImpactNormalImpulse (int index) const |
| float | getImpactTangentImpulse (int index) const |
| void | clearContactEvents () |
| Clears collected begin/end contact and impact event buffers. | |
| float | toMeters (float pixels) const |
| Converts a pixel-space length to meters. | |
| float | toPixels (float meters) const |
| Converts a meter-space length to pixels. | |
| b2World * | raw () |
| The underlying Box2D world (advanced use). | |
| const b2World * | raw () const |
| void | onBeginContact (b2Contact *contact) |
| void | onEndContact (b2Contact *contact) |
| void | onPreSolve (b2Contact *contact, const b2Manifold *oldManifold) |
| void | onPostSolve (b2Contact *contact, const b2ContactImpulse *impulse) |
| void | forgetBody (Body *body) |
| void | forgetFixture (Fixture *fixture) |
| int | nextBodyId () |
友元 | |
| class | Body |
| class | Fixture |
详细描述
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity, raycasts, AABB queries and contact/impact events.
构造及析构函数说明
◆ World() [1/2]
| eve::physics::World::World | ( | float | gravityX, |
| float | gravityY, | ||
| bool | sleep, | ||
| float | meter | ||
| ) |
Creates a physics world.
- 参数
-
gravityX/gravityY Gravity vector in pixels/s^2. sleep Whether bodies may sleep when idle. meter Pixels per meter conversion factor.
引用了 toMeters().
◆ ~World()
◆ World() [2/2]
|
delete |
成员函数说明
◆ clearContactEvents()
| void eve::physics::World::clearContactEvents | ( | ) |
◆ destroy()
| void eve::physics::World::destroy | ( | ) |
◆ destroyBody()
| void eve::physics::World::destroyBody | ( | Body * | body | ) |
◆ drawDebug()
| void eve::physics::World::drawDebug | ( | graphics::Graphics * | gfx | ) |
Optional: draw fixture AABBs via Graphics::drawSolidRect.
引用了 eve::physics::DebugDraw::begin() , 以及 eve::physics::DebugDraw::end().
◆ forgetBody()
| void eve::physics::World::forgetBody | ( | Body * | body | ) |
被这些函数引用 eve::physics::Body::destroy() , 以及 eve::physics::Body::~Body().
◆ forgetFixture()
| void eve::physics::World::forgetFixture | ( | Fixture * | fixture | ) |
◆ getBeginContactBodyAId()
◆ getBeginContactBodyBId()
◆ getBeginContactCount()
◆ getBeginContactFixtureATag()
| std::string eve::physics::World::getBeginContactFixtureATag | ( | int | index | ) | const |
◆ getBeginContactFixtureBTag()
| std::string eve::physics::World::getBeginContactFixtureBTag | ( | int | index | ) | const |
◆ getEndContactBodyAId()
◆ getEndContactBodyBId()
◆ getEndContactCount()
◆ getEndContactFixtureATag()
| std::string eve::physics::World::getEndContactFixtureATag | ( | int | index | ) | const |
◆ getEndContactFixtureBTag()
| std::string eve::physics::World::getEndContactFixtureBTag | ( | int | index | ) | const |
◆ getGravityX()
| float eve::physics::World::getGravityX | ( | ) | const |
引用了 toPixels().
◆ getGravityY()
| float eve::physics::World::getGravityY | ( | ) | const |
引用了 toPixels().
◆ getImpactBodyAId()
◆ getImpactBodyBId()
◆ getImpactCount()
◆ getImpactFixtureATag()
◆ getImpactFixtureBTag()
◆ getImpactNormalImpulse()
◆ getImpactNormalX()
◆ getImpactNormalY()
◆ getImpactPointX()
◆ getImpactPointY()
◆ getImpactRelativeNormalSpeed()
◆ getImpactTangentImpulse()
◆ getMeter()
◆ getQueryBodyId()
◆ getQueryCount()
◆ getRayHitBodyId()
◆ getRayHitFraction()
|
inline |
◆ getRayHitNormalX()
◆ getRayHitNormalY()
◆ getRayHitX()
◆ getRayHitY()
◆ hasRayHit()
◆ newBody()
| Body * eve::physics::World::newBody | ( | const std::string & | bodyType, |
| float | x, | ||
| float | y | ||
| ) |
bodyType: "static" | "kinematic" | "dynamic". x/y in pixels.
引用了 Body, body, nextBodyId(), raw(), toMeters(), x , 以及 y.
◆ nextBodyId()
◆ onBeginContact()
| void eve::physics::World::onBeginContact | ( | b2Contact * | contact | ) |
引用了 a, b , 以及 eve::event::Variant::makeInt().
◆ onEndContact()
| void eve::physics::World::onEndContact | ( | b2Contact * | contact | ) |
引用了 a, b , 以及 eve::event::Variant::makeInt().
◆ onPostSolve()
| void eve::physics::World::onPostSolve | ( | b2Contact * | contact, |
| const b2ContactImpulse * | impulse | ||
| ) |
引用了 eve::physics::World::ImpactEvent::normalImpulse, eve::physics::World::ImpactEvent::normalX, eve::physics::World::ImpactEvent::normalY, eve::physics::World::ImpactEvent::pointX, eve::physics::World::ImpactEvent::pointY, eve::physics::World::ImpactEvent::relativeNormalSpeed, eve::physics::World::ImpactEvent::tangentImpulse , 以及 toPixels().
◆ onPreSolve()
| void eve::physics::World::onPreSolve | ( | b2Contact * | contact, |
| const b2Manifold * | oldManifold | ||
| ) |
引用了 a, b, data , 以及 toPixels().
◆ operator=()
◆ queryAABB()
| int eve::physics::World::queryAABB | ( | float | x, |
| float | y, | ||
| float | w, | ||
| float | h | ||
| ) |
◆ raw() [1/2]
|
inline |
The underlying Box2D world (advanced use).
被这些函数引用 eve::physics::Body::destroy(), forgetFixture(), newBody() , 以及 eve::physics::Body::~Body().
◆ raw() [2/2]
◆ rayCast()
| int eve::physics::World::rayCast | ( | float | x1, |
| float | y1, | ||
| float | x2, | ||
| float | y2 | ||
| ) |
Closest raycast in pixel space from (x1,y1) to (x2,y2). Returns hit body id, or -1. Read hit details via getRayHit*.
引用了 b, normal, toMeters() , 以及 toPixels().
◆ setGravity()
| void eve::physics::World::setGravity | ( | float | gx, |
| float | gy | ||
| ) |
◆ setMeter()
| void eve::physics::World::setMeter | ( | float | pixelsPerMeter | ) |
◆ toMeters()
| float eve::physics::World::toMeters | ( | float | pixels | ) | const |
Converts a pixel-space length to meters.
被这些函数引用 eve::physics::Body::applyForce(), eve::physics::Body::applyForceAt(), eve::physics::Body::applyLinearImpulse(), newBody(), eve::physics::Body::newCircleFixture(), eve::physics::Body::newRectangleFixtureAt(), queryAABB(), rayCast(), setGravity(), eve::physics::Body::setLinearVelocity(), eve::physics::Body::setPosition(), eve::physics::Fixture::testPoint() , 以及 World().
◆ toPixels()
| float eve::physics::World::toPixels | ( | float | meters | ) | const |
Converts a meter-space length to pixels.
被这些函数引用 getGravityX(), getGravityY(), eve::physics::Body::getLinearSpeed(), eve::physics::Body::getLinearVelocityX(), eve::physics::Body::getLinearVelocityY(), eve::physics::Body::getWorldCenterX(), eve::physics::Body::getWorldCenterY(), eve::physics::Body::getX(), eve::physics::Body::getY(), onPostSolve(), onPreSolve() , 以及 rayCast().
◆ update()
| void eve::physics::World::update | ( | float | dt | ) |
Steps the simulation by dt seconds (5 velocity / 2 position iterations).
引用了 updateFull().
◆ updateFull()
| void eve::physics::World::updateFull | ( | float | dt, |
| int | velocityIterations, | ||
| int | positionIterations | ||
| ) |
友元及相关函数文档
◆ Body
◆ Fixture
该类的文档由以下文件生成: