70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
#ifndef WALLSVIACUBE_H
|
|
#define WALLSVIACUBE_H
|
|
|
|
#include "Walls.h"
|
|
#include "FloorPos.h"
|
|
#include "Cube.h"
|
|
|
|
namespace Ray3D {
|
|
|
|
/**
|
|
* simply use one 3D cube per wall
|
|
* if walls intersect in the 2D view, cubes will also intersect
|
|
*/
|
|
class WallsViaCubes : public Walls {
|
|
|
|
Cube::Part cubeParts = (Cube::Part) 63; // leftright,topbottom,rearfront
|
|
|
|
std::vector<Obstacle3D> vec;
|
|
|
|
public:
|
|
|
|
void clear() override {
|
|
vec.clear();
|
|
}
|
|
|
|
void add(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) override {
|
|
|
|
FloorPos fpos(f);
|
|
|
|
const float thickness_m = fol->thickness_m;
|
|
const Point2 from = (!aboveDoor) ? (fol->from) : (aboveDoor->from);
|
|
const Point2 to = (!aboveDoor) ? (fol->to) : (aboveDoor->to);
|
|
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 float _height = (fol->height_m > 0) ? (fol->height_m) : (fpos.height); // use either floor's height or user height
|
|
const double height = (!aboveDoor) ? (_height) : (fpos.height - aboveDoor->height);
|
|
const double cenZ = (!aboveDoor) ? (fpos.z1 + height/2) : (fpos.z1 + aboveDoor->height + height/2);// (fpos.z2 - (fpos.height - aboveDoor->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(getType(fol), fol->material);
|
|
res.triangles = cube.getTriangles();
|
|
vec.push_back(res);
|
|
|
|
}
|
|
|
|
const std::vector<Obstacle3D>& get() override {
|
|
return vec;
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // WALLSVIACUBE_H
|