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/floorplan/RenderTriangle.h
2018-10-25 12:23:40 +02:00

142 lines
3.3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef RENDERTRIANGLE_H
#define RENDERTRIANGLE_H
#include <vector>
#include <Indoor/geo/Point3.h>
class RenderTriangle {
struct Vertex{
float x,y,z;
Vertex(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
};
struct Normal {
float x,y,z;
Normal(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
};
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) {;}
};
std::vector<Vertex> vertices;
std::vector<Normal> normals;
std::vector<RGBA> rgba;
public:
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
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.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.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.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.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.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.push_back( Vertex(p1.x, p1.y, p1.z));
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
rgba.push_back( RGBA(r,g,b,a));
rgba.push_back(RGBA(r,g,b,a));
}
void clear() {
vertices.clear();
normals.clear();
rgba.clear();
}
const float* getVertices() const {return (float*) vertices.data();}
const float* getNormals() const {return (float*) normals.data();}
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;
}
};
#endif // RENDERTRIANGLE_H