158 lines
3.0 KiB
C++
158 lines
3.0 KiB
C++
#ifndef MV3DELEMENTFLOOROBSTACLEWALL_H
|
|
#define MV3DELEMENTFLOOROBSTACLEWALL_H
|
|
|
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
|
#include <Indoor/math/Math.h>
|
|
|
|
#include "MV3DElement.h"
|
|
|
|
|
|
|
|
class MV3DElementFloorObstacleWall : public MV3DElement {
|
|
|
|
Floorplan::Floor* f;
|
|
Floorplan::FloorObstacleLine* fo;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
MV3DElementFloorObstacleWall(Floorplan::Floor* f, Floorplan::FloorObstacleLine* fo) : f(f), fo(fo) {
|
|
;
|
|
}
|
|
|
|
protected:
|
|
|
|
|
|
|
|
struct Wall {
|
|
|
|
Point2 from;
|
|
Point2 to;
|
|
float atHeight;
|
|
float height;
|
|
|
|
Wall(const Point2 from, const Point2 to, float atHeight, float height) :
|
|
from(from), to(to), atHeight(atHeight), height(height) {;}
|
|
|
|
void paintGL() {
|
|
|
|
float y1 = atHeight;
|
|
float y2 = atHeight + height;
|
|
|
|
// polygon edges
|
|
Point3 p1 = Point3(from.x, y1, from.y);
|
|
Point3 p2 = Point3(to.x, y1, to.y);
|
|
Point3 p3 = Point3(to.x, y2, to.y);
|
|
Point3 p4 = Point3(from.x, y2, from.y);
|
|
|
|
// calculate normal
|
|
// Point3 v1 = p2-p1;
|
|
// Point3 v2 = p3-p1;
|
|
// Point3 n = cross(v1, v2);
|
|
// n/=n.length();
|
|
Point3 n = Math::normal(p2-p1, p3-p1);
|
|
|
|
// align normals to virtual viewport
|
|
Point3 view(99,99,99);
|
|
if ((view-n).length() > (view+n).length()) {n = -n;}
|
|
|
|
// fill the wall
|
|
glColor3f(0.75, 0.75, 0.75);
|
|
glDisable(GL_CULL_FACE);
|
|
glBegin(GL_QUADS);
|
|
glNormal3f(n.x, n.y, n.z);
|
|
glVertex3f(p1.x, p1.y, p1.z);
|
|
glVertex3f(p2.x, p2.y, p2.z);
|
|
glVertex3f(p3.x, p3.y, p3.z);
|
|
glVertex3f(p4.x, p4.y, p4.z);
|
|
glEnd();
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct Handrail {
|
|
|
|
Point2 from;
|
|
Point2 to;
|
|
float atHeight;
|
|
float height;
|
|
|
|
Handrail(const Point2 from, const Point2 to, float atHeight, float height) :
|
|
from(from), to(to), atHeight(atHeight), height(height) {;}
|
|
|
|
void paintGL() {
|
|
|
|
float y1 = atHeight;
|
|
float y2 = atHeight + height;
|
|
|
|
// polygon edges
|
|
Point3 p1 = Point3(from.x, y1, from.y);
|
|
Point3 p2 = Point3(to.x, y1, to.y);
|
|
|
|
Point3 p3 = Point3(from.x, y2, from.y);
|
|
Point3 p4 = Point3(to.x, y2, to.y);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
glBegin(GL_LINES);
|
|
|
|
glColor3f(1,1,1);
|
|
|
|
// top
|
|
glVertex3f(p3.x, p3.y, p3.z);
|
|
glVertex3f(p4.x, p4.y, p4.z);
|
|
|
|
// start bar
|
|
glVertex3f(p1.x, p1.y, p1.z);
|
|
glVertex3f(p3.x, p3.y, p3.z);
|
|
|
|
// end bar
|
|
glVertex3f(p2.x, p2.y, p2.z);
|
|
glVertex3f(p4.x, p4.y, p4.z);
|
|
|
|
glColor3f(0.6, 0.6, 0.6);
|
|
|
|
// intermediate bars
|
|
const Point3 d1 = p2-p1;
|
|
const Point3 d2 = p4-p3;
|
|
const int numBars = d2.length() / 1;
|
|
for (int i = 1; i < numBars; ++i) {
|
|
const Point3 s = p1 + d1 * i / numBars;
|
|
const Point3 e = p3 + d2 * i / numBars;
|
|
glVertex3f(s.x, s.y, s.z);
|
|
glVertex3f(e.x, e.y, e.z);
|
|
}
|
|
|
|
glEnd();
|
|
glEnable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/** repaint me */
|
|
void paintGL() override {
|
|
|
|
|
|
|
|
|
|
|
|
if (fo->type == Floorplan::ObstacleType::WALL) {
|
|
|
|
Wall wall(fo->from, fo->to, f->atHeight, f->height);
|
|
wall.paintGL();
|
|
|
|
} else if (fo->type == Floorplan::ObstacleType::HANDRAIL) {
|
|
|
|
Handrail rail(fo->from, fo->to, f->atHeight, 1.0);
|
|
rail.paintGL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // MV3DELEMENTFLOOROBSTACLEWALL_H
|