-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathibounded.cpp
100 lines (82 loc) · 2.17 KB
/
ibounded.cpp
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
#include "ibounded.h"
void swapF(float * f1,float * f2) {
float tmp = *f1;
*f1 = *f2;
*f2 = tmp;
}
void BoundingRect::updateNormals() {
glm::vec3 bottomBackLeft = glm::vec3(
bottom.x,
bottom.y,
bottom.z
);
glm::vec3 bottomBackRight = glm::vec3(
top.x,
bottom.y,
bottom.z
);
glm::vec3 bottomFrontLeft = glm::vec3(
bottom.x,
bottom.y,
top.z
);
glm::vec3 bottomFrontRight = glm::vec3(
top.x,
bottom.y,
top.z
);
glm::vec3 topBackLeft = glm::vec3(
bottom.x,
top.y,
bottom.z
);
glm::vec3 topBackRight = glm::vec3(
top.x,
top.y,
bottom.z
);
glm::vec3 topFrontLeft = glm::vec3(
bottom.x,
top.y,
top.z
);
glm::vec3 topFrontRight = glm::vec3(
top.x,
top.y,
top.z
);
glm::vec3 normalLeft = glm::triangleNormal(bottomFrontLeft,topBackLeft,topFrontLeft);
glm::vec3 normalRight = normalLeft * -1.0f;
glm::vec3 normalBottom = glm::triangleNormal(bottomBackLeft, bottomBackRight, bottomFrontLeft);
glm::vec3 normalTop = normalBottom * -1.0f;
glm::vec3 normalFront = glm::triangleNormal(topFrontLeft,bottomFrontRight,bottomFrontLeft);
glm::vec3 normalBack = normalFront * -1.0f;
normals[0] = normalLeft;
normals[1] = normalRight;
normals[2] = normalBottom;
normals[3] = normalTop;
normals[4] = normalFront;
normals[5] = normalBack;
}
bool IBounded::isWithinBounds(const BoundingRect &rect) const {
BoundingRect boundedRect = getBoundingRect();
if (boundedRect.bottom.x < rect.bottom.x ) {
return false;
}
if (boundedRect.top.x > rect.top.x) {
return false;
}
if (boundedRect.bottom.y < rect.bottom.y ) {
return false;
}
if (boundedRect.top.y > rect.top.y) {
return false;
}
if (boundedRect.bottom.z < rect.bottom.z ) {
return false;
}
if (boundedRect.top.z > rect.top.z) {
return false;
}
return true;
}