feat: added the ability to render whole model

This commit is contained in:
2025-11-13 13:47:59 +01:00
parent f8ffb9c0b3
commit e370c1d0c3
6 changed files with 123 additions and 22 deletions

View File

@@ -4,25 +4,48 @@
#include "fastmath.hpp"
struct polygon {
const vec3 points[3];
vec3 points[3];
vec3 delta[3];
bool skip = false;
polygon(const vec3 &v1, const vec3 &v2, const vec3 &v3)
: points{v1, v2, v3} {}
polygon() : points{} {}
void calcDelta() {
bool contains(const vec3 &p) {
for (int i = 0; i < 3; i++) {
int n = (i + 1) % 3;
vec3 d = points[n] - points[i];
d = vec3(d.y(), -d.x(), d.z());
delta[i] = vec3(d.y(), -d.x(), d.z());
if (delta[i].isSmall()) {
skip = true;
return;
}
}
}
bool contains(const vec3 &p) {
if (skip)
return false;
for (int i = 0; i < 3; i++) {
int n = (i + 1) % 3;
vec3 s = p - points[n];
if (s * d < decimal(0.0))
if (s.isSmall())
return false;
if (s * delta[i] <= decimal(0.0))
return false;
}
return true;
}
friend std::ostream &operator<<(std::ostream &os, const polygon &p) {
for (int i = 0; i < 3; i++) {
os << p.points[i];
}
return os;
}
};
#endif