载入中...
搜索中...
未找到
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 <box3d/id.h>
14
15namespace eve::physics {
16
17class World3D;
18class Shape3D;
19
25public:
27 Body3D(World3D *world, b3BodyId bodyId, int id, PhysicsBodyHandle runtimeHandle);
29 ~Body3D();
30
31 Body3D(const Body3D &) = delete;
32 Body3D &operator=(const Body3D &) = delete;
33
35 int getId() const { return id_; }
36
38 void setPosition(float x, float y, float z);
40 float getX() const;
42 float getY() const;
44 float getZ() const;
45
47 void setRotation(float qx, float qy, float qz, float qw);
49 float getRotX() const;
51 float getRotY() const;
53 float getRotZ() const;
55 float getRotW() const;
56
58 void setLinearVelocity(float vx, float vy, float vz);
60 float getLinearVelocityX() const;
62 float getLinearVelocityY() const;
64 float getLinearVelocityZ() const;
65
67 float getMass() const;
68
70 void setAngularVelocity(float wx, float wy, float wz);
72 float getAngularVelocityX() const;
74 float getAngularVelocityY() const;
76 float getAngularVelocityZ() const;
77
79 std::vector<float> localToWorldPoint(float x, float y, float z) const;
81 [[nodiscard]] eve::Result<PhysicsVector3D> localToWorldPointOwned(float x, float y, float z) const;
83 std::vector<float> worldToLocalPoint(float x, float y, float z) const;
85 [[nodiscard]] eve::Result<PhysicsVector3D> worldToLocalPointOwned(float x, float y, float z) const;
87 std::vector<float> localToWorldVector(float x, float y, float z) const;
89 [[nodiscard]] eve::Result<PhysicsVector3D> localToWorldVectorOwned(float x, float y, float z) const;
91 std::vector<float> worldToLocalVector(float x, float y, float z) const;
93 std::vector<float> getLocalPointVelocity(float x, float y, float z) const;
95 [[nodiscard]] eve::Result<PhysicsVector3D> getLocalPointVelocityOwned(float x, float y, float z) const;
97 std::vector<float> getWorldPointVelocity(float x, float y, float z) const;
98
100 void applyForce(float fx, float fy, float fz);
102 void applyForceAt(float fx, float fy, float fz, float x, float y, float z);
104 void applyTorque(float tx, float ty, float tz);
106 void applyLinearImpulse(float ix, float iy, float iz);
108 void applyLinearImpulseAt(float ix, float iy, float iz, float x, float y, float z);
110 void applyAngularImpulse(float ix, float iy, float iz);
112 void applyLocalForce(float fx, float fy, float fz, float x, float y, float z);
114 void applyLocalForceToCenter(float fx, float fy, float fz);
116 void applyLocalTorque(float tx, float ty, float tz);
118 void applyLocalLinearImpulse(float ix, float iy, float iz, float x, float y, float z);
120 void applyLocalLinearImpulseToCenter(float ix, float iy, float iz);
122 void applyLocalAngularImpulse(float ix, float iy, float iz);
123
128 void setTargetTransform(float x, float y, float z, float qx, float qy, float qz, float qw,
129 float timeStep);
130
132 void setLinearDamping(float damping);
134 float getLinearDamping() const;
136 void setAngularDamping(float damping);
138 float getAngularDamping() const;
140 void setGravityScale(float scale);
142 float getGravityScale() const;
143
145 void setSleepEnabled(bool enabled);
147 bool isSleepEnabled() const;
149 void setSleepThreshold(float threshold);
151 float getSleepThreshold() const;
152
156 void setMotionLocks(bool linearX, bool linearY, bool linearZ, bool angularX, bool angularY,
157 bool angularZ);
159 bool isLinearXLocked() const;
161 bool isLinearYLocked() const;
163 bool isLinearZLocked() const;
165 bool isAngularXLocked() const;
167 bool isAngularYLocked() const;
169 bool isAngularZLocked() const;
170
185 void setMassProperties(float mass, float centerX, float centerY, float centerZ,
186 float inertiaXX, float inertiaYY, float inertiaZZ,
187 float inertiaXY = 0.f, float inertiaXZ = 0.f,
188 float inertiaYZ = 0.f);
190 void resetMassProperties();
192 float getInertiaXX() const;
194 float getInertiaYY() const;
196 float getInertiaZZ() const;
198 float getInertiaXY() const;
200 float getInertiaXZ() const;
202 float getInertiaYZ() const;
204 float getLocalCenterX() const;
206 float getLocalCenterY() const;
208 float getLocalCenterZ() const;
210 float getWorldCenterX() const;
212 float getWorldCenterY() const;
214 float getWorldCenterZ() const;
215
217 void setType(const std::string &bodyType);
219 std::string getType() const;
220
222 void setFixedRotation(bool fixed);
224 bool isFixedRotation() const;
225
227 void setActive(bool active);
229 bool isActive() const;
230
232 void setBullet(bool bullet);
234 bool isBullet() const;
235
237 void setAwake(bool awake);
239 bool isAwake() const;
240
249 Shape3D *newBoxShape(float width, float height, float depth, float density = 1.f,
250 float friction = 0.2f, float restitution = 0.f);
259 Shape3D *newSphereShape(float radius, float density = 1.f, float friction = 0.2f,
260 float restitution = 0.f);
269 Shape3D *newCapsuleShape(float height, float radius, float density = 1.f,
270 float friction = 0.2f, float restitution = 0.f);
285 Shape3D *newConvexHullShape(const std::vector<float> &vertices, int maxVertices = 64,
286 float density = 1.f, float friction = 0.2f,
287 float restitution = 0.f);
303 Shape3D *newTriangleMeshShape(const std::vector<float> &vertices,
304 const std::vector<int32_t> &indices,
305 bool weldVertices = true, float weldTolerance = 0.001f,
306 bool identifyEdges = true, bool useMedianSplit = false);
323 Shape3D *newHeightFieldShape(int countX, int countZ, float cellSizeX, float cellSizeZ,
324 const std::vector<float> &heights, float globalMin,
325 float globalMax, bool clockwiseWinding = false);
326
328 void destroy();
329
338 World3D *getWorld() { return world_; }
347 const World3D *getWorld() const { return world_; }
349 b3BodyId raw() const { return bodyId_; }
351 bool isValid() const;
352
357 [[nodiscard]] PhysicsBodyHandle runtimeHandle() const noexcept { return runtimeHandle_; }
358
360 void invalidate();
361
362private:
363 friend struct WorldSnapshotAccess;
364 friend class World3D;
365 friend class Shape3D;
366
367 World3D *world_ = nullptr;
368 b3BodyId bodyId_{};
369 int id_ = 0;
370 PhysicsBodyHandle runtimeHandle_ = PhysicsBodyHandle::invalid();
371};
372
373} // namespace eve::physics
bool & active
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
std::vector< std::uint32_t > indices
std::uint32_t height
std::uint32_t width
void(* destroy)(void *)
std::array< float, 3 > scale
Owning, generation-qualified results for cross-module 3D physics queries.
World3D * world
Process-local, generation-qualified handles owned by the physics domain.
std::vector< Point > vertices
float radius
Move-only, checked operation results for the common layer.
double restitution
std::uint32_t depth
float vz
float wz
float wx
float vy
float qy
bool awake
float vx
float qx
float qw
float qz
float wy
bool bullet
Move-only operation result carrying either a value or Status.
Definition Result.h:155
3D rigid body (Box3D) in meter-space coordinates (+Y up by convention). Owned by a World3D; create pr...
Definition Body3D.h:24
bool isAngularYLocked() const
Whether rotation around Y is locked.
bool isAngularXLocked() const
Whether rotation around X is locked.
Body3D & operator=(const Body3D &)=delete
float getInertiaYZ() const
Local symmetric inertia tensor YZ component.
b3BodyId raw() const
Raw.
Definition Body3D.h:349
const World3D * getWorld() const
Returns the owning world as a read-only borrowed pointer.
Definition Body3D.h:347
float getLocalCenterY() const
Local center of mass Y coordinate.
bool isAngularZLocked() const
Whether rotation around Z is locked.
float getWorldCenterX() const
World center of mass X coordinate.
float getInertiaYY() const
Local inertia tensor YY component about the center of mass.
bool isLinearYLocked() const
Whether translation along Y is locked.
World3D * getWorld()
Returns the owning world, or null after invalidation.
Definition Body3D.h:338
float getInertiaXZ() const
Local symmetric inertia tensor XZ component.
bool isLinearZLocked() const
Whether translation along Z is locked.
float getLocalCenterZ() const
Local center of mass Z coordinate.
bool isLinearXLocked() const
Whether translation along X is locked.
Body3D(const Body3D &)=delete
int getId() const
Stable id used by collision events.
Definition Body3D.h:35
float getInertiaXX() const
Local inertia tensor XX component about the center of mass.
float getInertiaXY() const
Local symmetric inertia tensor XY component.
float getWorldCenterZ() const
World center of mass Z coordinate.
float getInertiaZZ() const
Local inertia tensor ZZ component about the center of mass.
float getWorldCenterY() const
World center of mass Y coordinate.
float getLocalCenterX() const
Local center of mass X coordinate.
PhysicsBodyHandle runtimeHandle() const noexcept
Returns the process-local solver handle used by PhysicsLink.
Definition Body3D.h:357
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:25
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
bool enabled