载入中...
搜索中...
未找到
Body3D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Result.h"
8
9#include <string>
10#include <vector>
11#include <cstdint>
12
13#include <memory>
15
16namespace eve::physics {
17namespace box3d {
18class WorldBackend;
19}
20
21namespace box3d {
22struct Access;
23}
24class World3D;
25class Shape3D;
26
32public:
34 Body3D(World3D *world, std::unique_ptr<IBodyBackend3D> backend, int id, PhysicsBodyHandle runtimeHandle);
36 ~Body3D();
37
38 Body3D(const Body3D &) = delete;
39 Body3D &operator=(const Body3D &) = delete;
40
42 int getId() const { return id_; }
43
45 void setPosition(float x, float y, float z);
47 float getX() const;
49 float getY() const;
51 float getZ() const;
52
54 void setRotation(float qx, float qy, float qz, float qw);
56 float getRotX() const;
58 float getRotY() const;
60 float getRotZ() const;
62 float getRotW() const;
63
65 void setLinearVelocity(float vx, float vy, float vz);
67 float getLinearVelocityX() const;
69 float getLinearVelocityY() const;
71 float getLinearVelocityZ() const;
72
74 float getMass() const;
75
77 void setAngularVelocity(float wx, float wy, float wz);
79 float getAngularVelocityX() const;
81 float getAngularVelocityY() const;
83 float getAngularVelocityZ() const;
84
86 std::vector<float> localToWorldPoint(float x, float y, float z) const;
88 [[nodiscard]] eve::Result<PhysicsVector3D> localToWorldPointOwned(float x, float y, float z) const;
90 std::vector<float> worldToLocalPoint(float x, float y, float z) const;
92 [[nodiscard]] eve::Result<PhysicsVector3D> worldToLocalPointOwned(float x, float y, float z) const;
94 std::vector<float> localToWorldVector(float x, float y, float z) const;
96 [[nodiscard]] eve::Result<PhysicsVector3D> localToWorldVectorOwned(float x, float y, float z) const;
98 std::vector<float> worldToLocalVector(float x, float y, float z) const;
100 std::vector<float> getLocalPointVelocity(float x, float y, float z) const;
102 [[nodiscard]] eve::Result<PhysicsVector3D> getLocalPointVelocityOwned(float x, float y, float z) const;
104 std::vector<float> getWorldPointVelocity(float x, float y, float z) const;
105
107 void applyForce(float fx, float fy, float fz);
109 void applyForceAt(float fx, float fy, float fz, float x, float y, float z);
111 void applyTorque(float tx, float ty, float tz);
113 void applyLinearImpulse(float ix, float iy, float iz);
115 void applyLinearImpulseAt(float ix, float iy, float iz, float x, float y, float z);
117 void applyAngularImpulse(float ix, float iy, float iz);
119 void applyLocalForce(float fx, float fy, float fz, float x, float y, float z);
121 void applyLocalForceToCenter(float fx, float fy, float fz);
123 void applyLocalTorque(float tx, float ty, float tz);
125 void applyLocalLinearImpulse(float ix, float iy, float iz, float x, float y, float z);
127 void applyLocalLinearImpulseToCenter(float ix, float iy, float iz);
129 void applyLocalAngularImpulse(float ix, float iy, float iz);
130
135 void setTargetTransform(float x, float y, float z, float qx, float qy, float qz, float qw,
136 float timeStep);
137
139 void setLinearDamping(float damping);
141 float getLinearDamping() const;
143 void setAngularDamping(float damping);
145 float getAngularDamping() const;
147 void setGravityScale(float scale);
149 float getGravityScale() const;
150
152 void setSleepEnabled(bool enabled);
154 bool isSleepEnabled() const;
156 void setSleepThreshold(float threshold);
158 float getSleepThreshold() const;
159
163 void setMotionLocks(bool linearX, bool linearY, bool linearZ, bool angularX, bool angularY,
164 bool angularZ);
166 bool isLinearXLocked() const;
168 bool isLinearYLocked() const;
170 bool isLinearZLocked() const;
172 bool isAngularXLocked() const;
174 bool isAngularYLocked() const;
176 bool isAngularZLocked() const;
177
192 void setMassProperties(float mass, float centerX, float centerY, float centerZ,
193 float inertiaXX, float inertiaYY, float inertiaZZ,
194 float inertiaXY = 0.f, float inertiaXZ = 0.f,
195 float inertiaYZ = 0.f);
197 void resetMassProperties();
199 float getInertiaXX() const;
201 float getInertiaYY() const;
203 float getInertiaZZ() const;
205 float getInertiaXY() const;
207 float getInertiaXZ() const;
209 float getInertiaYZ() const;
211 float getLocalCenterX() const;
213 float getLocalCenterY() const;
215 float getLocalCenterZ() const;
217 float getWorldCenterX() const;
219 float getWorldCenterY() const;
221 float getWorldCenterZ() const;
222
224 void setType(const std::string &bodyType);
226 std::string getType() const;
227
229 void setFixedRotation(bool fixed);
231 bool isFixedRotation() const;
232
234 void setActive(bool active);
236 bool isActive() const;
237
239 void setBullet(bool bullet);
241 bool isBullet() const;
242
244 void setAwake(bool awake);
246 bool isAwake() const;
247
256 Shape3D *newBoxShape(float width, float height, float depth, float density = 1.f,
257 float friction = 0.2f, float restitution = 0.f);
266 Shape3D *newSphereShape(float radius, float density = 1.f, float friction = 0.2f,
267 float restitution = 0.f);
276 Shape3D *newCapsuleShape(float height, float radius, float density = 1.f,
277 float friction = 0.2f, float restitution = 0.f);
292 Shape3D *newConvexHullShape(const std::vector<float> &vertices, int maxVertices = 64,
293 float density = 1.f, float friction = 0.2f,
294 float restitution = 0.f);
310 Shape3D *newTriangleMeshShape(const std::vector<float> &vertices,
311 const std::vector<int32_t> &indices,
312 bool weldVertices = true, float weldTolerance = 0.001f,
313 bool identifyEdges = true, bool useMedianSplit = false);
330 Shape3D *newHeightFieldShape(int countX, int countZ, float cellSizeX, float cellSizeZ,
331 const std::vector<float> &heights, float globalMin,
332 float globalMax, bool clockwiseWinding = false);
333
335 void destroy();
336
345 World3D *getWorld() { return world_; }
354 const World3D *getWorld() const { return world_; }
356 bool isValid() const;
357
362 [[nodiscard]] PhysicsBodyHandle runtimeHandle() const noexcept { return runtimeHandle_; }
363
365 void invalidate();
366
367private:
369 friend struct box3d::Access;
370 friend struct WorldSnapshotAccess;
372 friend class World3D;
373 friend class Shape3D;
374
375 Shape3D *createShape(ShapeGeometry3D geometry, float density, float friction, float restitution);
376 World3D *world_ = nullptr;
377 std::unique_ptr<IBodyBackend3D> backend_{};
378 int id_ = 0;
379 PhysicsBodyHandle runtimeHandle_ = PhysicsBodyHandle::invalid();
380};
381
382} // namespace eve::physics
double z
double y
double x
bool & active
bool awake
#define EVENGINE_API_WORLD
Definition Export.h:109
float friction
float density
std::vector< std::uint32_t > indices
std::uint32_t height
std::uint32_t width
void(* destroy)(void *)
std::array< float, 3 > scale
double radius
Definition MeleeHit.cpp:42
OceanRenderBackend backend
Owning, generation-qualified results for cross-module 3D physics queries.
Process-local, generation-qualified handles owned by the physics domain.
Move-only, checked operation results for the common layer.
std::string geometry
double restitution
std::array< double, 2 > vertices[3]
std::uint32_t depth
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
Body3D & operator=(const Body3D &)=delete
const World3D * getWorld() const
Returns the owning world as a read-only borrowed pointer.
Definition Body3D.h:354
World3D * getWorld()
Returns the owning world, or null after invalidation.
Definition Body3D.h:345
Body3D(const Body3D &)=delete
int getId() const
Stable id used by collision events.
Definition Body3D.h:42
PhysicsBodyHandle runtimeHandle() const noexcept
Returns the process-local solver handle used by PhysicsLink.
Definition Body3D.h:362
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
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
bool enabled
Owning, backend-independent shape source; metres, local quaternion XYZW.
Private bridge used exclusively by Box3D composition and native query code.
Definition Box3DBody.h:15