68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#ifndef FLOORPLAN_3D_DOORS_H
|
|
#define FLOORPLAN_3D_DOORS_H
|
|
|
|
#include "Walls.h"
|
|
#include "misc.h"
|
|
#include "primitives/Cube.h"
|
|
|
|
namespace Floorplan3D {
|
|
|
|
class Doors {
|
|
|
|
Cube::Part cubeParts = (Cube::Part) 63; // leftright,topbottom,rearfront
|
|
|
|
public:
|
|
|
|
std::vector<Obstacle3D> getDoors(const Floorplan::Floor* floor) {
|
|
std::vector<Obstacle3D> res;
|
|
for (const Floorplan::FloorObstacle* o: floor->obstacles) {
|
|
const Floorplan::FloorObstacleWall* wall = dynamic_cast<const Floorplan::FloorObstacleWall*>(o);
|
|
if (wall) {
|
|
for (const Floorplan::FloorObstacleWallDoor* door : wall->doors) {
|
|
res.push_back(getDoor(floor, wall, door));
|
|
}
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
Obstacle3D getDoor(const Floorplan::Floor* f, const Floorplan::FloorObstacleWall* wall, const Floorplan::FloorObstacleWallDoor* door) {
|
|
|
|
FloorPos fpos(f);
|
|
|
|
const float thickness_m = 0.1;
|
|
const Point2 from = door->getStart(wall);
|
|
const Point2 to = door->getEnd(wall);
|
|
const Point2 cen2 = (from+to)/2;
|
|
|
|
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 double height = door->height;
|
|
const double cenZ = (fpos.z1 + height/2);
|
|
const Point3 pos(cen2.x, cen2.y, cenZ);
|
|
|
|
// div by 2.01 to prevent overlapps and z-fighting
|
|
const float sx = from.getDistance(to) / 2;
|
|
const float sy = thickness_m / 2;
|
|
const float sz = height / 2.01f; // prevent overlaps
|
|
const Point3 size(sx, sy, sz);
|
|
const Point3 rot(0,0,deg);
|
|
|
|
// build
|
|
Cube cube(pos, size, rot, cubeParts);
|
|
|
|
// done
|
|
Obstacle3D res(Obstacle3D::Type::DOOR, door->material);
|
|
res.triangles = cube.getTriangles();
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // FLOORPLAN_3D_DOORS_H
|