changes to Floorplan 3D
This commit is contained in:
@@ -5,59 +5,7 @@
|
||||
#include "Polygon2.h"
|
||||
#include "Triangle3.h"
|
||||
|
||||
class TriangleStrip {
|
||||
|
||||
private:
|
||||
std::vector<Point3> pts;
|
||||
|
||||
public:
|
||||
|
||||
void add(const Point3 p) {
|
||||
pts.push_back(p);
|
||||
}
|
||||
|
||||
void set(const std::vector<Point3>& pts) {
|
||||
this->pts = pts;
|
||||
}
|
||||
|
||||
void toTriangles(std::vector<Triangle3>& trias) const {
|
||||
|
||||
// https://en.wikipedia.org/wiki/Triangle_strip
|
||||
// GL_TRIANGLE_STRIP
|
||||
// Draws a series of triangles (three-sided polygons) using vertices v0, v1, v2, then v2, v1, v3 (note the order), then v2, v3, v4, and so on. The ordering is to ensure that the triangles are all drawn with the same orientation so that the strip can correctly form part of a surface.
|
||||
// For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n. N-2 triangles are drawn.
|
||||
|
||||
|
||||
|
||||
for (size_t j = 2; j < pts.size(); ++j) {
|
||||
|
||||
|
||||
if (j % 2 == 0) {
|
||||
Triangle3 tria(
|
||||
pts[j-2],
|
||||
pts[j-1],
|
||||
pts[j]
|
||||
);
|
||||
trias.push_back(tria);
|
||||
} else {
|
||||
Triangle3 tria(
|
||||
pts[j-1],
|
||||
pts[j-2],
|
||||
pts[j]
|
||||
);
|
||||
trias.push_back(tria);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<Triangle3> toTriangles() const {
|
||||
std::vector<Triangle3> trias;
|
||||
toTriangles(trias);
|
||||
return trias;
|
||||
}
|
||||
|
||||
};
|
||||
#include "TriangleStrip3.h"
|
||||
|
||||
class GPCPolygon2 {
|
||||
|
||||
@@ -168,7 +116,7 @@ public:
|
||||
for (int i = 0; i < res.num_strips; ++i) {
|
||||
gpc_vertex_list lst = res.strip[i];
|
||||
|
||||
TriangleStrip strip;
|
||||
TriangleStrip3 strip;
|
||||
for (int j = 0; j < lst.num_vertices; ++j) {
|
||||
gpc_vertex& v = lst.vertex[j];
|
||||
strip.add(Point3(v.x, v.y, z));
|
||||
|
||||
59
geo/TriangleStrip3.h
Normal file
59
geo/TriangleStrip3.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef TRIANGLESTRIP3_H
|
||||
#define TRIANGLESTRIP3_H
|
||||
|
||||
#include <vector>
|
||||
#include "Point3.h"
|
||||
#include "Triangle3.h"
|
||||
|
||||
class TriangleStrip3 {
|
||||
|
||||
private:
|
||||
std::vector<Point3> pts;
|
||||
|
||||
public:
|
||||
|
||||
void add(const Point3 p) {
|
||||
pts.push_back(p);
|
||||
}
|
||||
|
||||
void set(const std::vector<Point3>& pts) {
|
||||
this->pts = pts;
|
||||
}
|
||||
|
||||
void toTriangles(std::vector<Triangle3>& trias) const {
|
||||
|
||||
// https://en.wikipedia.org/wiki/Triangle_strip
|
||||
// GL_TRIANGLE_STRIP
|
||||
// Draws a series of triangles (three-sided polygons) using vertices v0, v1, v2, then v2, v1, v3 (note the order), then v2, v3, v4, and so on. The ordering is to ensure that the triangles are all drawn with the same orientation so that the strip can correctly form part of a surface.
|
||||
// For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n. N-2 triangles are drawn.
|
||||
|
||||
for (size_t j = 2; j < pts.size(); ++j) {
|
||||
|
||||
if (j % 2 == 0) {
|
||||
Triangle3 tria(
|
||||
pts[j-2],
|
||||
pts[j-1],
|
||||
pts[j]
|
||||
);
|
||||
trias.push_back(tria);
|
||||
} else {
|
||||
Triangle3 tria(
|
||||
pts[j-1],
|
||||
pts[j-2],
|
||||
pts[j]
|
||||
);
|
||||
trias.push_back(tria);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<Triangle3> toTriangles() const {
|
||||
std::vector<Triangle3> trias;
|
||||
toTriangles(trias);
|
||||
return trias;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // TRIANGLESTRIP3_H
|
||||
Reference in New Issue
Block a user