载入中...
搜索中...
未找到
Body.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6
7#include <string>
8#include <vector>
9
10class b2Body;
11
12namespace eve::physics {
13
14class World;
15class Fixture;
16
22public:
24 Body(World *world, b2Body *body, int id, PhysicsBodyHandle runtimeHandle);
26 ~Body();
27
28 Body(const Body &) = delete;
29 Body &operator=(const Body &) = delete;
30
32 int getId() const { return id_; }
33
35 void setPosition(float x, float y);
37 float getX() const;
39 float getY() const;
40
42 void setAngle(float radians);
44 float getAngle() const;
45
47 void setLinearVelocity(float vx, float vy);
49 float getLinearVelocityX() const;
51 float getLinearVelocityY() const;
53 float getLinearSpeed() const;
55 float getMass() const;
57 float getWorldCenterX() const;
59 float getWorldCenterY() const;
60
62 void setAngularVelocity(float omega);
64 float getAngularVelocity() const;
65
67 void applyForce(float fx, float fy);
69 void applyForceAt(float fx, float fy, float x, float y);
71 void applyLinearImpulse(float ix, float iy);
73 void applyAngularImpulse(float impulse);
74
76 void setType(const std::string &bodyType);
78 std::string getType() const;
79
81 void setFixedRotation(bool fixed);
83 bool isFixedRotation() const;
84
86 void setActive(bool active);
88 bool isActive() const;
89
91 void setBullet(bool bullet);
93 bool isBullet() const;
94
96 void setAwake(bool awake);
98 bool isAwake() const;
99
108 Fixture *newRectangleFixture(float width, float height, float density = 1.f,
109 float friction = 0.2f, float restitution = 0.f);
118 Fixture *newRectangleFixtureAt(float width, float height, float offsetX, float offsetY,
119 float density = 1.f, float friction = 0.2f,
120 float restitution = 0.f);
129 Fixture *newCircleFixture(float radius, float density = 1.f, float friction = 0.2f,
130 float restitution = 0.f);
142 Fixture *newPolygonFixture(const std::vector<float> &vertices, float density = 1.f,
143 float friction = 0.2f, float restitution = 0.f);
153 Fixture *newChainFixture(const std::vector<float> &vertices, bool loop = false,
154 float friction = 0.2f, float restitution = 0.f);
155
157 void destroy();
158
160 [[nodiscard]] bool isValid() const noexcept { return world_ != nullptr && body_ != nullptr; }
161
166 [[nodiscard]] PhysicsBodyHandle runtimeHandle() const noexcept { return runtimeHandle_; }
167
176 World *getWorld() { return world_; }
185 const World *getWorld() const { return world_; }
194 b2Body *raw() { return body_; }
203 const b2Body *raw() const { return body_; }
204
206 void invalidate();
207
208private:
209 friend struct WorldSnapshotAccess;
210 friend class World;
211 friend class Fixture;
212
213 World *world_ = nullptr;
214 b2Body *body_ = nullptr;
215 int id_ = 0;
216 PhysicsBodyHandle runtimeHandle_ = PhysicsBodyHandle::invalid();
217};
218
219} // namespace eve::physics
bool & active
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
std::uint32_t height
std::uint32_t width
void(* destroy)(void *)
World3D * world
Process-local, generation-qualified handles owned by the physics domain.
std::vector< Point > vertices
float radius
double restitution
float offsetX
float offsetY
std::string body
float vy
bool awake
float vx
bool bullet
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFi...
Definition Body.h:21
bool isValid() const noexcept
True while both the wrapper and its owning Box2D world are live.
Definition Body.h:160
const World * getWorld() const
Returns the owning world as a read-only borrowed pointer.
Definition Body.h:185
Body(const Body &)=delete
Body & operator=(const Body &)=delete
const b2Body * raw() const
Exposes the underlying Box2D body for read-only backend integration.
Definition Body.h:203
b2Body * raw()
Exposes the underlying Box2D body for tightly-scoped backend integration.
Definition Body.h:194
PhysicsBodyHandle runtimeHandle() const noexcept
Returns the process-local solver handle used by PhysicsLink.
Definition Body.h:166
int getId() const
Stable id used by contact/impact events.
Definition Body.h:32
World * getWorld()
Returns the owning world, or null after invalidation.
Definition Body.h:176
2D fixture: a shape attached to a Body with material + filter settings. Also carries a string tag use...
Definition Fixture.h:18
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity,...
Definition World.h:41
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36