-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperspective.cpp
More file actions
44 lines (37 loc) · 1.41 KB
/
Copy pathperspective.cpp
File metadata and controls
44 lines (37 loc) · 1.41 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
//
// Created by kobedb on 20.05.22.
//
#include "perspective.h"
#include <vector>
using namespace std;
namespace KDBRenderUtils
{
void doProjection(Figure& fig, double d = 1)
{
for(auto& v : fig.vertices) {
v.x = d * v.x / -v.z;
v.y = d * v.y / -v.z;
}
}
std::vector<Line2D> toPerspectiveProjectedLines(const std::vector<Figure>& pFigures, PolarCoord eye, bool eyeCoordTransformationNeeded)
{
vector<Figure> figures = pFigures; // make a local copy of pFigures
vector<Line2D> lines;
for(auto& fig : figures) {
if(eyeCoordTransformationNeeded) applyTransformation(fig, eyePointTransformation(eye));
doProjection(fig);
for(const auto& face : fig.faces) {
for(int i = 0; i < face.point_indexes.size(); i++) {
int p0_i = face.point_indexes[i];
int p1_i = face.point_indexes[(i+1)%face.point_indexes.size()]; //This loops around to 0, to draw a line between the first and the last vertex
const Vector3D& p0 = fig.vertices[p0_i];
const Vector3D& p1 = fig.vertices[p1_i];
Point2D projP0 = {p0.x, p0.y};
Point2D projP1 = {p1.x, p1.y};
lines.push_back(Line2D{projP0, projP1, fig.color, p0.z, p1.z});
}
}
}
return lines;
}
}