mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-08 06:06:51 +02:00
#8 remove poly-portals clipping code
This commit is contained in:
@@ -6,12 +6,6 @@
|
||||
#define MAX_CLIP_PLANES 16
|
||||
|
||||
struct Frustum {
|
||||
|
||||
struct Poly {
|
||||
vec3 vertices[MAX_CLIP_PLANES];
|
||||
int count;
|
||||
};
|
||||
|
||||
vec3 pos;
|
||||
vec4 planes[MAX_CLIP_PLANES * 2]; // + buffer for OBB visibility test
|
||||
int start, count;
|
||||
@@ -35,71 +29,6 @@ struct Frustum {
|
||||
planes[i] *= 1.0f / planes[i].xyz.length();
|
||||
}
|
||||
|
||||
void calcPlanes(const Poly &poly) {
|
||||
count = 1 + poly.count; // add one for near plane (not changing)
|
||||
ASSERT(count < MAX_CLIP_PLANES);
|
||||
if (count < 4) return;
|
||||
|
||||
vec3 e1 = poly.vertices[0] - pos;
|
||||
for (int i = 1; i < count; i++) {
|
||||
vec3 e2 = poly.vertices[i % poly.count] - pos;
|
||||
planes[i].xyz = e1.cross(e2).normal();
|
||||
planes[i].w = -(pos.dot(planes[i].xyz));
|
||||
e1 = e2;
|
||||
}
|
||||
}
|
||||
|
||||
void clipPlane(const Poly &src, Poly &dst, const vec4 &plane) {
|
||||
dst.count = 0;
|
||||
if (!src.count) return;
|
||||
|
||||
float t1 = src.vertices[0].dot(plane.xyz) + plane.w;
|
||||
|
||||
for (int i = 0; i < src.count; i++) {
|
||||
const vec3 &v1 = src.vertices[i];
|
||||
const vec3 &v2 = src.vertices[(i + 1) % src.count];
|
||||
|
||||
float t2 = v2.dot(plane.xyz) + plane.w;
|
||||
|
||||
// hack for big float numbers
|
||||
int s1 = (int)t1;
|
||||
int s2 = (int)t2;
|
||||
|
||||
if (s1 >= 0) {
|
||||
dst.vertices[dst.count++] = v1;
|
||||
ASSERT(dst.count < MAX_CLIP_PLANES);
|
||||
}
|
||||
|
||||
if ((s1 ^ s2) < 0) { // check for opposite signs
|
||||
float k1 = t2 / (t2 - t1);
|
||||
float k2 = t1 / (t2 - t1);
|
||||
dst.vertices[dst.count++] = v1 * (float)k1 - v2 * (float)k2;
|
||||
ASSERT(dst.count < MAX_CLIP_PLANES);
|
||||
}
|
||||
|
||||
t1 = t2;
|
||||
}
|
||||
}
|
||||
|
||||
bool clipByPortal(const vec3 *vertices, int vCount, const vec3 &normal) {
|
||||
if (normal.dot(pos - vertices[0]) < 0.0f) // check portal winding order
|
||||
return false;
|
||||
|
||||
Poly poly[2];
|
||||
|
||||
poly[0].count = vCount;
|
||||
memmove(poly[0].vertices, vertices, sizeof(vec3) * poly[0].count);
|
||||
#ifdef _DEBUG
|
||||
debugPoly.count = 0;
|
||||
#endif
|
||||
int j = 0;
|
||||
for (int i = 1; i < count; i++, j ^= 1)
|
||||
clipPlane(poly[j], poly[j ^ 1], planes[i]);
|
||||
|
||||
calcPlanes(poly[j]);
|
||||
return count >= 4;
|
||||
}
|
||||
|
||||
// AABB visibility check
|
||||
bool isVisible(const vec3 &min, const vec3 &max) const {
|
||||
if (count < 4) return false;
|
||||
|
Reference in New Issue
Block a user