added support for .obj objects within the floorplan

include objects within navmesh calculation
include objects within 3d mesh generation
minor changes/fixes
This commit is contained in:
2018-02-17 17:20:43 +01:00
parent 42a3a47317
commit 8358f45674
15 changed files with 770 additions and 114 deletions

View File

@@ -9,8 +9,8 @@ class BBox2 {
protected:
static constexpr float MAX = +99999;
static constexpr float MIN = -99999;
static constexpr float MAX = +99999999;
static constexpr float MIN = -99999999;
/** minimum */
Point2 p1;
@@ -26,17 +26,28 @@ public:
/** ctor */
BBox2(const Point2& p1, const Point2& p2) : p1(p1), p2(p2) {;}
/** ctor */
BBox2(const float x1, const float y1, const float x2, const float y2) : p1(x1,y1), p2(x2,y2) {;}
/** adjust the bounding-box by adding this point */
void add(const Point2& p) {
add(p.x, p.y);
}
if (p.x > p2.x) {p2.x = p.x;}
if (p.y > p2.y) {p2.y = p.y;}
/** adjust the bounding-box by adding this point */
void add(const float x, const float y) {
if (p.x < p1.x) {p1.x = p.x;}
if (p.y < p1.y) {p1.y = p.y;}
if (x > p2.x) {p2.x = x;}
if (y > p2.y) {p2.y = y;}
if (x < p1.x) {p1.x = x;}
if (y < p1.y) {p1.y = y;}
}
/** the area spanned by the bbox */
float getArea() const {return getSize().x * getSize().y;}
/** returns true if the bbox is not yet configured */
bool isInvalid() const {
return p1.x == MAX || p1.y == MAX || p2.x == MIN || p2.y == MIN;
@@ -63,6 +74,44 @@ public:
(p2.y == o.p2.y);
}
bool intersects(const BBox2& o) const {
// TODO is this correct?
if (o.p2.x < p1.x) {return false;}
if (o.p1.x > p2.x) {return false;}
if (o.p2.y < p1.y) {return false;}
if (o.p1.y > p2.y) {return false;}
return true;
// return (p1.x <= o.p2.x) &&
// (p1.y <= o.p2.y) &&
// (p2.x >= o.p1.x) &&
// (p2.y >= o.p1.y);
}
BBox2 combine(const BBox2& o) {
// TODO is this correct?
const float x1 = std::min(p1.x, o.p1.x);
const float x2 = std::max(p2.x, o.p2.x);
const float y1 = std::min(p1.y, o.p1.y);
const float y2 = std::max(p2.y, o.p2.y);
return BBox2(x1,y1, x2,y2);
}
BBox2 intersection(const BBox2& o) {
// TODO is this correct?
const float x1 = std::max(p1.x, o.p1.x);
const float x2 = std::min(p2.x, o.p2.x);
const float y1 = std::max(p1.y, o.p1.y);
const float y2 = std::min(p2.y, o.p2.y);
return BBox2(x1,y1, x2,y2);
}
/** does the BBox intersect with the given line? */
bool intersects (const Line2& l) const {
const Line2 l1(p1.x, p1.y, p2.x, p1.y); // upper
@@ -87,10 +136,14 @@ public:
}
bool contains(const Point2& p) const {
if (p.x < p1.x) {return false;}
if (p.x > p2.x) {return false;}
if (p.y < p1.y) {return false;}
if (p.y > p2.y) {return false;}
return contains(p.x, p.y);
}
bool contains(const float x, const float y) const {
if (x < p1.x) {return false;}
if (x > p2.x) {return false;}
if (y < p1.y) {return false;}
if (y > p2.y) {return false;}
return true;
}