-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigure.cpp
More file actions
45 lines (40 loc) · 1.24 KB
/
Copy pathFigure.cpp
File metadata and controls
45 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Created by kobedb on 20.05.22.
//
#include "Figure.h"
using namespace std;
namespace KDBRenderUtils
{
void Figure::triangulate() {
vector<Face> triangle_faces;
triangle_faces.reserve(faces.size());
for(const Face& f : faces) {
if(f.point_indexes.size() <= 3) {
triangle_faces.push_back(f);
continue;
}
for(vector<Face>::size_type i = 1; i < f.point_indexes.size()-1; i++) {
triangle_faces.push_back(Face{{f.point_indexes[0], f.point_indexes[i], f.point_indexes[i+1]}});
}
}
faces = triangle_faces;
}
void Figure::addFigure(const Figure& fig)
{
int vertices_offset = vertices.size();
vertices.insert(vertices.begin(), fig.vertices.begin(), fig.vertices.end());
for(const auto& f : fig.faces) {
Face updatedFace;
for(int i : f.point_indexes) {
updatedFace.point_indexes.push_back(i+vertices_offset);
}
faces.push_back(updatedFace);
}
}
void applyTransformation(Figure& fig, const Matrix& m)
{
for(Vector3D& vert : fig.vertices) {
vert = vert * m;
}
}
} // KDBRenderUtils