118 lines
3.0 KiB
C++
118 lines
3.0 KiB
C++
#ifndef MV3DELEMENTSTAIR_H
|
|
#define MV3DELEMENTSTAIR_H
|
|
|
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
|
|
|
#include "misc/Cube.h"
|
|
#include "MV3DElement.h"
|
|
#include "misc/Shader.h"
|
|
|
|
class MV3DElementStair : public MV3DElement {
|
|
|
|
Floorplan::Floor* floor;
|
|
Floorplan::Stair* stair;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
MV3DElementStair(Floorplan::Floor* floor, Floorplan::Stair* stair) : floor(floor), stair(stair) {
|
|
;
|
|
}
|
|
|
|
protected:
|
|
|
|
|
|
/** repaint me */
|
|
void render(const RenderSettings& rs) override {
|
|
|
|
//glDisable(GL_CULL_FACE);
|
|
|
|
|
|
std::vector<float> vertices;
|
|
std::vector<float> normals;
|
|
|
|
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
|
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
|
|
|
for (int i = 0; i < (int) parts.size(); ++i) {
|
|
|
|
//const Floorplan::StairPart& part = parts[i];
|
|
const Floorplan::Quad3& quad = quads[i];
|
|
|
|
//const Floorplan::Quad3 quad = part.getQuad(floor);
|
|
const Point3 p1 = quad.p2-quad.p1;
|
|
const Point3 p2 = quad.p4-quad.p1;
|
|
|
|
Point3 n = Math::normal(p1,p2);
|
|
if (n.z < 0) {n = -n;}
|
|
|
|
vertices.insert(vertices.end(), {quad.p1.x, quad.p1.y, quad.p1.z});
|
|
vertices.insert(vertices.end(), {quad.p2.x, quad.p2.y, quad.p2.z});
|
|
vertices.insert(vertices.end(), {quad.p3.x, quad.p3.y, quad.p3.z});
|
|
|
|
vertices.insert(vertices.end(), {quad.p3.x, quad.p3.y, quad.p3.z});
|
|
vertices.insert(vertices.end(), {quad.p4.x, quad.p4.y, quad.p4.z});
|
|
vertices.insert(vertices.end(), {quad.p1.x, quad.p1.y, quad.p1.z});
|
|
|
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
|
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
normals.insert(normals.end(), {n.x, n.y, n.z});
|
|
|
|
}
|
|
|
|
rs.shader->bind();
|
|
rs.shader->setModelMatrix(QMatrix4x4());
|
|
rs.shader->setColor(1.0, 0.55, 0.55);
|
|
rs.shader->setVertices(vertices.data());
|
|
rs.shader->setNormals(normals.data());
|
|
glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3);
|
|
rs.shader->unsetVertices();
|
|
rs.shader->unsetNormals();
|
|
rs.shader->release();
|
|
|
|
/*
|
|
TODO_GL
|
|
//glColor3f(1.0, 0.55, 0.55);
|
|
glColor3f(0.3, 0.3, 0.3);
|
|
glBegin(GL_QUADS);
|
|
|
|
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
|
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
|
|
|
for (int i = 0; i < (int) parts.size(); ++i) {
|
|
|
|
//const Floorplan::StairPart& part = parts[i];
|
|
const Floorplan::Quad3& quad = quads[i];
|
|
|
|
//const Floorplan::Quad3 quad = part.getQuad(floor);
|
|
const Point3 p1 = quad.p2-quad.p1;
|
|
const Point3 p2 = quad.p4-quad.p1;
|
|
|
|
Point3 n = Math::normal(p1,p2);
|
|
if (n.z < 0) {n = -n;}
|
|
|
|
glNormal3f(n.x, n.z, n.z);
|
|
glVertex3f(quad.p1.x, quad.p1.z, quad.p1.y);
|
|
glVertex3f(quad.p2.x, quad.p2.z, quad.p2.y);
|
|
glVertex3f(quad.p3.x, quad.p3.z, quad.p3.y);
|
|
glVertex3f(quad.p4.x, quad.p4.z, quad.p4.y);
|
|
|
|
}
|
|
glEnd();
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
*/
|
|
}
|
|
|
|
bool isTransparent() const override {
|
|
return false;
|
|
}
|
|
|
|
};
|
|
|
|
#endif // MV3DELEMENTSTAIR_H
|