-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCrossSection.cpp
More file actions
113 lines (98 loc) · 2.78 KB
/
CrossSection.cpp
File metadata and controls
113 lines (98 loc) · 2.78 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
#include "CrossSection.h"
namespace Forth
{
CrossSection::CrossSection(void) : Projector4()
{
}
void CrossSection::InternalProject1(const Buffer4 &source, Visualizer4 *dest)
{
int *t4 = source.indices;
Vector4 *v4 = source.vertices;
// Loop over all point
for (int i = 0; i < source.indiceCount; i += 2)
{
// Do initial check if this edge is really intersect
if (sides[t4[i]] == sides[t4[i + 1]])
continue;
// Intersect
int a = t4[0 + i], b = t4[1 + i];
_temp[0] = CrossInterpolate(viewmodel * v4[a], viewmodel * v4[b]);
// Push to destination
dest->Render(_temp, 1);
}
}
void CrossSection::InternalProject2(const Buffer4 &source, Visualizer4 *dest)
{
int *t4 = source.indices;
Vector4 *v4 = source.vertices;
// Loop over all point
for (int i = 0; i < source.indiceCount; i += 3)
{
// Do initial check if this edge is really intersect
if (IsEqual(sides[t4[i]], sides[t4[i + 1]], sides[t4[i + 2]]))
continue;
// Intersect
int iter = 0, a, b;
for (int j = 0; j < 3; j++)
{
if (sides[a = t4[_leftEdges[j] + i]] ^ sides[b = t4[_rightEdges[j] + i]])
{
_temp[iter++] = CrossInterpolate(viewmodel * v4[a], viewmodel * v4[b]);
}
}
// Push to destination
dest->Render(_temp, iter);
}
}
void CrossSection::InternalProject3(const Buffer4 &source, Visualizer4 *dest)
{
int *t4 = source.indices;
// Loop over all point
for (int i = 0; i < source.indiceCount; i += 4)
{
// Do initial check if this edge is really intersect
if (IsEqual(sides[t4[i]], sides[t4[i + 1]], sides[t4[i + 2]], sides[t4[i + 3]]))
continue;
// Intersect
int iter = 0, a, b;
for (int j = 0; j < 6; j++)
{
if (sides[a = t4[_leftEdges[j] + i]] ^ sides[b = t4[_rightEdges[j] + i]])
{
_temp[iter++] = CrossInterpolate(vmverts[a], vmverts[b]);
}
}
// Push to destination
dest->Render(_temp, iter);
}
}
void CrossSection::Project(const Buffer4 &source, const Transform4 &transform, Visualizer4 *dest)
{
viewmodel = view * transform;
EnsureCapacity(&sides, 0, &sides_cap, source.verticeCount);
EnsureCapacity(&vmverts, 0, &vmverts_cap, source.verticeCount);
{
// faster than "sides[i] = (viewmodel * source.vertices[i]).w > 0"
/*const Vector4 &vmw = viewmodel.rotation.ew;
float vmwp = -viewmodel.position.w;*/
for (int i = 0; i < source.verticeCount; ++i)
{
sides[i] = (vmverts[i] = viewmodel * source.vertices[i]).w > 0.f/*(Dot(vmw, source.vertices[i]) > vmwp)*/;
}
}
{
switch (source.simplex)
{
case SimplexMode::SM_Line:
InternalProject1(source, dest);
break;
case SimplexMode::SM_Triangle:
InternalProject2(source, dest);
break;
case SimplexMode::SM_Tetrahedron:
InternalProject3(source, dest);
break;
}
}
}
} // namespace Forth