93 lines
2.4 KiB
C++
93 lines
2.4 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef FLOORPLAN_3D_STAIRS_H
|
||
#define FLOORPLAN_3D_STAIRS_H
|
||
|
||
#include "Obstacle3.h"
|
||
#include "primitives/Cube.h"
|
||
|
||
namespace Floorplan3D {
|
||
|
||
class Stairs {
|
||
|
||
public:
|
||
|
||
std::vector<Obstacle3D> getStairs(const Floorplan::Floor* f) {
|
||
std::vector<Obstacle3D> res;
|
||
for (const Floorplan::Stair* stair : f->stairs) {
|
||
res.push_back(getStair(f, stair));
|
||
}
|
||
return res;
|
||
}
|
||
|
||
Obstacle3D getStair(const Floorplan::Floor* f, const Floorplan::Stair* s) {
|
||
|
||
Obstacle3D res(Obstacle3D::Type::STAIR, Floorplan::Material::CONCRETE);
|
||
|
||
std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(s->getParts(), f);
|
||
for (const Floorplan::Quad3& quad : quads) {
|
||
|
||
if (quad.isLeveled()) {
|
||
|
||
const float h = 0.2;
|
||
const Point3 ph(0,0,h);
|
||
const Cube cube = Cube::fromBottomAndHeight(quad.p1-ph, quad.p2-ph, quad.p3-ph, quad.p4-ph, 0.2);
|
||
|
||
const std::vector<Triangle3> tmp = cube.getTriangles();
|
||
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
|
||
|
||
} else {
|
||
|
||
const Point3 dir1 = quad.p3 - quad.p2;
|
||
const Point3 dir2 = quad.p4 - quad.p1;
|
||
float stepH = 0.20;
|
||
const float totalH = quad.p3.z - quad.p1.z;
|
||
const int numStairs = std::round(totalH / stepH);
|
||
stepH = totalH / numStairs;
|
||
|
||
for (int i = 0; i < numStairs; ++i) {
|
||
|
||
//const float y1 = quad.p1.z + (stepH * i);
|
||
//const float y2 = y1 + stepH;
|
||
|
||
Point3 p1b = quad.p1 + dir1 * (i+0) / numStairs; p1b.z -= stepH;
|
||
Point3 p2b = quad.p2 + dir2 * (i+0) / numStairs; p2b.z -= stepH;
|
||
|
||
const Point3 p3t = quad.p2 + dir2 * (i+1) / numStairs;
|
||
const Point3 p4t = quad.p1 + dir1 * (i+1) / numStairs;
|
||
|
||
const Point3 p1t(p1b.x, p1b.y, p4t.z);
|
||
const Point3 p2t(p2b.x, p2b.y, p3t.z);
|
||
|
||
const Point3 p3b(p3t.x, p3t.y, p2b.z+stepH);
|
||
const Point3 p4b(p4t.x, p4t.y, p1b.z+stepH);
|
||
|
||
const Cube cube = Cube::fromVertices(p1t, p2t, p3t, p4t, p1b, p2b, p3b, p4b);
|
||
const std::vector<Triangle3> tmp = cube.getTriangles();
|
||
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
|
||
|
||
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
return res;
|
||
|
||
}
|
||
|
||
};
|
||
|
||
}
|
||
|
||
#endif // FLOORPLAN_3D_STAIRS_H
|