-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
169 lines (112 loc) · 3.53 KB
/
test.c
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "c3dlas.h"
void checklinelineline() {
Ray3 r1 = {
.o = { 0, 0, 3},
.d = { 0, 2, 0},
};
Ray3 r2 = {
.o = { 0, 0, 1},
.d = { 0, 2, 0},
};
Vector3 o1[] = {
{99,99,99},
{99,99,99},
};
int ret;
ret = shortestLineFromRayToRay3p(&r1, &r2, o1);
printf("%s\n", c3dlas_EnumString(ret));
printf(" out: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f\n", o1[0].x, o1[0].y, o1[0].z, o1[1].x, o1[1].y, o1[1].z);
}
void checklinePlaneClip() {
Plane pl = {
{0,0,1}, 1,
};
Vector3 line[] = {
{0,0, -3},
{0,0, -4},
};
Vector3 o1[] = {
{99,99,99},
{99,99,99},
};
Vector3 o2[] = {
{99,99,99},
{99,99,99},
};
int ret, i1, i2;
ret = linePlaneClip3p(line, line+1, &pl, o1, o2, &i1, &i2);
printf("%s\n", c3dlas_EnumString(ret));
printf(" above1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f\n", i1, o1[0].x, o1[0].y, o1[0].z, o1[1].x, o1[1].y, o1[1].z);
printf(" below1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f\n", i2, o2[0].x, o2[0].y, o2[0].z, o2[1].x, o2[1].y, o2[1].z);
}
void checkTriPlaneClip() {
Plane pl = {
{0,0,1}, 1,
};
Vector3 tri1[] = { // intersecting
{ 0,0, 5},
{-3,0,-3}, // l,h
{ 3,0,-3},
};
Vector3 tri11[] = { // intersecting
{-3,0, 3}, // l,h
{ 3,0, 3},
{ 0,0,-5},
};
Vector3 tri2[] = { // entirely above
{3,4,2},
{3,5,3},
{3,6,7},
};
Vector3 tri3[] = {
{-2,0, 1},
{ 3,0, 2},
{ 3,0,-2},
};
Vector3 l[] = {
{3, 3, -4},
{4, 4, 5},
{4, 4, -9},
};
Vector3 o1[] = {
{999,999,999},{999,999,999},{999,999,999},
{999,999,999},{999,999,999},{999,999,999},
{888,888,888},{888,888,888},{888,888,888}
};
Vector3 o2[] = {
{999,999,999},{999,999,999},{999,999,999},
{999,999,999},{999,999,999},{999,999,999},
{888,888,888},{888,888,888},{888,888,888}
};
int ret, i1, i2;
ret = triPlaneClip3p(tri3, &pl, o1, o2, &i1, &i2);
printf("%s\n", c3dlas_EnumString(ret));
printf(" above1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f \n", i1, o1[0].x, o1[0].y, o1[0].z, o1[1].x, o1[1].y, o1[1].z, o1[2].x, o1[2].y, o1[2].z);
printf(" above2 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - %f \n", i1, o1[3].x, o1[3].y, o1[3].z, o1[4].x, o1[4].y, o1[4].z, o1[5].x, o1[5].y, o1[5].z, o1[6].x );
printf(" below1 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f \n", i2, o2[0].x, o2[0].y, o2[0].z, o2[1].x, o2[1].y, o2[1].z, o2[2].x, o2[2].y, o2[2].z);
printf(" below2 %d: % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - % .1f,% .1f,% .1f - %f \n", i2, o2[3].x, o2[3].y, o2[3].z, o2[4].x, o2[4].y, o2[4].z, o2[5].x, o2[5].y, o2[5].z, o2[6].x );
Vector3 n[] = {{999,999,999},{999,999,999},{999,999,999},{999,999,999},{999,999,999},};
vpTriFaceNormal3p(o1, &n[0]);
vpTriFaceNormal3p(o1+3, &n[1]);
vpTriFaceNormal3p(o2, &n[2]);
vpTriFaceNormal3p(o2+3, &n[3]);
vpTriFaceNormal3p(tri3, &n[4]);
printf(" nin: % .2f,% .2f,% .2f\n", n[4].x, n[4].y, n[4].z);
printf(" na1: % .2f,% .2f,% .2f\n", n[0].x, n[0].y, n[0].z);
printf(" na2: % .2f,% .2f,% .2f\n", n[1].x, n[1].y, n[1].z);
printf(" nb1: % .2f,% .2f,% .2f\n", n[2].x, n[2].y, n[2].z);
printf(" nb2: % .2f,% .2f,% .2f\n", n[3].x, n[3].y, n[3].z);
printf(" %f, %f, %f\n", vDot3p(n, n+2), vDot3p(n, n+1), vDot3p(n+2, n+3));
}
int main(int argc, char* argv) {
Matrix m = IDENT_MATRIX;
mOrtho(-2.2, 3.3, 4.4, -5.5, 0.66, 7.7, &m);
float a,b,c,d,e,f;
mOrthoExtractPlanes(&m, &a, &b, &c, &d, &e, &f);
printf("%f,%f,%f,%f,%f,%f\n", a, b,c,d,e,f);
return 0;
}