载入中...
搜索中...
未找到
Frustum.h
浏览该文件的文档.
1#pragma once
2
3#include <cmath>
4
5namespace eve::voxel {
6
8struct Frustum {
9 float planes[6][4]{};
10
15 static Frustum fromViewProjColumnMajor(const float *m16) {
16 Frustum f;
17 // Column-major → treat rows of transpose as m[col*4+row] access via
18 // row-major view of columns: plane = row3 ± row{0,1,2} of the matrix.
19 auto m = [&](int row, int col) -> float { return m16[col * 4 + row]; };
20 auto set = [&](int i, float a, float b, float c, float d) {
21 const float len = std::sqrt(a * a + b * b + c * c);
22 if (len > 1e-8f) {
23 f.planes[i][0] = a / len;
24 f.planes[i][1] = b / len;
25 f.planes[i][2] = c / len;
26 f.planes[i][3] = d / len;
27 } else {
28 f.planes[i][0] = a;
29 f.planes[i][1] = b;
30 f.planes[i][2] = c;
31 f.planes[i][3] = d;
32 }
33 };
34 // left, right, bottom, top, near, far
35 set(0, m(3, 0) + m(0, 0), m(3, 1) + m(0, 1), m(3, 2) + m(0, 2), m(3, 3) + m(0, 3));
36 set(1, m(3, 0) - m(0, 0), m(3, 1) - m(0, 1), m(3, 2) - m(0, 2), m(3, 3) - m(0, 3));
37 set(2, m(3, 0) + m(1, 0), m(3, 1) + m(1, 1), m(3, 2) + m(1, 2), m(3, 3) + m(1, 3));
38 set(3, m(3, 0) - m(1, 0), m(3, 1) - m(1, 1), m(3, 2) - m(1, 2), m(3, 3) - m(1, 3));
39 set(4, m(3, 0) + m(2, 0), m(3, 1) + m(2, 1), m(3, 2) + m(2, 2), m(3, 3) + m(2, 3));
40 set(5, m(3, 0) - m(2, 0), m(3, 1) - m(2, 1), m(3, 2) - m(2, 2), m(3, 3) - m(2, 3));
41 return f;
42 }
43
44 bool intersectsAABB(float minX, float minY, float minZ, float maxX, float maxY,
45 float maxZ) const {
46 for (int i = 0; i < 6; ++i) {
47 const float *p = planes[i];
48 const float x = p[0] >= 0.f ? maxX : minX;
49 const float y = p[1] >= 0.f ? maxY : minY;
50 const float z = p[2] >= 0.f ? maxZ : minZ;
51 if (p[0] * x + p[1] * y + p[2] * z + p[3] < 0.f) return false;
52 }
53 return true;
54 }
55};
56
57} // namespace eve::voxel
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
uint32_t a
uint32_t b
uint32_t c
float f
glm::vec4 p[6]
int d
float m[16]
方块类型定义:名字、各面图集纹理、方向性、组合声明。 方向性方块在注册时按 orientation 绕 Y 轴展开成多个"具体类型"变体, 每个变体持有旋转后的各面纹理;渲染端只消费纹理 id,不接触 ...
Definition Chunk.h:12
Six frustum planes in ax+by+cz+d >= 0 form (normals point inward).
Definition Frustum.h:8
static Frustum fromViewProjColumnMajor(const float *m16)
Extract from a column-major 4x4 view-projection matrix (RH + Vulkan ZO). Layout matches glm::mat4 mem...
Definition Frustum.h:15
bool intersectsAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) const
Definition Frustum.h:44
float planes[6][4]
Definition Frustum.h:9