This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/3D/MV3DElementFloorObstacleWall.h
root e5e19779d5 worked on android port
opengl1 -> es
2018-01-31 17:15:11 +01:00

170 lines
3.6 KiB
C++

#ifndef MV3DELEMENTFLOOROBSTACLEWALL_H
#define MV3DELEMENTFLOOROBSTACLEWALL_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/math/Math.h>
#include "misc/Cube.h"
#include "misc/Window.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 thickness_m;
Floorplan::Material mat;
float atHeight;
float height;
Wall(const Point2 from, const Point2 to, const float thickness_m, const Floorplan::Material mat, float atHeight, float height) :
from(from), to(to), thickness_m(thickness_m), mat(mat), atHeight(atHeight), height(height) {;}
void render(const RenderSettings& rs) {
const float rad = -std::atan2(to.y - from.y, to.x - from.x);
const float deg = rad * 180 / M_PI;
//const Point2 dir = (to - from).normalized();
//const Point2 dirPerp = dir.perpendicular();
//const float w = 0.1;
const Point2 cen2 = (from+to)/2;
const Point3 pos(cen2.x, cen2.y, atHeight + height/2);
// div by 2.01 to prevent overlapps and z-fi
const float sx = from.getDistance(to) / 2.02f;
const float sy = thickness_m / 2.02f;
const float sz = height / 2.02f; // prevent overlaps
const Point3 size(sx, sy, sz);
const Point3 rot(0,0,deg);
// build
Cube cube(pos, size, rot);
if (mat == Floorplan::Material::CONCRETE) {
cube.setColor(0.5, 0.5, 0.5);
} else {
cube.setColor(0.75, 0.75, 0.75);
}
cube.render(rs);
}
};
struct Handrail : public Renderable3D {
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 render(const RenderSettings& rs) override {
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);
/*
TODO_GL
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
glColor3f(0.9, 0.9, 0.9);
// 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 render(const RenderSettings& rs) override {
if (fo->material == Floorplan::Material::GLASS) {
Window win(fo->from, fo->to, f->atHeight, f->height);
win.render(rs);
} else if (fo->type == Floorplan::ObstacleType::WALL) {
Wall wall(fo->from, fo->to, fo->thickness_m, fo->material, f->atHeight, f->height);
wall.render(rs);
} else if (fo->type == Floorplan::ObstacleType::HANDRAIL) {
Handrail rail(fo->from, fo->to, f->atHeight, 1.0);
rail.render(rs);
}
}
bool isTransparent() const override {
return fo->material == Floorplan::Material::GLASS;
}
};
#endif // MV3DELEMENTFLOOROBSTACLEWALL_H