载入中...
搜索中...
未找到
InspectionPlan.cpp
浏览该文件的文档.
3
4#include <algorithm>
5#include <cmath>
6#include <limits>
7
8namespace eve::graphics {
9namespace {
10template <class T>
11Result<T> invalid(const char* message) {
13}
14bool finite(const glm::mat4& matrix) {
15 for (int column = 0; column < 4; ++column)
16 for (int row = 0; row < 4; ++row)
17 if (!std::isfinite(matrix[column][row])) return false;
18 return true;
19}
20} // namespace
21
23 uint32_t cellWidth, uint32_t cellHeight, float padding) {
24 if (!cellWidth || !cellHeight || cellWidth > 1024 || cellHeight > 1024 || !camera.width || !camera.height ||
25 !std::isfinite(padding) || padding < 1.f || padding > 4.f || !finite(camera.view) || !finite(camera.projection))
26 return invalid<InspectionViews>("Invalid inspection viewport, camera matrix or padding");
27 for (int axis = 0; axis < 3; ++axis)
28 if (!std::isfinite(bounds.minimum[axis]) || !std::isfinite(bounds.maximum[axis]) ||
29 bounds.minimum[axis] > bounds.maximum[axis] || std::abs(bounds.minimum[axis]) > 1e8f ||
30 std::abs(bounds.maximum[axis]) > 1e8f)
31 return invalid<InspectionViews>("Inspection bounds must be finite, ordered and within world limits");
32 const glm::vec3 extent = bounds.maximum - bounds.minimum;
33 const float largest = std::max({extent.x, extent.y, extent.z});
34 if (largest < 1e-4f) return invalid<InspectionViews>("Inspection bounds are empty or too small");
36 output.center = bounds.minimum + extent * .5f;
37 output.worldUnitsPerPixel = padding * std::max(std::max(extent.x, extent.z) / float(cellWidth),
38 std::max(extent.y, extent.z) / float(cellHeight));
39 const float halfWidth = output.worldUnitsPerPixel * float(cellWidth) * .5f;
40 const float halfHeight = output.worldUnitsPerPixel * float(cellHeight) * .5f;
41 const float nearZ = std::max(.001f, largest * .01f);
42 const float distance = largest * 2.f + nearZ;
43 const float farZ = largest * 4.f + nearZ * 2.f;
44 const std::array<glm::vec3, 3> directions{{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}}};
45 const std::array<glm::vec3, 3> ups{{{0, 1, 0}, {0, 1, 0}, {0, 0, -1}}};
46 for (size_t index = 0; index < 3; ++index) {
47 auto& view = output.cameras[index];
48 view.width = cellWidth;
49 view.height = cellHeight;
50 view.view = glm::lookAtRH(output.center + directions[index] * distance, output.center, ups[index]);
51 view.projection = orthoVulkanRH_ZO(-halfWidth, halfWidth, -halfHeight, halfHeight, nearZ, farZ);
52 if (!finite(view.view) || !finite(view.projection))
53 return invalid<InspectionViews>("Inspection camera cannot represent bounds at this world position");
54 // Verify the actual float matrices, not just the ideal framing formula.
55 for (unsigned corner = 0; corner < 8; ++corner) {
56 glm::vec3 position;
57 for (int axis = 0; axis < 3; ++axis)
58 position[axis] = (corner & (1u << axis)) ? bounds.maximum[axis] : bounds.minimum[axis];
59 const auto clip = view.projection * view.view * glm::vec4(position, 1.f);
60 if (!std::isfinite(clip.x) || !std::isfinite(clip.y) || !std::isfinite(clip.z) ||
61 std::abs(clip.x) > 1.001f || std::abs(clip.y) > 1.001f || clip.z < 0.f || clip.z > 1.f)
62 return invalid<InspectionViews>("Inspection bounds lose precision or fall outside the planned view");
63 }
64 }
65 output.cameras[3] = camera;
67}
68
71 using Samples = std::vector<InspectionSample>;
72 if (!std::isfinite(start) || !std::isfinite(end) || !std::isfinite(fps) || !std::isfinite(duration) || start < 0. ||
73 end < start || end > 1e6 || fps <= 0. || fps > 240. || duration <= 0. || duration > 1e6 ||
76 return invalid<Samples>("Invalid inspection time range, frame rate, clip duration or loop mode");
77 Samples samples;
78 samples.reserve(16);
79 const double tolerance = 4. * std::numeric_limits<double>::epsilon() * std::max(1., end);
80 for (unsigned index = 0; index <= 16; ++index) {
81 double time = start + double(index) / fps;
82 if (time > end && time - end > tolerance) break;
83 if (index == 16) return invalid<Samples>("Inspection request exceeds 16 samples; split the range explicitly");
84 if (index != 0 && std::abs(time - end) <= tolerance) time = end;
85 double clipTime = loop == InspectionLoop::Repeat ? std::fmod(time, duration) : time;
87 const double wrapTolerance = std::min(duration * 1e-6, tolerance);
88 if (clipTime <= wrapTolerance || duration - clipTime <= wrapTolerance) clipTime = 0.;
89 }
90 samples.push_back({time, clipTime});
91 }
92 return Result<Samples>::success(std::move(samples));
93}
94} // namespace eve::graphics
Duration start
float duration
std::string output
std::string message
float camera[2]
glm::vec4 clip
float halfWidth
JointPoint2D axis
std::array< float, 3 > position
float distance
OceanSprayView view
size_t directions
bool finite
glm::dmat4 matrix
unsigned column
size_t end
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Status invalid(const char *message)
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
InspectionLoop
Explicit clip-end behavior; loop wraps exact duration to time zero.
Result< std::vector< InspectionSample > > planInspectionSamples(double start, double end, double fps, double duration, InspectionLoop loop)
Result< InspectionViews > planInspectionViews(const InspectionBounds &bounds, const InspectionCamera &camera, uint32_t cellWidth, uint32_t cellHeight, float padding)
glm::mat4 orthoVulkanRH_ZO(float left, float right, float bottom, float top, float zNear, float zFar)
Ortho vulkan rh zo.
Definition ClipSpace.h:30
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
Definition Widget.cpp:870
World-space bounds, supplied from one frozen pose or a union of sampled poses.
Owning camera value snapshot; matrices use engine RH, zero-to-one, Y-down clip space.
Row-major front (+Z), right (+X), top (+Y), and unchanged game camera.
glm::vec4 bounds