-
Notifications
You must be signed in to change notification settings - Fork 0
/
cubes.cpp
67 lines (63 loc) · 1.48 KB
/
cubes.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
#include "cubes.h"
bool inbound(f32 start,f32 end,f32 now){
f32 diff = end -start;
if (diff >0){
if(now <= end && now >= start){
return true;
}
else{
return false;
}
}
else{
if(now <= start && now >= end){
return true;
}
else{
return false;
}
}
}
std::vector<core::vector3df> findCubesOfInterest(Tline line){
std::vector<core::vector3df> cubes;
core::vector3df tracepoint;
core::vector3df cubeofinterest;
core::vector3df direction = line.end - line.start;
direction.normalize();
tracepoint = line.start;
if(direction.getLength() != 0){
while(inbound(line.start.X,line.end.X,tracepoint.X) && inbound(line.start.Y,line.end.Y,tracepoint.Y) && inbound(line.start.Z,line.end.Z,tracepoint.Z)){
cubeofinterest.X = abs(floor(tracepoint.X));
cubeofinterest.Y = abs(floor(tracepoint.Y));
cubeofinterest.Z = abs(floor(tracepoint.Z));
if(cubeofinterest.X< 0){
cubeofinterest.X = 0;
}
if(cubeofinterest.Y<0){
cubeofinterest.Y =0;
}
if(cubeofinterest.Z<0){
cubeofinterest.Z =0;
}
if(cubeofinterest.X>= numbox){
cubeofinterest.X = numbox -1;
}
if(cubeofinterest.Y>= numbox){
cubeofinterest.Y =numbox-1;
}
if(cubeofinterest.Z>= numbox){
cubeofinterest.Z =numbox-1;
}
tracepoint = tracepoint + 0.5*direction*Boxsize;
if(!cubes.empty()){
if(!cubes.back().equals(cubeofinterest)){
cubes.push_back(cubeofinterest);
}
}
else{
cubes.push_back(cubeofinterest);
}
}
}
return cubes;
}