-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtriangle.cpp
More file actions
116 lines (91 loc) · 2.29 KB
/
triangle.cpp
File metadata and controls
116 lines (91 loc) · 2.29 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "triangle.hpp"
Triangle::Triangle() {
a = Vector3(0,0,0);
b = Vector3(0,0,0);
c = Vector3(0,0,0);
}
Triangle::Triangle(Vector3& _a, Vector3& _b, Vector3& _c, const SDL_Color& _color) {
a = _a;
b = _b;
c = _c;
color = _color;
}
Triangle::Triangle(const Triangle& tri) {
Vector3 _a(tri.a.getX(), tri.a.getY(), tri.a.getZ());
Vector3 _b(tri.b.getX(), tri.b.getY(), tri.b.getZ());
Vector3 _c(tri.c.getX(), tri.c.getY(), tri.c.getZ());
a = _a;
b = _b;
c = _c;
color = tri.color;
}
Vector3& Triangle::getA() {
return a;
}
Vector3& Triangle::getB(){
return b;
}
Vector3& Triangle::getC() {
return c;
}
SDL_Color& Triangle::getColor() {
return color;
}
void Triangle::setA(const Vector3& _a){
a = _a;
}
void Triangle::setB(const Vector3& _b){
b = _b;
}
void Triangle::setC(const Vector3& _c){
c = _c;
}
void Triangle::setColor(const SDL_Color& _color){
color = _color;
}
Vector3 Triangle::getCenterThirdSide(){
float x = (a.getX() + c.getX()) / 2;
float y = (a.getY() + c.getY()) / 2;
float z = (a.getZ() + c.getZ()) / 2;
return Vector3(x,y,z);
}
void Triangle::operator*= (float scalar){
a *= scalar;
b *= scalar;
c *= scalar;
}
void Triangle::inverseXY(){
a.inverseXY();
b.inverseXY();
c.inverseXY();
}
Triangle Triangle::multiplyByMatrix(const Matrix4& mat){
a = a.multiplyVector3ByMatrix4(mat);
b = b.multiplyVector3ByMatrix4(mat);
c = c.multiplyVector3ByMatrix4(mat);
return *this;
}
void Triangle::operator+= (const Vector3& vec){
a += vec;
b += vec;
c += vec;
}
Triangle Triangle::operator= (const Triangle& tri){
a = tri.a;
b = tri.b;
c = tri.c;
color = tri.color;
return *this;
}
std::ostream& operator<<(std::ostream& st, Triangle& tri){
st << tri.getA() << " // " << tri.getB() << " // " << tri.getC() << std::endl;
return st;
}
void Triangle::scaleToViewAndWindow(int window_width,int window_height){
a+= Vector3(1,1,0);
b+= Vector3(1,1,0);
c+= Vector3(1,1,0);
a = a * Vector3(0.5*((float) window_width),0.5*((float)window_height),1);
b = b * Vector3(0.5*((float) window_width),0.5*((float)window_height),1);
c = c * Vector3(0.5*((float) window_width),0.5*((float)window_height),1);
}