载入中...
搜索中...
未找到
World3DMover.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cfloat>
5#include <cmath>
6#include <utility>
7
8namespace eve::physics {
9using namespace world3d_detail;
10
11void World3D::setMoverUp(float x, float y, float z) { worldValue(rigidBackend_->setMoverUp(x, y, z)); }
12
13
15 if (!std::isfinite(degrees)) throw eve::Exception("World3D.setMoverSlopeLimit: degrees must be finite");
16 degrees = std::clamp(degrees, 0.f, 89.9f);
17 moverSlopeCos_ = std::cos(degrees * 0.01745329251994329577f);
18}
19
20bool World3D::moveCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius, float dx, float dy,
21 float dz) {
22 return worldValue(rigidBackend_->moveCapsule(ax, ay, az, bx, by, bz, radius, dx, dy, dz));
23}
24
25
26eve::Result<CapsuleMove3D> World3D::moveCapsuleOwned(float ax, float ay, float az, float bx, float by, float bz,
27 float radius, float dx, float dy, float dz, QueryFilter3D filter,
28 CapsuleMovePolicy3D policy) {
29 return rigidBackend_->moveCapsuleOwned(ax, ay, az, bx, by, bz, radius, dx, dy, dz, filter, policy);
30}
31
32
34 if (index < 0 || index >= static_cast<int>(queryBodyIds_.size()))
35 throw eve::Exception("World3D.getQueryBodyId: index out of range");
36 return queryBodyIds_[static_cast<size_t>(index)];
37}
38
39bool World3D::pointProbe(float x, float y, float z, float radius, ClothContact3D *out) const {
40 return pointProbeFiltered(x, y, z, radius, out, ~uint64_t{0}, ~uint64_t{0}) == ClothProbeStatus::Hit;
41}
42
44 uint64_t categoryBits, uint64_t maskBits) const {
45 if (!out) return ClothProbeStatus::Miss;
46 *out = worldValue(rigidBackend_->pointProbeFiltered(x, y, z, radius, categoryBits, maskBits));
48}
49
50
51const World3D::RayResult &World3D::rayResultAt(int index, const char *operation) const {
52 if (index < 0 || index >= static_cast<int>(rayResults_.size()))
53 throw eve::Exception("World3D.%s: index out of range", operation);
54 return rayResults_[static_cast<size_t>(index)];
55}
56
57#define EV_RAY_INT_GETTER(name, member) \
58 int World3D::name(int index) const { return rayResultAt(index, #name).member; }
59
60EV_RAY_INT_GETTER(getRayResultBodyId, bodyId)
61EV_RAY_INT_GETTER(getRayResultShapeId, shapeId)
62EV_RAY_INT_GETTER(getRayResultShapeTag, shapeTag)
63EV_RAY_INT_GETTER(getRayResultMaterialId, materialId)
64EV_RAY_INT_GETTER(getRayResultTriangleIndex, triangleIndex)
65
66#undef EV_RAY_INT_GETTER
67
68#define EV_RAY_FLOAT_GETTER(name, member) \
69 float World3D::name(int index) const { return rayResultAt(index, #name).member; }
70
71EV_RAY_FLOAT_GETTER(getRayResultX, x)
72EV_RAY_FLOAT_GETTER(getRayResultY, y)
73EV_RAY_FLOAT_GETTER(getRayResultZ, z)
74EV_RAY_FLOAT_GETTER(getRayResultNormalX, normalX)
75EV_RAY_FLOAT_GETTER(getRayResultNormalY, normalY)
76EV_RAY_FLOAT_GETTER(getRayResultNormalZ, normalZ)
77EV_RAY_FLOAT_GETTER(getRayResultFraction, fraction)
78
79#undef EV_RAY_FLOAT_GETTER
80
81const World3D::ShapeCastResult &World3D::shapeCastResultAt(int index, const char *operation) const {
82 if (index < 0 || index >= static_cast<int>(shapeCastResults_.size()))
83 throw eve::Exception("World3D.%s: index out of range", operation);
84 return shapeCastResults_[static_cast<size_t>(index)];
85}
86
87#define EV_CAST_INT_GETTER(name, member) \
88 int World3D::name(int index) const { return shapeCastResultAt(index, #name).member; }
89
90EV_CAST_INT_GETTER(getShapeCastResultBodyId, bodyId)
91EV_CAST_INT_GETTER(getShapeCastResultShapeId, shapeId)
92EV_CAST_INT_GETTER(getShapeCastResultShapeTag, shapeTag)
93EV_CAST_INT_GETTER(getShapeCastResultMaterialId, materialId)
94EV_CAST_INT_GETTER(getShapeCastResultTriangleIndex, triangleIndex)
95
96#undef EV_CAST_INT_GETTER
97
98#define EV_CAST_FLOAT_GETTER(name, member) \
99 float World3D::name(int index) const { return shapeCastResultAt(index, #name).member; }
100
101EV_CAST_FLOAT_GETTER(getShapeCastResultX, x)
102EV_CAST_FLOAT_GETTER(getShapeCastResultY, y)
103EV_CAST_FLOAT_GETTER(getShapeCastResultZ, z)
104EV_CAST_FLOAT_GETTER(getShapeCastResultNormalX, normalX)
105EV_CAST_FLOAT_GETTER(getShapeCastResultNormalY, normalY)
106EV_CAST_FLOAT_GETTER(getShapeCastResultNormalZ, normalZ)
107EV_CAST_FLOAT_GETTER(getShapeCastResultFraction, fraction)
108
109#undef EV_CAST_FLOAT_GETTER
110
112 if (index < 0 || index >= static_cast<int>(queryShapes_.size()))
113 throw eve::Exception("World3D.getQueryShapeId: index out of range");
114 return queryShapes_[static_cast<size_t>(index)].first;
115}
116
118 if (index < 0 || index >= static_cast<int>(queryShapes_.size()))
119 throw eve::Exception("World3D.getQueryShapeTag: index out of range");
120 return queryShapes_[static_cast<size_t>(index)].second;
121}
122
123} // namespace eve::physics
double z
double y
double x
ActionParameterOperation operation
float degrees
Definition CardTypes.cpp:38
std::int32_t second
std::int32_t first
double radius
Definition MeleeHit.cpp:42
glm::dvec3 dx
glm::dvec3 dz
std::string filter
ScriptStructure out
float dy
Definition Shadow.cpp:151
uint32_t index
float fraction
int shapeId
#define EV_RAY_FLOAT_GETTER(name, member)
#define EV_CAST_INT_GETTER(name, member)
#define EV_RAY_INT_GETTER(name, member)
#define EV_CAST_FLOAT_GETTER(name, member)
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:176
int getQueryBodyId(int index) const
Body id of the i-th query hit.
int getQueryShapeId(int index) const
Stable shape id of the i-th shape hit, sorted ascending.
int getQueryShapeTag(int index) const
User tag paired with the i-th shape hit.
void setMoverUp(float x, float y, float z)
Set the up direction used for grounded and slope classification.
eve::Result< CapsuleMove3D > moveCapsuleOwned(float ax, float ay, float az, float bx, float by, float bz, float radius, float dx, float dy, float dz, QueryFilter3D filter={}, CapsuleMovePolicy3D policy={})
Moves a capsule and returns all resolved movement data as one owning result.
void setMoverSlopeLimit(float degrees)
Set maximum walkable slope in degrees, clamped to [0, 89.9].
bool pointProbe(float x, float y, float z, float radius, ClothContact3D *out) const
Probe the deepest non-sensor shape within radius of a meter-space point. Returns false when nothing i...
ClothProbeStatus pointProbeFiltered(float x, float y, float z, float radius, ClothContact3D *out, uint64_t categoryBits, uint64_t maskBits) const
Probe a cloth particle using symmetric category/mask filtering.
bool moveCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius, float dx, float dy, float dz)
Move a capsule with continuous collision and multi-plane sliding. Existing penetration is recovered b...
T worldValue(eve::Result< T > result)
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
ClothProbeStatus
Named outcome for a filtered cloth particle probe.
Per-call capsule mover classification policy; never mutates persistent World3D settings.
Result of a 3D point probe: deepest non-sensor shape within radius. Normal points from the shape towa...
Query filter applied atomically for one owning query operation.