载入中...
搜索中...
未找到
Body3D.cpp
浏览该文件的文档.
1#include "physics/Body3D.h"
2#include "common/Assert.h"
3#include "physics/Shape3D.h"
4#include "physics/World3D.h"
5#include "physics/Joint3D.h"
6
7#include "common/Exception.h"
8
9
10#include <cmath>
11#include <vector>
12
13namespace eve::physics {
14namespace {
15
16template <class T>
17T legacyBodyValue(eve::Result<T> result) {
18 if (!result.ok()) throw eve::Exception("%s", result.error()->message().c_str());
19 return std::move(result).value();
20}
21void legacyBodyValue(eve::Result<void> result) {
22 if (!result.ok()) throw eve::Exception("%s", result.error()->message().c_str());
23}
24} // namespace
25
26Body3D::Body3D(World3D* world, std::unique_ptr<IBodyBackend3D> backend, int id, PhysicsBodyHandle runtimeHandle)
27 : world_(world), backend_(std::move(backend)), id_(id), runtimeHandle_(runtimeHandle) {
28 EV_PARAM_CHECK(backend_ != nullptr, "Body3D requires a backend");
29 backend_->bindOwner(*this);
30}
31
33 if (isValid() && world_ && world_->isValid()) {
34 std::vector<Joint3D *> joints(world_->joints_.begin(), world_->joints_.end());
35 for (Joint3D *joint : joints) {
36 if (joint && (joint->bodyA_ == this || joint->bodyB_ == this)) {
37 world_->forgetJoint(joint);
38 joint->invalidate();
39 }
40 }
41 // Invalidate shapes that still reference this body.
42 std::vector<Shape3D *> shapes(world_->shapes_.begin(), world_->shapes_.end());
43 for (Shape3D *s : shapes) {
44 if (s && s->getBody() == this) {
45 world_->forgetShape(s);
46 s->invalidate();
47 }
48 }
49 world_->forgetBody(this);
50 }
51 if (backend_) backend_->destroy();
52 if (backend_) backend_->invalidate();
53 world_ = nullptr;
54 runtimeHandle_ = PhysicsBodyHandle::invalid();
55}
56
57bool Body3D::isValid() const { return backend_ && backend_->isValid(); }
58
60 if (backend_) backend_->invalidate();
61 world_ = nullptr;
62 runtimeHandle_ = PhysicsBodyHandle::invalid();
63}
64
66 if (!isValid() || !world_ || !world_->isValid()) {
67 if (backend_) backend_->destroy();
68 invalidate();
69 return;
70 }
71 std::vector<Joint3D *> joints(world_->joints_.begin(), world_->joints_.end());
72 for (Joint3D *joint : joints) {
73 if (joint && (joint->bodyA_ == this || joint->bodyB_ == this)) {
74 world_->forgetJoint(joint);
75 joint->invalidate();
76 }
77 }
78 std::vector<Shape3D *> shapes(world_->shapes_.begin(), world_->shapes_.end());
79 for (Shape3D *s : shapes) {
80 if (s && s->getBody() == this) {
81 world_->forgetShape(s);
82 // Destroy the underlying shape before invalidating the wrapper.
83 s->destroy();
84 }
85 }
86 backend_->destroy();
87 world_->forgetBody(this);
88 if (backend_) backend_->invalidate();
89 world_ = nullptr;
90 runtimeHandle_ = PhysicsBodyHandle::invalid();
91}
92
93void Body3D::setPosition(float x, float y, float z) {
94 if (!isValid()) return;
95 legacyBodyValue(backend_->setPosition(x, y, z));
96}
97float Body3D::getX() const {
98 if (!isValid()) return 0.f;
99 return legacyBodyValue(backend_->getX());
100}
101float Body3D::getY() const {
102 if (!isValid()) return 0.f;
103 return legacyBodyValue(backend_->getY());
104}
105float Body3D::getZ() const {
106 if (!isValid()) return 0.f;
107 return legacyBodyValue(backend_->getZ());
108}
109void Body3D::setRotation(float qx, float qy, float qz, float qw) {
110 if (!isValid()) return;
111 legacyBodyValue(backend_->setRotation(qx, qy, qz, qw));
112}
113float Body3D::getRotX() const {
114 if (!isValid()) return 0.f;
115 return legacyBodyValue(backend_->getRotX());
116}
117float Body3D::getRotY() const {
118 if (!isValid()) return 0.f;
119 return legacyBodyValue(backend_->getRotY());
120}
121float Body3D::getRotZ() const {
122 if (!isValid()) return 0.f;
123 return legacyBodyValue(backend_->getRotZ());
124}
125float Body3D::getRotW() const {
126 if (!isValid()) return 1.f;
127 return legacyBodyValue(backend_->getRotW());
128}
129void Body3D::setLinearVelocity(float vx, float vy, float vz) {
130 if (!isValid()) return;
131 legacyBodyValue(backend_->setLinearVelocity(vx, vy, vz));
132}
134 if (!isValid()) return 0.f;
135 return legacyBodyValue(backend_->getLinearVelocityX());
136}
138 if (!isValid()) return 0.f;
139 return legacyBodyValue(backend_->getLinearVelocityY());
140}
142 if (!isValid()) return 0.f;
143 return legacyBodyValue(backend_->getLinearVelocityZ());
144}
145float Body3D::getMass() const {
146 if (!isValid()) return 0.f;
147 return legacyBodyValue(backend_->getMass());
148}
149void Body3D::setAngularVelocity(float wx, float wy, float wz) {
150 if (!isValid()) return;
151 legacyBodyValue(backend_->setAngularVelocity(wx, wy, wz));
152}
154 if (!isValid()) return 0.f;
155 return legacyBodyValue(backend_->getAngularVelocityX());
156}
158 if (!isValid()) return 0.f;
159 return legacyBodyValue(backend_->getAngularVelocityY());
160}
162 if (!isValid()) return 0.f;
163 return legacyBodyValue(backend_->getAngularVelocityZ());
164}
165std::vector<float> Body3D::localToWorldPoint(float x, float y, float z) const {
166 if (!isValid()) return {0.f, 0.f, 0.f};
167 return legacyBodyValue(backend_->localToWorldPoint(x, y, z));
168}
170 return backend_->localToWorldPointOwned(x, y, z);
171}
172std::vector<float> Body3D::worldToLocalPoint(float x, float y, float z) const {
173 if (!isValid()) return {0.f, 0.f, 0.f};
174 return legacyBodyValue(backend_->worldToLocalPoint(x, y, z));
175}
177 return backend_->worldToLocalPointOwned(x, y, z);
178}
179std::vector<float> Body3D::localToWorldVector(float x, float y, float z) const {
180 if (!isValid()) return {0.f, 0.f, 0.f};
181 return legacyBodyValue(backend_->localToWorldVector(x, y, z));
182}
184 return backend_->localToWorldVectorOwned(x, y, z);
185}
186std::vector<float> Body3D::worldToLocalVector(float x, float y, float z) const {
187 if (!isValid()) return {0.f, 0.f, 0.f};
188 return legacyBodyValue(backend_->worldToLocalVector(x, y, z));
189}
190std::vector<float> Body3D::getLocalPointVelocity(float x, float y, float z) const {
191 if (!isValid()) return {0.f, 0.f, 0.f};
192 return legacyBodyValue(backend_->getLocalPointVelocity(x, y, z));
193}
195 return backend_->getLocalPointVelocityOwned(x, y, z);
196}
197std::vector<float> Body3D::getWorldPointVelocity(float x, float y, float z) const {
198 if (!isValid()) return {0.f, 0.f, 0.f};
199 return legacyBodyValue(backend_->getWorldPointVelocity(x, y, z));
200}
201void Body3D::applyForce(float fx, float fy, float fz) {
202 if (!isValid()) return;
203 legacyBodyValue(backend_->applyForce(fx, fy, fz));
204}
205void Body3D::applyForceAt(float fx, float fy, float fz, float x, float y, float z) {
206 if (!isValid()) return;
207 legacyBodyValue(backend_->applyForceAt(fx, fy, fz, x, y, z));
208}
209void Body3D::applyTorque(float tx, float ty, float tz) {
210 if (!isValid()) return;
211 legacyBodyValue(backend_->applyTorque(tx, ty, tz));
212}
213void Body3D::applyLinearImpulse(float ix, float iy, float iz) {
214 if (!isValid()) return;
215 legacyBodyValue(backend_->applyLinearImpulse(ix, iy, iz));
216}
217void Body3D::applyLinearImpulseAt(float ix, float iy, float iz, float x, float y, float z) {
218 if (!isValid()) return;
219 legacyBodyValue(backend_->applyLinearImpulseAt(ix, iy, iz, x, y, z));
220}
221void Body3D::applyAngularImpulse(float ix, float iy, float iz) {
222 if (!isValid()) return;
223 legacyBodyValue(backend_->applyAngularImpulse(ix, iy, iz));
224}
225void Body3D::applyLocalForce(float fx, float fy, float fz, float x, float y, float z) {
226 if (!isValid()) return;
227 legacyBodyValue(backend_->applyLocalForce(fx, fy, fz, x, y, z));
228}
229void Body3D::applyLocalForceToCenter(float fx, float fy, float fz) {
230 if (!isValid()) return;
231 legacyBodyValue(backend_->applyLocalForceToCenter(fx, fy, fz));
232}
233void Body3D::applyLocalTorque(float tx, float ty, float tz) {
234 if (!isValid()) return;
235 legacyBodyValue(backend_->applyLocalTorque(tx, ty, tz));
236}
237void Body3D::applyLocalLinearImpulse(float ix, float iy, float iz, float x, float y,
238 float z) {
239 if (!isValid()) return;
240 legacyBodyValue(backend_->applyLocalLinearImpulse(ix, iy, iz, x, y, z));
241}
242void Body3D::applyLocalLinearImpulseToCenter(float ix, float iy, float iz) {
243 if (!isValid()) return;
244 legacyBodyValue(backend_->applyLocalLinearImpulseToCenter(ix, iy, iz));
245}
246void Body3D::applyLocalAngularImpulse(float ix, float iy, float iz) {
247 if (!isValid()) return;
248 legacyBodyValue(backend_->applyLocalAngularImpulse(ix, iy, iz));
249}
250void Body3D::setTargetTransform(float x, float y, float z, float qx, float qy, float qz,
251 float qw, float timeStep) {
252 if (!isValid()) return;
253 legacyBodyValue(backend_->setTargetTransform(x, y, z, qx, qy, qz, qw, timeStep));
254}
255void Body3D::setLinearDamping(float damping) {
256 if (!isValid()) return;
257 legacyBodyValue(backend_->setLinearDamping(damping));
258}
260 if (!isValid()) return 0.f;
261 return legacyBodyValue(backend_->getLinearDamping());
262}
263void Body3D::setAngularDamping(float damping) {
264 if (!isValid()) return;
265 legacyBodyValue(backend_->setAngularDamping(damping));
266}
268 if (!isValid()) return 0.f;
269 return legacyBodyValue(backend_->getAngularDamping());
270}
272 if (!isValid()) return;
273 legacyBodyValue(backend_->setGravityScale(scale));
274}
276 if (!isValid()) return 0.f;
277 return legacyBodyValue(backend_->getGravityScale());
278}
280 if (!isValid()) return;
281 legacyBodyValue(backend_->setSleepEnabled(enabled));
282}
284 if (!isValid()) return false;
285 return legacyBodyValue(backend_->isSleepEnabled());
286}
287void Body3D::setSleepThreshold(float threshold) {
288 if (!isValid()) return;
289 legacyBodyValue(backend_->setSleepThreshold(threshold));
290}
292 if (!isValid()) return 0.f;
293 return legacyBodyValue(backend_->getSleepThreshold());
294}
295void Body3D::setMotionLocks(bool linearX, bool linearY, bool linearZ, bool angularX,
296 bool angularY, bool angularZ) {
297 if (!isValid()) return;
298 legacyBodyValue(backend_->setMotionLocks(linearX, linearY, linearZ, angularX, angularY, angularZ));
299}
301 if (!isValid()) return false;
302 return legacyBodyValue(backend_->isLinearXLocked());
303}
305 if (!isValid()) return false;
306 return legacyBodyValue(backend_->isLinearYLocked());
307}
309 if (!isValid()) return false;
310 return legacyBodyValue(backend_->isLinearZLocked());
311}
313 if (!isValid()) return false;
314 return legacyBodyValue(backend_->isAngularXLocked());
315}
317 if (!isValid()) return false;
318 return legacyBodyValue(backend_->isAngularYLocked());
319}
321 if (!isValid()) return false;
322 return legacyBodyValue(backend_->isAngularZLocked());
323}
324void Body3D::setMassProperties(float mass, float centerX, float centerY, float centerZ,
325 float inertiaXX, float inertiaYY, float inertiaZZ,
326 float inertiaXY, float inertiaXZ, float inertiaYZ) {
327 if (!isValid()) return;
328 legacyBodyValue(backend_->setMassProperties(mass, centerX, centerY, centerZ, inertiaXX, inertiaYY, inertiaZZ,
329 inertiaXY, inertiaXZ, inertiaYZ));
330}
332 if (!isValid()) return;
333 legacyBodyValue(backend_->resetMassProperties());
334}
335float Body3D::getInertiaXX() const {
336 if (!isValid()) return 0.f;
337 return legacyBodyValue(backend_->getInertiaXX());
338}
339float Body3D::getInertiaYY() const {
340 if (!isValid()) return 0.f;
341 return legacyBodyValue(backend_->getInertiaYY());
342}
343float Body3D::getInertiaZZ() const {
344 if (!isValid()) return 0.f;
345 return legacyBodyValue(backend_->getInertiaZZ());
346}
347float Body3D::getInertiaXY() const {
348 if (!isValid()) return 0.f;
349 return legacyBodyValue(backend_->getInertiaXY());
350}
351float Body3D::getInertiaXZ() const {
352 if (!isValid()) return 0.f;
353 return legacyBodyValue(backend_->getInertiaXZ());
354}
355float Body3D::getInertiaYZ() const {
356 if (!isValid()) return 0.f;
357 return legacyBodyValue(backend_->getInertiaYZ());
358}
360 if (!isValid()) return 0.f;
361 return legacyBodyValue(backend_->getLocalCenterX());
362}
364 if (!isValid()) return 0.f;
365 return legacyBodyValue(backend_->getLocalCenterY());
366}
368 if (!isValid()) return 0.f;
369 return legacyBodyValue(backend_->getLocalCenterZ());
370}
372 if (!isValid()) return 0.f;
373 return legacyBodyValue(backend_->getWorldCenterX());
374}
376 if (!isValid()) return 0.f;
377 return legacyBodyValue(backend_->getWorldCenterY());
378}
380 if (!isValid()) return 0.f;
381 return legacyBodyValue(backend_->getWorldCenterZ());
382}
383void Body3D::setType(const std::string &bodyType) {
384 if (!isValid()) return;
385 if (bodyType != "static" && world_) {
386 for (Shape3D *shape : world_->shapes_) {
387 if (shape && shape->getBody() == this &&
388 (shape->geometry_.kind == Shape3D::Kind::TriangleMesh ||
389 shape->geometry_.kind == Shape3D::Kind::HeightField))
390 throw eve::Exception(
391 "Body3D.setType: triangle-mesh and height-field colliders require a static body");
392 }
393 }
394 legacyBodyValue(backend_->setType(bodyType));
395}
396std::string Body3D::getType() const {
397 if (!isValid()) return "static";
398 return legacyBodyValue(backend_->getType());
399}
400void Body3D::setFixedRotation(bool fixed) {
401 if (!isValid()) return;
402 legacyBodyValue(backend_->setFixedRotation(fixed));
403}
405 if (!isValid()) return false;
406 return legacyBodyValue(backend_->isFixedRotation());
407}
409 if (!isValid()) return;
410 legacyBodyValue(backend_->setActive(active));
411}
412bool Body3D::isActive() const {
413 if (!isValid()) return false;
414 return legacyBodyValue(backend_->isActive());
415}
417 if (!isValid()) return;
418 legacyBodyValue(backend_->setBullet(bullet));
419}
420bool Body3D::isBullet() const {
421 if (!isValid()) return false;
422 return legacyBodyValue(backend_->isBullet());
423}
425 if (!isValid()) return;
426 legacyBodyValue(backend_->setAwake(awake));
427}
428bool Body3D::isAwake() const {
429 if (!isValid()) return false;
430 return legacyBodyValue(backend_->isAwake());
431}
432Shape3D* Body3D::createShape(ShapeGeometry3D geometry, float density, float friction, float restitution) {
433 if (!isValid() || !world_) throw eve::Exception("Body3D.createShape: body destroyed");
434 auto backend = legacyBodyValue(backend_->createShape(geometry, density, friction, restitution));
435 auto shape = std::make_unique<Shape3D>(world_, this, std::move(backend), world_->nextShapeRuntimeHandle(),
436 std::move(geometry));
437 world_->shapes_.insert(shape.get());
438 return shape.release();
439}
440Shape3D* Body3D::newBoxShape(float width, float height, float depth, float density, float friction, float restitution) {
443 geometry.a = width * 0.5f;
444 geometry.b = height * 0.5f;
445 geometry.c = depth * 0.5f;
446 return createShape(std::move(geometry), density, friction, restitution);
447}
451 geometry.a = radius;
452 return createShape(std::move(geometry), density, friction, restitution);
453}
457 geometry.a = height * 0.5f;
458 geometry.b = radius;
459 return createShape(std::move(geometry), density, friction, restitution);
460}
461Shape3D* Body3D::newConvexHullShape(const std::vector<float>& vertices, int maxVertices, float density, float friction,
462 float restitution) {
465 geometry.hullVertices = vertices;
466 geometry.hullMaxVertices = maxVertices;
467 return createShape(std::move(geometry), density, friction, restitution);
468}
469Shape3D* Body3D::newTriangleMeshShape(const std::vector<float>& vertices, const std::vector<int32_t>& indices,
470 bool weldVertices, float weldTolerance, bool identifyEdges, bool useMedianSplit) {
473 geometry.meshVertices = vertices;
474 geometry.meshIndices = indices;
475 geometry.meshWeldVertices = weldVertices;
476 geometry.meshWeldTolerance = weldTolerance;
477 geometry.meshIdentifyEdges = identifyEdges;
478 geometry.meshUseMedianSplit = useMedianSplit;
479 return createShape(std::move(geometry), 0.f, 0.2f, 0.f);
480}
481Shape3D* Body3D::newHeightFieldShape(int countX, int countZ, float cellSizeX, float cellSizeZ,
482 const std::vector<float>& heights, float globalMin, float globalMax,
483 bool clockwiseWinding) {
486 geometry.heightCountX = countX;
487 geometry.heightCountZ = countZ;
488 geometry.heightCellSizeX = cellSizeX;
489 geometry.heightCellSizeZ = cellSizeZ;
490 geometry.heightValues = heights;
491 geometry.heightGlobalMin = globalMin;
492 geometry.heightGlobalMax = globalMax;
493 geometry.heightClockwise = clockwiseWinding;
494 return createShape(std::move(geometry), 0.f, 0.2f, 0.f);
495}
496} // namespace eve::physics
double z
double y
double x
bool & active
EVEngine assertion entry point, backed by zeroerr.
#define EV_PARAM_CHECK(cond,...)
Validate a function parameter / public API precondition.
Definition Assert.h:30
const std::string & s
bool awake
float friction
float density
ShaderImageInput shape
std::vector< std::uint32_t > indices
std::uint32_t height
std::uint32_t width
std::array< float, 3 > scale
std::string id
Poco::JSON::Object::Ptr result
double radius
Definition MeleeHit.cpp:42
OceanRenderBackend backend
std::string geometry
double restitution
std::array< double, 2 > vertices[3]
std::uint32_t depth
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static constexpr RuntimeHandle invalid() noexcept
Returns the canonical invalid handle.
bool isAngularYLocked() const
Whether rotation around Y is locked.
Definition Body3D.cpp:316
void setActive(bool active)
Disables/enables the body and its shapes.
Definition Body3D.cpp:408
bool isAngularXLocked() const
Whether rotation around X is locked.
Definition Body3D.cpp:312
void setRotation(float qx, float qy, float qz, float qw)
Orientation as quaternion (x, y, z, w).
Definition Body3D.cpp:109
std::vector< float > localToWorldVector(float x, float y, float z) const
Rotates a body-local direction/vector into world space; returns {x,y,z}.
Definition Body3D.cpp:179
float getInertiaYZ() const
Local symmetric inertia tensor YZ component.
Definition Body3D.cpp:355
std::vector< float > worldToLocalVector(float x, float y, float z) const
Rotates a world direction/vector into body-local space; returns {x,y,z}.
Definition Body3D.cpp:186
~Body3D()
Body 3 d.
Definition Body3D.cpp:32
float getLocalCenterY() const
Local center of mass Y coordinate.
Definition Body3D.cpp:363
bool isBullet() const
True when bullet.
Definition Body3D.cpp:420
void setAngularDamping(float damping)
Angular damping coefficient, finite and non-negative.
Definition Body3D.cpp:263
bool isAngularZLocked() const
Whether rotation around Z is locked.
Definition Body3D.cpp:320
bool isActive() const
True when active.
Definition Body3D.cpp:412
void applyForce(float fx, float fy, float fz)
Force applied at the center of mass.
Definition Body3D.cpp:201
float getWorldCenterX() const
World center of mass X coordinate.
Definition Body3D.cpp:371
float getLinearVelocityY() const
Returns the linear velocity y.
Definition Body3D.cpp:137
std::vector< float > localToWorldPoint(float x, float y, float z) const
Converts a body-local point to world coordinates; returns {x,y,z}.
Definition Body3D.cpp:165
void applyLinearImpulse(float ix, float iy, float iz)
Instantaneous linear impulse.
Definition Body3D.cpp:213
void setFixedRotation(bool fixed)
Lock all angular axes (Box3D motion locks).
Definition Body3D.cpp:400
void applyAngularImpulse(float ix, float iy, float iz)
Instantaneous angular impulse.
Definition Body3D.cpp:221
float getInertiaYY() const
Local inertia tensor YY component about the center of mass.
Definition Body3D.cpp:339
float getAngularDamping() const
Current angular damping coefficient.
Definition Body3D.cpp:267
float getX() const
Returns the x.
Definition Body3D.cpp:97
void setLinearDamping(float damping)
Linear damping coefficient, finite and non-negative.
Definition Body3D.cpp:255
std::vector< float > worldToLocalPoint(float x, float y, float z) const
Converts a world point to body-local coordinates; returns {x,y,z}.
Definition Body3D.cpp:172
void applyLocalForceToCenter(float fx, float fy, float fz)
Body-local force applied at the center of mass.
Definition Body3D.cpp:229
bool isLinearYLocked() const
Whether translation along Y is locked.
Definition Body3D.cpp:304
float getMass() const
Body mass in kg.
Definition Body3D.cpp:145
bool isFixedRotation() const
True when fixed rotation.
Definition Body3D.cpp:404
eve::Result< PhysicsVector3D > getLocalPointVelocityOwned(float x, float y, float z) const
Returns allocation-free world velocity at a body-local point.
Definition Body3D.cpp:194
eve::Result< PhysicsVector3D > worldToLocalPointOwned(float x, float y, float z) const
Converts a world point to an allocation-free owning value with structured stale/input failure.
Definition Body3D.cpp:176
void setBullet(bool bullet)
CCD bullet mode.
Definition Body3D.cpp:416
Shape3D * newBoxShape(float width, float height, float depth, float density=1.f, float friction=0.2f, float restitution=0.f)
Creates a box shape in meter-space units.
Definition Body3D.cpp:440
bool isValid() const
True while the underlying Box3D body is still alive.
Definition Body3D.cpp:57
void applyLocalTorque(float tx, float ty, float tz)
Body-local torque.
Definition Body3D.cpp:233
float getY() const
Returns the y.
Definition Body3D.cpp:101
Shape3D * newTriangleMeshShape(const std::vector< float > &vertices, const std::vector< int32_t > &indices, bool weldVertices=true, float weldTolerance=0.001f, bool identifyEdges=true, bool useMedianSplit=false)
Creates a static concave triangle-mesh collider from packed arrays.
Definition Body3D.cpp:469
void setAwake(bool awake)
Wakes / sleeps the body manually.
Definition Body3D.cpp:424
void applyLinearImpulseAt(float ix, float iy, float iz, float x, float y, float z)
Instantaneous linear impulse applied at a world position.
Definition Body3D.cpp:217
eve::Result< PhysicsVector3D > localToWorldPointOwned(float x, float y, float z) const
Converts a local point to an allocation-free owning value with structured stale/input failure.
Definition Body3D.cpp:169
float getLinearDamping() const
Current linear damping coefficient.
Definition Body3D.cpp:259
Shape3D * newConvexHullShape(const std::vector< float > &vertices, int maxVertices=64, float density=1.f, float friction=0.2f, float restitution=0.f)
Creates a convex hull from packed local XYZ vertices.
Definition Body3D.cpp:461
float getInertiaXZ() const
Local symmetric inertia tensor XZ component.
Definition Body3D.cpp:351
void destroy()
Destroys the body inside its world.
Definition Body3D.cpp:65
float getRotZ() const
Returns the rot z.
Definition Body3D.cpp:121
float getSleepThreshold() const
Current sleep velocity threshold.
Definition Body3D.cpp:291
void setMassProperties(float mass, float centerX, float centerY, float centerZ, float inertiaXX, float inertiaYY, float inertiaZZ, float inertiaXY=0.f, float inertiaXZ=0.f, float inertiaYZ=0.f)
Overrides mass, local center of mass, and the symmetric local inertia tensor.
Definition Body3D.cpp:324
void setTargetTransform(float x, float y, float z, float qx, float qy, float qz, float qw, float timeStep)
Drives a kinematic body to a target pose over a positive time step. The target quaternion is normaliz...
Definition Body3D.cpp:250
float getRotY() const
Returns the rot y.
Definition Body3D.cpp:117
void applyLocalForce(float fx, float fy, float fz, float x, float y, float z)
Body-local force applied at a body-local point.
Definition Body3D.cpp:225
bool isLinearZLocked() const
Whether translation along Z is locked.
Definition Body3D.cpp:308
float getGravityScale() const
Current world-gravity multiplier.
Definition Body3D.cpp:275
float getLocalCenterZ() const
Local center of mass Z coordinate.
Definition Body3D.cpp:367
float getRotX() const
Returns the rot x.
Definition Body3D.cpp:113
bool isLinearXLocked() const
Whether translation along X is locked.
Definition Body3D.cpp:300
float getAngularVelocityZ() const
Returns the angular velocity z.
Definition Body3D.cpp:161
void setSleepEnabled(bool enabled)
Enables or disables automatic sleeping for this body.
Definition Body3D.cpp:279
void invalidate()
Internal: marks the wrapper invalid after world destruction.
Definition Body3D.cpp:59
void applyLocalLinearImpulseToCenter(float ix, float iy, float iz)
Body-local linear impulse applied at the center of mass.
Definition Body3D.cpp:242
float getAngularVelocityX() const
Returns the angular velocity x.
Definition Body3D.cpp:153
std::string getType() const
Returns the type.
Definition Body3D.cpp:396
float getRotW() const
Returns the rot w.
Definition Body3D.cpp:125
void applyTorque(float tx, float ty, float tz)
Torque applied in world space.
Definition Body3D.cpp:209
bool isSleepEnabled() const
Whether automatic sleeping is enabled.
Definition Body3D.cpp:283
float getInertiaXX() const
Local inertia tensor XX component about the center of mass.
Definition Body3D.cpp:335
void setMotionLocks(bool linearX, bool linearY, bool linearZ, bool angularX, bool angularY, bool angularZ)
Atomically locks translation and rotation on individual local solver axes.
Definition Body3D.cpp:295
void applyForceAt(float fx, float fy, float fz, float x, float y, float z)
Force applied at a world position.
Definition Body3D.cpp:205
void resetMassProperties()
Restores automatic mass, center, and inertia calculation from attached shapes.
Definition Body3D.cpp:331
eve::Result< PhysicsVector3D > localToWorldVectorOwned(float x, float y, float z) const
Rotates a local vector into an allocation-free owning world vector.
Definition Body3D.cpp:183
float getInertiaXY() const
Local symmetric inertia tensor XY component.
Definition Body3D.cpp:347
float getWorldCenterZ() const
World center of mass Z coordinate.
Definition Body3D.cpp:379
float getInertiaZZ() const
Local inertia tensor ZZ component about the center of mass.
Definition Body3D.cpp:343
Shape3D * newCapsuleShape(float height, float radius, float density=1.f, float friction=0.2f, float restitution=0.f)
Creates a capsule along local Y.
Definition Body3D.cpp:454
void setLinearVelocity(float vx, float vy, float vz)
Linear velocity in m/s.
Definition Body3D.cpp:129
void applyLocalLinearImpulse(float ix, float iy, float iz, float x, float y, float z)
Body-local linear impulse applied at a body-local point.
Definition Body3D.cpp:237
float getWorldCenterY() const
World center of mass Y coordinate.
Definition Body3D.cpp:375
void setGravityScale(float scale)
Multiplier applied to world gravity; may be negative.
Definition Body3D.cpp:271
bool isAwake() const
True when awake.
Definition Body3D.cpp:428
Shape3D * newHeightFieldShape(int countX, int countZ, float cellSizeX, float cellSizeZ, const std::vector< float > &heights, float globalMin, float globalMax, bool clockwiseWinding=false)
Creates a compressed static height-field collider extending along +X/+Z.
Definition Body3D.cpp:481
Body3D(World3D *world, std::unique_ptr< IBodyBackend3D > backend, int id, PhysicsBodyHandle runtimeHandle)
Internal: consumes an owning body backend (use World3D::newBody).
Definition Body3D.cpp:26
void setPosition(float x, float y, float z)
Position in meters.
Definition Body3D.cpp:93
void setType(const std::string &bodyType)
"static" | "kinematic" | "dynamic".
Definition Body3D.cpp:383
float getLocalCenterX() const
Local center of mass X coordinate.
Definition Body3D.cpp:359
float getLinearVelocityZ() const
Returns the linear velocity z.
Definition Body3D.cpp:141
std::vector< float > getWorldPointVelocity(float x, float y, float z) const
World-space velocity at the supplied world point.
Definition Body3D.cpp:197
void setAngularVelocity(float wx, float wy, float wz)
Angular velocity in rad/s.
Definition Body3D.cpp:149
void setSleepThreshold(float threshold)
Sleep velocity threshold, finite and non-negative.
Definition Body3D.cpp:287
float getAngularVelocityY() const
Returns the angular velocity y.
Definition Body3D.cpp:157
std::vector< float > getLocalPointVelocity(float x, float y, float z) const
World-space velocity at a point expressed in body-local coordinates.
Definition Body3D.cpp:190
float getZ() const
Returns the z.
Definition Body3D.cpp:105
Shape3D * newSphereShape(float radius, float density=1.f, float friction=0.2f, float restitution=0.f)
Creates a sphere shape in meter-space units.
Definition Body3D.cpp:448
float getLinearVelocityX() const
Returns the linear velocity x.
Definition Body3D.cpp:133
void applyLocalAngularImpulse(float ix, float iy, float iz)
Body-local angular impulse.
Definition Body3D.cpp:246
Script-facing joint owned by a World3D. Legacy scalar/void methods adapt the checked backend contract...
Definition Joint3D.h:27
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:34
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
void forgetBody(Body3D *body)
Raw Box3D world id.
Definition World3D.cpp:502
void forgetJoint(Joint3D *joint)
Internal: removes a joint wrapper from ownership bookkeeping.
Definition World3D.cpp:305
bool isValid() const
True while the underlying Box3D world is alive.
Definition World3D.cpp:239
void forgetShape(Shape3D *shape)
Definition World3D.cpp:507
PhysicsShapeHandle nextShapeRuntimeHandle()
Internal: next generation-qualified shape handle.
Definition World3D.cpp:410
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
bool enabled
Owning, backend-independent shape source; metres, local quaternion XYZW.