载入中...
搜索中...
未找到
DistanceField3D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <algorithm>
6#include <cstddef>
7#include <vector>
8
9namespace eve::physics {
10
17public:
19 DistanceField3D(int width, int height, int depth, float cellSize, float originX,
20 float originY, float originZ, float outsideDistance);
21
23 void setDistances(const std::vector<float> &distances);
25 void fill(float distance);
36 void setDistanceRegion(int x, int y, int z, int width, int height, int depth,
37 const std::vector<float> &distances);
39 void fillRegion(int x, int y, int z, int width, int height, int depth, float distance);
41 void setDistance(int x, int y, int z, float distance);
43 float getDistance(int x, int y, int z) const;
45 float sample(float x, float y, float z) const;
46
48 int getWidth() const { return width_; }
50 int getHeight() const { return height_; }
52 int getDepth() const { return depth_; }
54 int getSampleCount() const { return static_cast<int>(distances_.size()); }
56 float getCellSize() const { return cellSize_; }
58 float getOriginX() const { return originX_; }
60 float getOriginY() const { return originY_; }
62 float getOriginZ() const { return originZ_; }
64 float getOutsideDistance() const { return outsideDistance_; }
66 unsigned int getRevision() const { return revision_; }
67
69 void sampleNormal(float x, float y, float z);
71 float getNormalX() const { return normalX_; }
73 float getNormalY() const { return normalY_; }
75 float getNormalZ() const { return normalZ_; }
76
78 bool checkSphere(float x, float y, float z, float radius);
80 bool checkCapsule(float ax, float ay, float az, float bx, float by, float bz,
81 float radius);
93 bool castSphere(float x, float y, float z, float radius, float deltaX, float deltaY,
94 float deltaZ);
99 bool castCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius,
100 float deltaX, float deltaY, float deltaZ);
106 bool moveCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius,
107 float deltaX, float deltaY, float deltaZ);
109 void setMoverUp(float x, float y, float z);
111 void setMoverSlopeLimit(float degrees);
113 void setMoverSkinWidth(float width);
115 float getMoverSkinWidth() const { return moverSkinWidth_; }
117 void setMoverGroundSnap(float distance);
119 float getMoverGroundSnap() const { return moverGroundSnap_; }
121 void setMoverStepHeight(float height);
123 float getMoverStepHeight() const { return moverStepHeight_; }
125 float getCollisionDistance() const { return collisionDistance_; }
127 float getCollisionX() const { return collisionX_; }
129 float getCollisionY() const { return collisionY_; }
131 float getCollisionZ() const { return collisionZ_; }
133 float getSurfaceX() const { return surfaceX_; }
135 float getSurfaceY() const { return surfaceY_; }
137 float getSurfaceZ() const { return surfaceZ_; }
139 float getShapeContactX() const { return shapeContactX_; }
141 float getShapeContactY() const { return shapeContactY_; }
143 float getShapeContactZ() const { return shapeContactZ_; }
145 float getPenetrationDepth() const { return std::max(0.f, -collisionDistance_); }
147 float getCastFraction() const { return castFraction_; }
149 float getCastDistance() const { return castDistance_; }
151 bool didCastStartInside() const { return castStartedInside_; }
153 float getMoverDeltaX() const { return moverDeltaX_; }
155 float getMoverDeltaY() const { return moverDeltaY_; }
157 float getMoverDeltaZ() const { return moverDeltaZ_; }
159 float getMoverNormalX() const { return moverNormalX_; }
161 float getMoverNormalY() const { return moverNormalY_; }
163 float getMoverNormalZ() const { return moverNormalZ_; }
165 int getMoverIterations() const { return moverIterations_; }
167 bool isMoverGrounded() const { return moverGrounded_; }
169 float getMoverGroundDot() const { return moverGroundDot_; }
171 bool didMoverHitWall() const { return moverHitWall_; }
172
173private:
174 bool validIndex(int x, int y, int z) const;
175 bool validRegion(int x, int y, int z, int width, int height, int depth) const;
176 size_t index(int x, int y, int z) const;
177 void setCollisionResult(float x, float y, float z, float radius);
178 float capsuleClearance(float ax, float ay, float az, float bx, float by, float bz,
179 float radius, float &closestX, float &closestY, float &closestZ) const;
180 void updateContactPoints(float x, float y, float z, float radius);
181 void setCastResult(float fraction, float travelLength, float x, float y, float z,
182 float clearance, float radius, bool startedInside);
183
184 int width_, height_, depth_;
185 float cellSize_, originX_, originY_, originZ_, outsideDistance_;
186 std::vector<float> distances_;
187 float normalX_ = 0.f, normalY_ = 1.f, normalZ_ = 0.f;
188 float collisionDistance_ = 0.f, collisionX_ = 0.f, collisionY_ = 0.f,
189 collisionZ_ = 0.f;
190 float surfaceX_ = 0.f, surfaceY_ = 0.f, surfaceZ_ = 0.f;
191 float shapeContactX_ = 0.f, shapeContactY_ = 0.f, shapeContactZ_ = 0.f;
192 float castFraction_ = 1.f, castDistance_ = 0.f;
193 bool castStartedInside_ = false;
194 float moverDeltaX_ = 0.f, moverDeltaY_ = 0.f, moverDeltaZ_ = 0.f;
195 float moverNormalX_ = 0.f, moverNormalY_ = 1.f, moverNormalZ_ = 0.f;
196 int moverIterations_ = 0;
197 float moverUpX_ = 0.f, moverUpY_ = 1.f, moverUpZ_ = 0.f;
198 float moverSlopeCos_ = 0.6427876f;
199 float moverSkinWidth_ = 0.f;
200 float moverGroundSnap_ = 0.f;
201 float moverStepHeight_ = 0.f;
202 float moverGroundDot_ = -1.f;
203 bool moverGrounded_ = false;
204 bool moverHitWall_ = false;
205 bool moverStepping_ = false;
206 unsigned int revision_ = 0;
207};
208
209} // namespace eve::physics
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float degrees
Definition CardTypes.cpp:35
int bz
Definition CaveMesh.cpp:114
int ax
Definition CaveMesh.cpp:113
int ay
Definition CaveMesh.cpp:113
int bx
Definition CaveMesh.cpp:114
int az
Definition CaveMesh.cpp:113
int by
Definition CaveMesh.cpp:114
#define EVENGINE_API_WORLD
Definition Export.h:109
std::uint32_t height
std::uint32_t width
float distance
float radius
uint32_t index
std::uint32_t depth
Regular 3D signed-distance grid for terrain and voxel collision queries. Negative samples are solid,...
float getMoverGroundDot() const
Greatest dot product between mover Up and a normal from the latest move.
float getCollisionDistance() const
Signed clearance from the last check (negative means penetration).
float getCastDistance() const
World-space travel distance at the last cast hit.
int getSampleCount() const
Total number of signed-distance samples.
float getCollisionY() const
Y coordinate of the closest sampled point from the last collision check.
bool isMoverGrounded() const
Whether the latest move encountered a normal within the walkable slope limit.
float getMoverGroundSnap() const
Current post-move ground-snap distance.
float getOriginX() const
World-space X coordinate of grid vertex (0,0,0).
float getMoverStepHeight() const
Current automatic step height; zero disables step climbing.
float getOriginY() const
World-space Y coordinate of grid vertex (0,0,0).
float getCellSize() const
World-space distance between adjacent grid vertices.
int getHeight() const
Number of grid vertices along the Y axis.
float getOutsideDistance() const
Distance returned for world samples outside the grid.
float getNormalZ() const
Z component of the most recently sampled collision normal.
float getMoverDeltaX() const
Resolved X displacement from the most recent moveCapsule call.
unsigned int getRevision() const
Monotonic wrapping counter incremented once after each successful mutation.
float getShapeContactY() const
Y coordinate on the sphere or capsule surface along the contact normal.
float getNormalX() const
X component of the most recently sampled collision normal.
float getMoverNormalX() const
X component of the most recent blocking or recovery normal.
float getMoverDeltaZ() const
Resolved Z displacement from the most recent moveCapsule call.
bool didCastStartInside() const
Whether the most recent cast began overlapping the solid.
float getCollisionX() const
X coordinate of the closest sampled point from the last collision check.
int getMoverIterations() const
Number of solver passes used by the most recent moveCapsule call.
float getShapeContactZ() const
Z coordinate on the sphere or capsule surface along the contact normal.
int getWidth() const
Number of grid vertices along the X axis.
float getNormalY() const
Y component of the most recently sampled collision normal.
bool didMoverHitWall() const
Whether the latest move encountered a non-walkable contact normal.
float getSurfaceX() const
X coordinate of the projected signed-distance-field surface point.
float getCastFraction() const
Fraction in [0,1] of the requested displacement at the last cast hit.
float getMoverDeltaY() const
Resolved Y displacement from the most recent moveCapsule call.
float getCollisionZ() const
Z coordinate of the closest sampled point from the last collision check.
float getShapeContactX() const
X coordinate on the sphere or capsule surface along the contact normal.
float getPenetrationDepth() const
Non-negative overlap depth from the most recent overlap, cast, or move query.
float getSurfaceZ() const
Z coordinate of the projected signed-distance-field surface point.
float getSurfaceY() const
Y coordinate of the projected signed-distance-field surface point.
float getMoverNormalZ() const
Z component of the most recent blocking or recovery normal.
int getDepth() const
Number of grid vertices along the Z axis.
float getMoverSkinWidth() const
Current mover separation from collision surfaces.
float getOriginZ() const
World-space Z coordinate of grid vertex (0,0,0).
float getMoverNormalY() const
Y component of the most recent blocking or recovery normal.
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36