94 lines
2.5 KiB
C++
94 lines
2.5 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_HANDRAILS_H
|
||
#define FLOORPLAN_3D_HANDRAILS_H
|
||
|
||
#include "Obstacle3.h"
|
||
#include "misc.h"
|
||
|
||
namespace Floorplan3D {
|
||
|
||
class Handrails {
|
||
|
||
public:
|
||
|
||
std::vector<Obstacle3D> getHandrails(const Floorplan::Floor* f) {
|
||
std::vector<Obstacle3D> res;
|
||
for (const Floorplan::FloorObstacle* o: f->obstacles) {
|
||
const Floorplan::FloorObstacleLine* line = dynamic_cast<const Floorplan::FloorObstacleLine*>(o);
|
||
if (line && line->type == Floorplan::ObstacleType::HANDRAIL) {
|
||
res.push_back(getHandrail(f, line));
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
|
||
Obstacle3D getHandrail(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol) const {
|
||
|
||
FloorPos fpos(f);
|
||
|
||
// target
|
||
Obstacle3D res(getType(fol), fol->material);
|
||
|
||
const float thickness_m = 0.05;
|
||
const Point2 from = fol->from;
|
||
const Point2 to = fol->to;
|
||
const Point2 cen2 = (from+to)/2;
|
||
|
||
// edges
|
||
const float z1 = fpos.z1;
|
||
const float z2 = fpos.z1 + 1.0;
|
||
Point3 p1 = Point3(from.x, from.y, z1);
|
||
Point3 p2 = Point3(to.x, to.y, z1);
|
||
Point3 p3 = Point3(from.x, from.y, z2);
|
||
Point3 p4 = Point3(to.x, to.y, z2);
|
||
|
||
const float rad = std::atan2(to.y - from.y, to.x - from.x);
|
||
const float deg = rad * 180 / M_PI;
|
||
|
||
// cube's destination center
|
||
const Point3 pUp(cen2.x, cen2.y, z2);
|
||
|
||
const float sx = from.getDistance(to) / 2;
|
||
const float sy = thickness_m / 2;
|
||
const float sz = thickness_m / 2;
|
||
const Point3 size(sx, sy, sz);
|
||
const Point3 rot(0,0,deg);
|
||
|
||
// upper bar
|
||
const Cube cubeUpper(pUp, size, rot);
|
||
const std::vector<Triangle3> tmp = cubeUpper.getTriangles();
|
||
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
|
||
|
||
const Point3 d1 = p2-p1;
|
||
const Point3 d2 = p4-p3;
|
||
const int numBars = d2.length() / 0.75f;
|
||
for (int i = 1; i < numBars; ++i) {
|
||
const Point3 s = p1 + d1 * i / numBars;
|
||
const Point3 e = p3 + d2 * i / numBars;
|
||
const Point3 c = (s+e)/2;
|
||
const Point3 size(thickness_m/2, thickness_m/2, s.getDistance(e)/2 - thickness_m);
|
||
const Cube cube(c, size, rot);
|
||
const std::vector<Triangle3> tmp = cube.getTriangles();
|
||
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
|
||
}
|
||
|
||
// done
|
||
return res;
|
||
|
||
}
|
||
|
||
};
|
||
|
||
}
|
||
|
||
#endif // FLOORPLAN_3D_HANDRAILS_H
|