Merge branch 'master' of https://git.frank-ebner.de/FHWS/Indoor
This commit is contained in:
@@ -66,6 +66,12 @@ public:
|
||||
Point2 getCenter() const { return (p1+p2) / 2; }
|
||||
|
||||
|
||||
Point2 getCorner1() const {return Point2(p1.x, p1.y);}
|
||||
Point2 getCorner2() const {return Point2(p2.x, p1.y);}
|
||||
Point2 getCorner3() const {return Point2(p1.x, p2.y);}
|
||||
Point2 getCorner4() const {return Point2(p2.x, p2.y);}
|
||||
|
||||
|
||||
/** equal? */
|
||||
bool operator == (const BBox2& o) const {
|
||||
return (p1.x == o.p1.x) &&
|
||||
|
||||
13
geo/BBox3.h
13
geo/BBox3.h
@@ -54,6 +54,9 @@ public:
|
||||
/** get the bbox's maximum */
|
||||
const Point3& getMax() const {return p2;}
|
||||
|
||||
/** get the bbox's size */
|
||||
const Point3 getSize() const {return p2-p1;}
|
||||
|
||||
/** equal? */
|
||||
bool operator == (const BBox3& o) const {
|
||||
return (p1.x == o.p1.x) &&
|
||||
@@ -86,11 +89,11 @@ public:
|
||||
p2 += p; // increase maximum
|
||||
}
|
||||
|
||||
/** set both, min/max z to the same value */
|
||||
void setZ(const float z) {
|
||||
p1.z = z;
|
||||
p2.z = z;
|
||||
}
|
||||
/** set both, min/max z to the same value */
|
||||
void setZ(const float z) {
|
||||
p1.z = z;
|
||||
p2.z = z;
|
||||
}
|
||||
|
||||
/** does the bbox contain the given point? */
|
||||
bool contains(const Point3& p) const {
|
||||
|
||||
@@ -86,6 +86,48 @@ public:
|
||||
|
||||
}
|
||||
|
||||
/** add some slight delta to prevent rounding issues */
|
||||
bool intersectsDelta(const Ray3& ray, const double delta, Point3& pos) const {
|
||||
|
||||
const Point3 e1 = p2-p1;
|
||||
const Point3 e2 = p3-p1;
|
||||
|
||||
// make delta an absolute value (independent of the triangle's size)
|
||||
// larger triangle -> smaller delta, as u,v are [0:1]
|
||||
//double deltaU = delta/e2.length();
|
||||
//double deltaV = delta/e1.length();
|
||||
|
||||
const double deltaU = delta;
|
||||
const double deltaV = delta;
|
||||
|
||||
const Point3 h = cross(ray.dir, e2);
|
||||
const double a = dot(e1, h);
|
||||
|
||||
if (a > -0.00001 && a < 0.00001) {return false;}
|
||||
|
||||
const double f = 1/a;
|
||||
|
||||
const Point3 s = ray.start - p1;
|
||||
const double u = f * dot(s,h);
|
||||
|
||||
if (u < 0.0-deltaU || u > 1.0+deltaU) {return false;}
|
||||
|
||||
const Point3 q = cross(s, e1);
|
||||
const double v = f * dot(ray.dir, q);
|
||||
|
||||
if (v < 0.0-deltaV || u + v > 1.0+deltaV) {return false;}
|
||||
const double t = f * dot(e2,q);
|
||||
|
||||
|
||||
if (t > 0.00001) {
|
||||
pos = ray.start + (ray.dir * t);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
int rayIntersectsTriangle(float *p, float *d,
|
||||
float *v0, float *v1, float *v2) {
|
||||
|
||||
Reference in New Issue
Block a user