refactoring
wireframe display worked on 3d-model display
This commit is contained in:
138
mapview/2D/MV2DElementFloorObstacleDoor.cpp
Normal file
138
mapview/2D/MV2DElementFloorObstacleDoor.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
#include "MV2DElementFloorObstacleDoor.h"
|
||||
|
||||
#include "MV2DElement.h"
|
||||
#include "MapViewElementHelper.h"
|
||||
#include "HasMoveableNodes.h"
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <chrono>
|
||||
|
||||
MV2DElementFloorObstacleDoor::MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo) : fo(fo) {
|
||||
;
|
||||
}
|
||||
|
||||
BBox2 MV2DElementFloorObstacleDoor::getBoundingBox() const {
|
||||
BBox2 bbox;
|
||||
bbox.add(fo->from);
|
||||
bbox.add(fo->to);
|
||||
return bbox;
|
||||
}
|
||||
|
||||
ClickDist MV2DElementFloorObstacleDoor::getMinDistanceXY(const Point2 p) const {
|
||||
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p) * 0.95;
|
||||
}
|
||||
|
||||
void MV2DElementFloorObstacleDoor::paint(Painter& p) {
|
||||
|
||||
// selected endpoints?
|
||||
if (hasFocus()) {
|
||||
p.setPenBrush(Qt::NoPen, CFG::SEL_COLOR);
|
||||
if (selectedUserIdx == 0) {p.drawCircle(fo->from);}
|
||||
if (selectedUserIdx == 1) {p.drawCircle(fo->to);}
|
||||
}
|
||||
|
||||
QPen pen;
|
||||
pen.setColor(QColor(0.5,0.5,0.5));
|
||||
pen.setStyle(Qt::PenStyle::DotLine);
|
||||
p.setPenBrush(pen, Qt::NoBrush);
|
||||
|
||||
if (Floorplan::DoorType::SWING == fo->type) {
|
||||
|
||||
// opening indicator
|
||||
const float open = (fo->swap) ? (-M_PI * 0.5) : (+M_PI * 0.5);
|
||||
const float len = (fo->to - fo->from).length();
|
||||
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
|
||||
const float angle2 = angle1 + open;
|
||||
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
|
||||
|
||||
pen.setWidth(2); p.setPen(pen);
|
||||
p.drawLine(fo->from, fo->to);
|
||||
|
||||
pen.setWidth(1); p.setPen(pen);
|
||||
p.drawLine(fo->from, pOpen);
|
||||
p.drawArc(fo->from, len, angle1, open);
|
||||
|
||||
} else if (Floorplan::DoorType::REVOLVING == fo->type) {
|
||||
|
||||
const float angle_rad = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
|
||||
|
||||
// arcs
|
||||
const Point2 cen = (fo->from + fo->to) / 2;
|
||||
const float rad = (fo->to - fo->from).length() / 2;
|
||||
p.drawArc(cen, rad, (40-90)/180.0f*M_PI+angle_rad, 100/180.0f*M_PI);
|
||||
p.drawArc(cen, rad, (180+40-90)/180.0f*M_PI+angle_rad, 100/180.0f*M_PI);
|
||||
|
||||
const int funAngle = (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() / 50) % 360;
|
||||
|
||||
// inner spinner
|
||||
int numDoors = 3;
|
||||
for (int i = 0; i < numDoors; ++i) {
|
||||
const int deg = 360 * i / numDoors + angle_rad*180.0f/M_PI + funAngle;
|
||||
const float sx = std::cos(deg / 180.0f * M_PI);
|
||||
const float sy = std::sin(deg / 180.0f * M_PI);
|
||||
const Point2 dst = cen + Point2(sx,sy) * rad;
|
||||
p.drawLine(cen, dst);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// available endpoints
|
||||
if (hasFocus()) {
|
||||
p.setPenBrush(Qt::black, Qt::NoBrush);
|
||||
p.drawCircle(fo->from);
|
||||
p.drawCircle(fo->to);
|
||||
}
|
||||
|
||||
// obstacle length
|
||||
if (hasFocus()) {
|
||||
p.setPenBrush(Qt::black, Qt::NoBrush);
|
||||
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MV2DElementFloorObstacleDoor::onFocus() {
|
||||
;
|
||||
}
|
||||
|
||||
void MV2DElementFloorObstacleDoor::onUnfocus() {
|
||||
selectedUserIdx = -1; // clear selection
|
||||
}
|
||||
|
||||
void MV2DElementFloorObstacleDoor::mousePressed(MapView2D* v, const Point2 p) {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
void MV2DElementFloorObstacleDoor::mouseMove(MapView2D* v, const Point2 p) {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
void MV2DElementFloorObstacleDoor::mouseReleased(MapView2D* v, const Point2 p) {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
std::vector<MoveableNode> MV2DElementFloorObstacleDoor::getMoveableNodes() const {
|
||||
std::vector<MoveableNode> nodes = {
|
||||
MoveableNode(0, fo->from),
|
||||
MoveableNode(1, fo->to)
|
||||
};
|
||||
return nodes;
|
||||
}
|
||||
|
||||
void MV2DElementFloorObstacleDoor::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
|
||||
switch (userIdx) {
|
||||
case 0: fo->from = newPos; break;
|
||||
case 1: fo->to = newPos; break;
|
||||
}
|
||||
emit v->onElementChange(this);
|
||||
}
|
||||
|
||||
bool MV2DElementFloorObstacleDoor::keyPressEvent(MapView2D* v, QKeyEvent *e) {
|
||||
(void) v;
|
||||
(void) e;
|
||||
return false;
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
#define MV2DELEMENTFLOOROBSTACLEDOOR_H
|
||||
|
||||
#include "MV2DElement.h"
|
||||
#include "MapViewElementHelper.h"
|
||||
#include "HasMoveableNodes.h"
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
@@ -16,136 +15,36 @@ private:
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo) : fo(fo) {;}
|
||||
MV2DElementFloorObstacleDoor(Floorplan::FloorObstacleDoor* fo);
|
||||
|
||||
/** get the element's 3D bounding box */
|
||||
BBox2 getBoundingBox() const override {
|
||||
BBox2 bbox;
|
||||
bbox.add(fo->from);
|
||||
bbox.add(fo->to);
|
||||
return bbox;
|
||||
}
|
||||
BBox2 getBoundingBox() const override;
|
||||
|
||||
/** get the element's minimal distance (nearest whatsoever) to the given point */
|
||||
ClickDist getMinDistanceXY(const Point2 p) const override {
|
||||
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p);
|
||||
}
|
||||
ClickDist getMinDistanceXY(const Point2 p) const override;
|
||||
|
||||
|
||||
|
||||
/** repaint me */
|
||||
void paint(Painter& p) override {
|
||||
void paint(Painter& p) override;
|
||||
|
||||
// selected endpoints?
|
||||
if (hasFocus()) {
|
||||
p.setPenBrush(Qt::NoPen, CFG::SEL_COLOR);
|
||||
if (selectedUserIdx == 0) {p.drawCircle(fo->from);}
|
||||
if (selectedUserIdx == 1) {p.drawCircle(fo->to);}
|
||||
}
|
||||
virtual void onFocus() override;
|
||||
|
||||
QPen pen;
|
||||
pen.setColor(QColor(0.5,0.5,0.5));
|
||||
pen.setStyle(Qt::PenStyle::DotLine);
|
||||
p.setPenBrush(pen, Qt::NoBrush);
|
||||
virtual void onUnfocus() override;
|
||||
|
||||
// opening indicator
|
||||
const float open = (fo->swap) ? (-M_PI * 0.5) : (+M_PI * 0.5);
|
||||
const float len = (fo->to - fo->from).length();
|
||||
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
|
||||
const float angle2 = angle1 + open;
|
||||
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
|
||||
virtual void mousePressed(MapView2D* v, const Point2 p) override;
|
||||
|
||||
pen.setWidth(2); p.setPen(pen);
|
||||
p.drawLine(fo->from, fo->to);
|
||||
virtual void mouseMove(MapView2D* v, const Point2 p) override;
|
||||
|
||||
pen.setWidth(1); p.setPen(pen);
|
||||
p.drawLine(fo->from, pOpen);
|
||||
p.drawArc(fo->from, len, angle1, open);
|
||||
|
||||
// available endpoints
|
||||
if (hasFocus()) {
|
||||
p.setPenBrush(Qt::black, Qt::NoBrush);
|
||||
p.drawCircle(fo->from);
|
||||
p.drawCircle(fo->to);
|
||||
}
|
||||
|
||||
// obstacle length
|
||||
if (hasFocus()) {
|
||||
p.setPenBrush(Qt::black, Qt::NoBrush);
|
||||
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
virtual void onFocus() override {
|
||||
;
|
||||
}
|
||||
|
||||
virtual void onUnfocus() override {
|
||||
selectedUserIdx = -1; // clear selection
|
||||
}
|
||||
|
||||
virtual void mousePressed(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
virtual void mouseMove(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
virtual void mouseReleased(MapView2D* v, const Point2 p) override {
|
||||
(void) v;
|
||||
(void) p;
|
||||
}
|
||||
|
||||
/** mouse moved to the given point */
|
||||
// virtual void mouseMove(MapView2D* v, const Point2 _p) override {
|
||||
// (void) v;
|
||||
// if (selPoint == -1) {return;}
|
||||
// const Point2 p = v->getScaler().snap(_p);
|
||||
// if (selPoint == 0) {fo->from.x = p.x; fo->from.y = p.y;}
|
||||
// if (selPoint == 1) {fo->to.x = p.x; fo->to.y = p.y;}
|
||||
// emit v->onElementChange(this);
|
||||
// }
|
||||
|
||||
/** mouse released */
|
||||
// virtual void mouseReleased(MapView2D* v, const Point2 _p) override {
|
||||
// // select a new point on mouse-release (more robust than on mouse-press)
|
||||
// const float t = v->getScaler().sm(CFG::SEL_THRESHOLD_SIZE_PX);
|
||||
// const float l1 = _p.getDistance(fo->from);
|
||||
// const float l2 = _p.getDistance(fo->to);
|
||||
// if (l1 < l2 && l1 <= t) {selPoint = 0;}
|
||||
// else if (l2 < l1 && l2 <= t) {selPoint = 1;}
|
||||
// else {selPoint = -1;}
|
||||
|
||||
// }
|
||||
virtual void mouseReleased(MapView2D* v, const Point2 p) override;
|
||||
|
||||
/** get a list of all nodes that are selectable / moveable */
|
||||
virtual std::vector<MoveableNode> getMoveableNodes() const override {
|
||||
std::vector<MoveableNode> nodes = {
|
||||
MoveableNode(0, fo->from),
|
||||
MoveableNode(1, fo->to)
|
||||
};
|
||||
return nodes;
|
||||
}
|
||||
virtual std::vector<MoveableNode> getMoveableNodes() const override;
|
||||
|
||||
/** the given node was moved */
|
||||
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
|
||||
switch (userIdx) {
|
||||
case 0: fo->from = newPos; break;
|
||||
case 1: fo->to = newPos; break;
|
||||
}
|
||||
emit v->onElementChange(this);
|
||||
}
|
||||
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override;
|
||||
|
||||
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
|
||||
(void) v;
|
||||
(void) e;
|
||||
return false;
|
||||
}
|
||||
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
const ClickDist dst = MapElementHelper::getLineDistanceXY(p1, p2, p);
|
||||
if (dst < min) {min = dst;}
|
||||
}
|
||||
return min;
|
||||
return min * 1.1; // penalty.. outlines are everywhere.. reduce priority
|
||||
}
|
||||
|
||||
virtual void onFocus() override {
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
// distance from endpoints
|
||||
// (direct) distance from endpoints
|
||||
const ClickDist d1(p1.getDistance(dst), ClickDistType::DIRECT);
|
||||
const ClickDist d2(p2.getDistance(dst), ClickDistType::DIRECT);
|
||||
|
||||
|
||||
@@ -56,6 +56,15 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
emit update();
|
||||
});
|
||||
|
||||
QPushButton* btnWireframe = new QPushButton(UIHelper::getIcon("wireframe"), "", this);
|
||||
btnWireframe->setCheckable(true);
|
||||
btnWireframe->setStyleSheet(style);
|
||||
btnWireframe->setGeometry(16, 16+8+32+8+32, 32, 32);
|
||||
connect(btnWireframe, &QPushButton::clicked, [this] () {
|
||||
useWireframe = !useWireframe;
|
||||
emit update();
|
||||
});
|
||||
|
||||
QPushButton* btnGrid = new QPushButton(UIHelper::getIcon("grid"), "", this);
|
||||
btnGrid->setCheckable(true);
|
||||
btnGrid->setChecked(false);
|
||||
@@ -74,6 +83,7 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
emit onShow3DNavMesh(btnNavMesh->isChecked());
|
||||
});
|
||||
|
||||
|
||||
// android
|
||||
setAttribute(Qt::WA_AcceptTouchEvents, true);
|
||||
grabGesture(Qt::PanGesture);
|
||||
@@ -81,7 +91,7 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
|
||||
auto format = QSurfaceFormat();
|
||||
//format.setVersion(4,3);
|
||||
format.setSamples(4);
|
||||
format.setSamples(2);
|
||||
//format.setProfile(QSurfaceFormat::CoreProfile);
|
||||
|
||||
setFormat(format);
|
||||
@@ -298,8 +308,8 @@ void MapView3D::draw() {
|
||||
rs.shader->setViewMatrix(V);
|
||||
rs.shader->setProjectionMatrix(P);
|
||||
|
||||
if (floorplanRenderer && floorplanRendererModel) {
|
||||
floorplanRenderer->renderSolid(rs, floorplanRendererModel->getTriaSolid() );
|
||||
if (showFloorplan && floorplanRendererModel) {
|
||||
floorplanRenderer->renderSolid(rs, floorplanRendererModel->getTriaSolid(), useWireframe );
|
||||
}
|
||||
|
||||
// // solid floorplan parts
|
||||
@@ -330,8 +340,8 @@ void MapView3D::draw() {
|
||||
|
||||
// }
|
||||
|
||||
if (floorplanRenderer && floorplanRendererModel) {
|
||||
floorplanRenderer->renderTransp(rs, floorplanRendererModel->getTriaTransp() );
|
||||
if (showFloorplan && floorplanRendererModel) {
|
||||
floorplanRenderer->renderTransp(rs, floorplanRendererModel->getTriaTransp(), useWireframe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class MapView3D : public QOpenGLWidget {
|
||||
Q_OBJECT
|
||||
|
||||
bool usePerspectiveProjection = false;
|
||||
bool useWireframe = false;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -27,25 +27,34 @@ public:
|
||||
}
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void renderSolid(const RenderSettings& rs, const RenderTriangle& rt) {
|
||||
void renderSolid(const RenderSettings& rs, const RenderTriangle& rt, bool wireframe) {
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(rt.getVertices().data());
|
||||
rs.shader->setNormals(rt.getNormals().data());
|
||||
rs.shader->setVertexColor(rt.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.getVertices().size()/3);
|
||||
rs.shader->setVertices(rt.getVertices());
|
||||
rs.shader->setNormals(rt.getNormals());
|
||||
rs.shader->setVertexColor(rt.getRGBA());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.count());
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
if (wireframe) {
|
||||
RenderTriangle rt2 = rt.toWireframe(false);
|
||||
rs.shader->setColor(0,0,0,128);
|
||||
rs.shader->setVertices(rt2.getVertices());
|
||||
//rs.shader->setVertexColor(rt2.getRGBA());
|
||||
glDrawArrays(GL_LINES, 0, rt2.count());
|
||||
rs.shader->unsetVertices();
|
||||
//rs.shader->unsetVertexColor();
|
||||
}
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void renderTransp(const RenderSettings& rs, const RenderTriangle& rt) {
|
||||
void renderTransp(const RenderSettings& rs, const RenderTriangle& rt, bool wireframe) {
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -53,14 +62,24 @@ public:
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(rt.getVertices().data());
|
||||
rs.shader->setNormals(rt.getNormals().data());
|
||||
rs.shader->setVertexColor(rt.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.getVertices().size()/3);
|
||||
rs.shader->setVertices(rt.getVertices());
|
||||
rs.shader->setNormals(rt.getNormals());
|
||||
rs.shader->setVertexColor(rt.getRGBA());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.count());
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
if (wireframe) {
|
||||
RenderTriangle rt2 = rt.toWireframe(false);
|
||||
rs.shader->setColor(0,0,0,128);
|
||||
rs.shader->setVertices(rt2.getVertices());
|
||||
//rs.shader->setVertexColor(rt2.getRGBA());
|
||||
glDrawArrays(GL_LINES, 0, rt2.count());
|
||||
rs.shader->unsetVertices();
|
||||
//rs.shader->unsetVertexColor();
|
||||
}
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
@@ -7,56 +7,71 @@
|
||||
|
||||
class RenderTriangle {
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> rgba;
|
||||
struct Vertex{
|
||||
float x,y,z;
|
||||
Vertex(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Normal {
|
||||
float x,y,z;
|
||||
Normal(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||
} __attribute__((packed));
|
||||
|
||||
struct RGBA {
|
||||
float r,g,b,a;
|
||||
RGBA(const float r, const float g, const float b, const float a) : r(r), g(g), b(b), a(a) {;}
|
||||
} __attribute__((packed));
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<Normal> normals;
|
||||
std::vector<RGBA> rgba;
|
||||
|
||||
public:
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
vertices.push_back(Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
vertices.push_back(Vertex(p3.x, p3.y, p3.z));
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
vertices.push_back(Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
vertices.push_back(Vertex(p3.x, p3.y, p3.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.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
vertices.push_back(Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
vertices.push_back(Vertex(p3.x, p3.y, p3.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.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void addLine(Point3 p1, Point3 p2, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.push_back( Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.push_back( RGBA(r,g,b,a));
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
|
||||
}
|
||||
|
||||
@@ -66,11 +81,49 @@ public:
|
||||
rgba.clear();
|
||||
}
|
||||
|
||||
const std::vector<float>& getVertices() const {return vertices;}
|
||||
const float* getVertices() const {return (float*) vertices.data();}
|
||||
|
||||
const std::vector<float>& getNormals() const {return normals;}
|
||||
const float* getNormals() const {return (float*) normals.data();}
|
||||
|
||||
const std::vector<float>& getRGBA() const {return rgba;}
|
||||
const float* getRGBA() const {return (float*) rgba.data();}
|
||||
|
||||
size_t count() const {return vertices.size();}
|
||||
|
||||
RenderTriangle toWireframe(const bool withVertexColors) const {
|
||||
|
||||
RenderTriangle res;
|
||||
|
||||
for (size_t i = 0; i < vertices.size(); i += 3) {
|
||||
|
||||
res.vertices.push_back(vertices[i+0]);
|
||||
res.vertices.push_back(vertices[i+1]);
|
||||
|
||||
res.vertices.push_back(vertices[i+1]);
|
||||
res.vertices.push_back(vertices[i+2]);
|
||||
|
||||
res.vertices.push_back(vertices[i+2]);
|
||||
res.vertices.push_back(vertices[i+0]);
|
||||
|
||||
}
|
||||
|
||||
if (withVertexColors) {
|
||||
for (size_t i = 0; i < rgba.size(); i += 3) {
|
||||
|
||||
res.rgba.push_back(rgba[i+0]);
|
||||
res.rgba.push_back(rgba[i+1]);
|
||||
|
||||
res.rgba.push_back(rgba[i+1]);
|
||||
res.rgba.push_back(rgba[i+2]);
|
||||
|
||||
res.rgba.push_back(rgba[i+2]);
|
||||
res.rgba.push_back(rgba[i+0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ enum class ParamType {
|
||||
FILE,
|
||||
POINT2,
|
||||
POINT3,
|
||||
ENUM,
|
||||
};
|
||||
|
||||
class ParamValue {
|
||||
@@ -85,13 +86,22 @@ struct Param {
|
||||
/** read-only parameter? */
|
||||
bool readOnly;
|
||||
|
||||
std::vector<std::string> enumValues;
|
||||
|
||||
|
||||
/** ctor */
|
||||
Param(const std::string& name, const ParamType type, const bool readOnly = false) : name(name), type(type), readOnly(readOnly) {;}
|
||||
|
||||
/** ctor */
|
||||
Param(const std::string& name, const ParamType type, const std::vector<std::string>& enumValues) : name(name), type(type), readOnly(false), enumValues(enumValues) {;}
|
||||
|
||||
|
||||
/** special parameter */
|
||||
static Param getNA() { return Param("", ParamType::NOT_AVAILABLE); }
|
||||
|
||||
/** get all supported enum values */
|
||||
const std::vector<std::string>& getEnumValues() const {return enumValues;}
|
||||
|
||||
};
|
||||
|
||||
/** free parameters */
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
/** get the number of parameters */
|
||||
int getNumParams() const override {
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
/** get the description of the idx-th parameter */
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
case 0: return Param("width", ParamType::FLOAT, true);
|
||||
case 1: return Param("height", ParamType::FLOAT);
|
||||
case 2: return Param("swap", ParamType::BOOL);
|
||||
case 3: return Param("type", ParamType::ENUM, {"unknown", "swing", "double swing", "slide", "double slide", "revolving"});
|
||||
default: throw Exception("out of bounds");
|
||||
}
|
||||
}
|
||||
@@ -65,6 +66,7 @@ public:
|
||||
case 0: return fo->getSize();
|
||||
case 1: return fo->height;
|
||||
case 2: return fo->swap;
|
||||
case 3: return (int) fo->type;
|
||||
default: throw Exception("out of bounds");
|
||||
}
|
||||
}
|
||||
@@ -75,6 +77,7 @@ public:
|
||||
case 0: break;
|
||||
case 1: fo->height = val.toFloat(); break;
|
||||
case 2: fo->swap = val.toBool(); break;
|
||||
case 3: fo->type = (Floorplan::DoorType) val.toInt(); break;
|
||||
default: throw Exception("out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user