-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertsel.c
276 lines (241 loc) · 6.22 KB
/
vertsel.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// vertsel.c
#include "qe3.h"
int FindPoint (vec3_t point)
{
int i, j;
for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
{
for (j=0 ; j<3 ; j++)
if (fabs(point[j] - g_qeglobals.d_points[i][j]) > 0.1)
break;
if (j == 3)
return i;
}
VectorCopy (point, g_qeglobals.d_points[g_qeglobals.d_numpoints]);
if (g_qeglobals.d_numpoints < MAX_POINTS-1)
g_qeglobals.d_numpoints++;
return g_qeglobals.d_numpoints-1;
}
int FindEdge (int p1, int p2, face_t *f)
{
int i;
for (i=0 ; i<g_qeglobals.d_numedges ; i++)
if (g_qeglobals.d_edges[i].p1 == p2 && g_qeglobals.d_edges[i].p2 == p1)
{
g_qeglobals.d_edges[i].f2 = f;
return i;
}
g_qeglobals.d_edges[g_qeglobals.d_numedges].p1 = p1;
g_qeglobals.d_edges[g_qeglobals.d_numedges].p2 = p2;
g_qeglobals.d_edges[g_qeglobals.d_numedges].f1 = f;
if (g_qeglobals.d_numedges < MAX_EDGES-1)
g_qeglobals.d_numedges++;
return g_qeglobals.d_numedges-1;
}
void MakeFace (brush_t* b, face_t *f)
//void MakeFace (face_t *f)
{
winding_t *w;
int i;
int pnum[128];
w = Brush_MakeFaceWinding (b, f);
// w = MakeFaceWinding (selected_brushes.next, f);
if (!w)
return;
for (i=0 ; i<w->numpoints ; i++)
pnum[i] = FindPoint (w->points[i]);
for (i=0 ; i<w->numpoints ; i++)
FindEdge (pnum[i], pnum[(i+1)%w->numpoints], f);
free (w);
}
void SetupVertexSelection (void)
{
face_t *f;
brush_t *b;
g_qeglobals.d_numpoints = 0;
g_qeglobals.d_numedges = 0;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
MakeFace (b,f);
}
/* if (!QE_SingleBrush())
return;
b = selected_brushes.next;
for (f=b->brush_faces ; f ; f=f->next)
MakeFace (f);
*/
Sys_UpdateWindows (W_ALL);
}
void SelectFaceEdge (brush_t* b, face_t *f, int p1, int p2)
//void SelectFaceEdge (face_t *f, int p1, int p2)
{
winding_t *w;
int i, j, k;
int pnum[128];
w = Brush_MakeFaceWinding (b, f);
// w = MakeFaceWinding (selected_brushes.next, f);
if (!w)
return;
for (i=0 ; i<w->numpoints ; i++)
pnum[i] = FindPoint (w->points[i]);
for (i=0 ; i<w->numpoints ; i++)
if (pnum[i] == p1 && pnum[(i+1)%w->numpoints] == p2)
{
VectorCopy (g_qeglobals.d_points[pnum[i]], f->planepts[0]);
VectorCopy (g_qeglobals.d_points[pnum[(i+1)%w->numpoints]], f->planepts[1]);
VectorCopy (g_qeglobals.d_points[pnum[(i+2)%w->numpoints]], f->planepts[2]);
for (j=0 ; j<3 ; j++)
{
for (k=0 ; k<3 ; k++)
{
f->planepts[j][k] = floor(f->planepts[j][k]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
}
}
AddPlanept (f->planepts[0]);
AddPlanept (f->planepts[1]);
break;
}
if (i == w->numpoints)
Sys_Printf ("Select face edge failed\n");
free (w);
}
/*
void SelectVertex (int p1)
{
brush_t *b;
winding_t *w;
int i, j, k;
face_t *f;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
{
w = Brush_MakeFaceWinding (b, f);
if (!w)
continue;
for (i=0 ; i<w->numpoints ; i++)
{
if (FindPoint (w->points[i]) == p1)
{
VectorCopy (w->points[(i+w->numpoints-1)%w->numpoints], f->planepts[0]);
VectorCopy (w->points[i], f->planepts[1]);
VectorCopy (w->points[(i+1)%w->numpoints], f->planepts[2]);
for (j=0 ; j<3 ; j++)
{
for (k=0 ; k<3 ; k++)
{
;//f->planepts[j][k] = floor(f->planepts[j][k]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
}
}
AddPlanept (f->planepts[1]);
//MessageBeep(-1);
break;
}
}
free (w);
}
}
// b = selected_brushes.next;
// for (f=b->brush_faces ; f ; f=f->next)
// {
// w = MakeFaceWinding (b, f);
// if (!w)
// continue;
// for (i=0 ; i<w->numpoints ; i++)
// {
// if (FindPoint (w->points[i]) == p1)
// {
// VectorCopy (w->points[(i+w->numpoints-1)%w->numpoints], f->planepts[0]);
// VectorCopy (w->points[i], f->planepts[1]);
// VectorCopy (w->points[(i+1)%w->numpoints], f->planepts[2]);
// for (j=0 ; j<3 ; j++)
// {
// for (k=0 ; k<3 ; k++)
// {
// f->planepts[j][k] = floor(f->planepts[j][k]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
// }
// }
//
// AddPlanept (f->planepts[1]);
// break;
// }
// }
// free (w);
// }
//
}
*/
void SelectEdgeByRay (vec3_t org, vec3_t dir)
{
int i, j, besti;
float d, bestd;
vec3_t mid, temp;
pedge_t *e;
brush_t* b;
// find the edge closest to the ray
besti = -1;
bestd = 8;
for (i=0 ; i<g_qeglobals.d_numedges ; i++)
{
for (j=0 ; j<3 ; j++)
mid[j] = 0.5*(g_qeglobals.d_points[g_qeglobals.d_edges[i].p1][j] + g_qeglobals.d_points[g_qeglobals.d_edges[i].p2][j]);
VectorSubtract (mid, org, temp);
d = DotProduct (temp, dir);
VectorMA (org, d, dir, temp);
VectorSubtract (mid, temp, temp);
d = VectorLength (temp);
if (d < bestd)
{
bestd = d;
besti = i;
}
}
if (besti == -1)
{
Sys_Printf ("Click didn't hit an edge\n");
return;
}
Sys_Printf ("Hit edge\n");
// make the two faces that border the edge use the two edge points
// as primary drag points
g_qeglobals.d_num_move_points = 0;
e = &g_qeglobals.d_edges[besti];
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
SelectFaceEdge (b, e->f1, e->p1, e->p2);
SelectFaceEdge (b, e->f2, e->p2, e->p1);
}
// SelectFaceEdge (e->f1, e->p1, e->p2);
// SelectFaceEdge (e->f2, e->p2, e->p1);
}
void SelectVertexByRay (vec3_t org, vec3_t dir)
{
int i, besti;
float d, bestd;
vec3_t temp;
// find the point closest to the ray
besti = -1;
bestd = 8;
for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
{
VectorSubtract (g_qeglobals.d_points[i], org, temp);
d = DotProduct (temp, dir);
VectorMA (org, d, dir, temp);
VectorSubtract (g_qeglobals.d_points[i], temp, temp);
d = VectorLength (temp);
if (d < bestd)
{
bestd = d;
besti = i;
}
}
if (besti == -1)
{
Sys_Printf ("Click didn't hit a vertex\n");
return;
}
Sys_Printf ("Hit vertex\n");
g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = g_qeglobals.d_points[besti];
//SelectVertex (besti);
}