-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.c
1327 lines (1117 loc) · 27.3 KB
/
select.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// select.c
#include "qe3.h"
/*
===========
Test_Ray
===========
*/
#define DIST_START 999999
trace_t Test_Ray (vec3_t origin, vec3_t dir, int flags)
{
brush_t *brush;
face_t *face;
float dist;
trace_t t;
memset (&t, 0, sizeof(t));
t.dist = DIST_START;
// single selection cycle (shift+alt+LBUTTON)
if (flags & SF_CYCLE)
{
int size, j = 0;
brush_t *select;
brush_t *array[MAX_MAP_BRUSHES];
select = (selected_brushes.next != &selected_brushes) ? selected_brushes.next : NULL;
Select_Deselect(true);
// go through active brushes and accumulate all "hit" brushes
for (brush = active_brushes.next; brush != &active_brushes; brush = brush->next)
{
if (FilterBrush (brush))
continue;
face = Brush_Ray (origin, dir, brush, &dist);
if (face)
{
array[j] = brush;
j++;
}
}
size = j;
if (size)
{
brush_t *b;
qboolean found = false;
int i;
for (i = 0; i < size; i++)
{
b = array[i];
// did we hit the last one selected yet ?
if (b == select)
{
// yes we want to select the next one in the list
int n = (i > 0) ? i - 1: size - 1;
select = array[n];
found = true;
break;
}
}
if (!found)
{
j = 0;
select = array[0];
}
}
if (select)
{
face = Brush_Ray (origin, dir, select, &dist);
t.dist = dist;
t.brush = select;
t.face = face;
t.selected = false;
return t;
}
}
if (! (flags & SF_SELECTED_ONLY) )
{
for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
{
if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
continue;
if (FilterBrush (brush))
continue;
face = Brush_Ray (origin, dir, brush, &dist);
if (dist > 0 && dist < t.dist)
{
t.dist = dist;
t.brush = brush;
t.face = face;
t.selected = false;
}
}
}
for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
{
if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
continue;
if (FilterBrush (brush))
continue;
face = Brush_Ray (origin, dir, brush, &dist);
if (dist > 0 && dist < t.dist)
{
t.dist = dist;
t.brush = brush;
t.face = face;
t.selected = true;
}
}
// if entites first, but didn't find any, check regular
if ( (flags & SF_ENTITIES_FIRST) && t.brush == NULL)
return Test_Ray (origin, dir, flags - SF_ENTITIES_FIRST);
return t;
}
/*
============
Select_Brush
============
*/
void Select_Brush (brush_t *brush, qboolean complete)
{
brush_t *b;
entity_t *e;
char selectionstring[256];
char *name;
vec3_t mins, maxs, size;
// deselect any selected faces on brush
Select_DeselectFaces(); // sikk - Multiple Face Selection
if (g_qeglobals.d_select_count < 2)
g_qeglobals.d_select_order[g_qeglobals.d_select_count] = brush;
g_qeglobals.d_select_count++;
e = brush->owner;
if (e)
{
// select complete entity on first click
if (e != world_entity && complete == true)
{
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
if (b->owner == e)
goto singleselect;
for (b=e->brushes.onext ; b != &e->brushes ; b=b->onext)
{
Brush_RemoveFromList (b);
Brush_AddToList (b, &selected_brushes);
}
}
else
{
singleselect:
Brush_RemoveFromList (brush);
Brush_AddToList (brush, &selected_brushes);
}
if (e->eclass)
{
UpdateEntitySel(brush->owner->eclass);
}
}
Select_GetBounds (mins, maxs);
VectorSubtract(maxs, mins, size);
name = ValueForKey (brush->owner, "classname");
sprintf (selectionstring, "Selected object: %s (%i %i %i)", name, (int)size[0], (int)size[1], (int)size[2]);
Sys_Status (selectionstring, 3);
}
/*
================
Select_DeselectFace
================
*/
void Select_DeselectFaces ()
{
int i;
if (select_face_count)
{
for (i = 0; i < select_face_count; i++)
selected_faces[i] = NULL;
select_face_count = 0;
}
}
/*
================
Select_IsFaceSelected
================
*/
qboolean Select_IsFaceSelected (face_t *face)
{
int i;
for (i = 0; i < select_face_count; i++)
if (face == selected_faces[i])
{
select_face_pos = i;
return true;
}
return false;
}
/*
============
Select_Ray
If the origin is inside a brush, that brush will be ignored.
============
*/
void Select_Ray (vec3_t origin, vec3_t dir, int flags)
{
trace_t t;
t = Test_Ray (origin, dir, flags);
if (!t.brush)
return;
if (flags == SF_SINGLEFACE)
{
// deselect face if already selected
if (Select_IsFaceSelected(t.face))
{
int i;
selected_faces[select_face_pos] = NULL;
for (i = select_face_pos; i < select_face_count; i++)
if (selected_faces[i + 1] != NULL)
selected_faces[i] = selected_faces[i + 1];
else
selected_faces[i] = NULL;
select_face_count--;
}
else
{ // if face we clicked on is of a selected brush, do nothing
selected_faces[select_face_count] = t.face;
selected_faces[select_face_count]->owner = t.brush;
Texture_SetTexture (&t.face->texdef, false);
select_face_count++;
}
g_qeglobals.d_select_mode = sel_brush;
Sys_UpdateWindows (W_ALL);
return;
}
// move the brush to the other list
g_qeglobals.d_select_mode = sel_brush;
if (t.selected)
{
Brush_RemoveFromList (t.brush);
Brush_AddToList (t.brush, &active_brushes);
}
else
{
Select_Brush (t.brush, true);
}
Sys_UpdateWindows (W_ALL);
}
void Select_Delete (void)
{
brush_t *brush;
// sikk---> Multiple Face Selection
if (select_face_count)
Select_DeselectFaces();
// <---sikk
g_qeglobals.d_select_mode = sel_brush;
g_qeglobals.d_select_count = 0;
g_qeglobals.d_num_move_points = 0;
while (selected_brushes.next != &selected_brushes)
{
brush = selected_brushes.next;
Brush_Free (brush);
}
// FIXME: remove any entities with no brushes
Sys_UpdateWindows (W_ALL);
}
// update the workzone to a given brush
void UpdateWorkzone_ForBrush( brush_t* b )
{
int dim1, dim2;
VectorCopy( b->mins, g_qeglobals.d_work_min );
VectorCopy( b->maxs, g_qeglobals.d_work_max );
// will update the workzone to the given brush
dim1 = (g_qeglobals.d_viewtype == YZ) ? 1 : 0;
dim2 = (g_qeglobals.d_viewtype == XY) ? 1 : 2;
g_qeglobals.d_work_min[dim1] = b->mins[dim1];
g_qeglobals.d_work_max[dim1] = b->maxs[dim1];
g_qeglobals.d_work_min[dim2] = b->mins[dim2];
g_qeglobals.d_work_max[dim2] = b->maxs[dim2];
}
void Select_Deselect (qboolean deselect_faces)
{
brush_t *b;
g_qeglobals.d_workcount++;
g_qeglobals.d_select_count = 0;
g_qeglobals.d_num_move_points = 0;
b = selected_brushes.next;
if (b == &selected_brushes)
{
// sikk---> Multiple Face Selection
if (deselect_faces)
{
Select_DeselectFaces();
Sys_UpdateWindows (W_ALL);
}
return;
}
if (deselect_faces)
Select_DeselectFaces();
// <---sikk
g_qeglobals.d_select_mode = sel_brush;
// grab top / bottom height for new brushes
// if (b->mins[2] < b->maxs[2])
// {
// g_qeglobals.d_new_brush_bottom_z = b->mins[2];
// g_qeglobals.d_new_brush_top_z = b->maxs[2];
// }
UpdateWorkzone_ForBrush(b);
selected_brushes.next->prev = &active_brushes;
selected_brushes.prev->next = active_brushes.next;
active_brushes.next->prev = selected_brushes.prev;
active_brushes.next = selected_brushes.next;
selected_brushes.prev = selected_brushes.next = &selected_brushes;
Sys_Status ("", 3); // sikk - Clear Selection Status
Sys_UpdateWindows (W_ALL);
}
/*
============
Select_Move
============
*/
void Select_Move (vec3_t delta)
{
brush_t *b;
// actually move the selected brushes
for (b = selected_brushes.next ; b != &selected_brushes ; b=b->next)
Brush_Move (b, delta);
// Sys_UpdateWindows (W_ALL);
}
/*
============
Select_Clone
Creates an exact duplicate of the selection in place, then moves
the selected brushes off of their old positions
============
*/
void Select_Clone (void)
{
brush_t *b, *b2, *n, *next, *next2;
vec3_t delta;
entity_t *e;
g_qeglobals.d_workcount++;
g_qeglobals.d_select_mode = sel_brush;
delta[0] = g_qeglobals.d_gridsize;
delta[1] = g_qeglobals.d_gridsize;
delta[2] = 0;
for (b=selected_brushes.next ; b != &selected_brushes ; b=next)
{
next = b->next;
// if the brush is a world brush, handle simply
if (b->owner == world_entity)
{
n = Brush_Clone (b);
Brush_AddToList (n, &active_brushes);
Entity_LinkBrush (world_entity, n);
Brush_Build( n );
Brush_Move (b, delta);
continue;
}
e = Entity_Clone (b->owner);
// clear the target / targetname
DeleteKey (e, "target");
DeleteKey (e, "targetname");
// if the brush is a fixed size entity, create a new entity
if (b->owner->eclass->fixedsize)
{
n = Brush_Clone (b);
Brush_AddToList (n, &active_brushes);
Entity_LinkBrush (e, n);
Brush_Build( n );
Brush_Move (b, delta);
continue;
}
// brush is a complex entity, grab all the other ones now
next = &selected_brushes;
for ( b2 = b ; b2 != &selected_brushes ; b2=next2)
{
next2 = b2->next;
if (b2->owner != b->owner)
{
if (next == &selected_brushes)
next = b2;
continue;
}
// move b2 to the start of selected_brushes,
// so it won't be hit again
Brush_RemoveFromList (b2);
Brush_AddToList (b2, &selected_brushes);
n = Brush_Clone (b2);
Brush_AddToList (n, &active_brushes);
Entity_LinkBrush (e, n);
Brush_Build( n );
Brush_Move (b2, delta);
}
}
Sys_UpdateWindows (W_ALL);
}
/*
============
Select_SetTexture
============
*/
void Select_SetTexture (texdef_t *texdef)
{
brush_t *b;
// sikk---> Multiple Face Selection
if (select_face_count)
{
int i, count = 0;
brush_t *array[MAX_MAP_BRUSHES];
for (i = 0; i < select_face_count; i++)
{
// this check makes sure that brushes are only added to undo once
// and not once per selected face on brush
if (!OnBrushList(selected_faces[i]->owner, array, count))
{
array[count] = selected_faces[i]->owner;
count++;
}
}
for (i = 0; i < select_face_count; i++)
Face_SetTexture(selected_faces[i], texdef);
}
// <---sikk
else if (selected_brushes.next != &selected_brushes)
{
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
if (!b->owner->eclass->fixedsize)
Brush_SetTexture (b, texdef);
}
Sys_UpdateWindows (W_ALL);
}
/*
================================================================
TRANSFORMATIONS
================================================================
*/
void Select_GetBounds (vec3_t mins, vec3_t maxs)
{
brush_t *b;
int i;
for (i=0 ; i<3 ; i++)
{
mins[i] = 99999;
maxs[i] = -99999;
}
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
for (i=0 ; i<3 ; i++)
{
if (b->mins[i] < mins[i])
mins[i] = b->mins[i];
if (b->maxs[i] > maxs[i])
maxs[i] = b->maxs[i];
}
}
void Select_GetTrueMid (vec3_t mid)
{
vec3_t mins, maxs;
int i;
Select_GetBounds (mins, maxs);
for (i=0 ; i<3 ; i++)
mid[i] = (mins[i] + ((maxs[i] - mins[i]) / 2));
}
void Select_GetMid (vec3_t mid)
{
vec3_t mins, maxs;
int i;
if (g_qeglobals.d_savedinfo.noclamp)
{
Select_GetTrueMid(mid);
return;
}
Select_GetBounds (mins, maxs);
for (i=0 ; i<3 ; i++)
mid[i] = g_qeglobals.d_gridsize*floor ( ( (mins[i] + maxs[i])*0.5 )/g_qeglobals.d_gridsize );
}
vec3_t select_origin;
vec3_t select_matrix[3];
qboolean select_fliporder;
void Select_AplyMatrix (void)
{
brush_t *b;
face_t *f;
int i, j;
vec3_t temp;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
{
for (i=0 ; i<3 ; i++)
{
VectorSubtract (f->planepts[i], select_origin, temp);
for (j=0 ; j<3 ; j++)
f->planepts[i][j] = DotProduct(temp, select_matrix[j])
+ select_origin[j];
}
if (select_fliporder)
{
VectorCopy (f->planepts[0], temp);
VectorCopy (f->planepts[2], f->planepts[0]);
VectorCopy (temp, f->planepts[2]);
}
}
Brush_Build( b );
}
Sys_UpdateWindows (W_ALL);
}
void Select_FlipAxis (int axis)
{
int i;
Select_GetMid (select_origin);
for (i=0 ; i<3 ; i++)
{
VectorCopy (vec3_origin, select_matrix[i]);
select_matrix[i][i] = 1;
}
select_matrix[axis][axis] = -1;
select_fliporder = true;
Select_AplyMatrix ();
Sys_UpdateWindows(W_ALL);
}
/*
================
Clamp
================
*/
void Clamp(float *f, int clamp)
{
float frac = *f - (int)*f;
*f = (int)*f % clamp;
*f += frac;
}
void ProjectOnPlane(vec3_t normal,float dist,vec3_t ez, vec3_t p)
{
if (fabs(ez[0]) == 1)
p[0] = (dist - normal[1] * p[1] - normal[2] * p[2]) / normal[0];
else if (fabs(ez[1]) == 1)
p[1] = (dist - normal[0] * p[0] - normal[2] * p[2]) / normal[1];
else
p[2] = (dist - normal[0] * p[0] - normal[1] * p[1]) / normal[2];
}
void Back(vec3_t dir, vec3_t p)
{
if (fabs(dir[0]) == 1)
p[0] = 0;
else if (fabs(dir[1]) == 1)
p[1] = 0;
else p[2] = 0;
}
// using scale[0] and scale[1]
void ComputeScale(vec3_t rex, vec3_t rey, vec3_t p, face_t *f)
{
float px = DotProduct(rex, p);
float py = DotProduct(rey, p);
vec3_t aux;
px *= f->texdef.scale[0];
py *= f->texdef.scale[1];
VectorCopy(rex, aux);
VectorScale(aux, px, aux);
VectorCopy(aux, p);
VectorCopy(rey, aux);
VectorScale(aux, py, aux);
VectorAdd(p, aux, p);
}
void ComputeAbsolute(face_t *f, vec3_t p1, vec3_t p2, vec3_t p3)
{
vec3_t ex,ey,ez; // local axis base
vec3_t aux;
vec3_t rex,rey;
// compute first local axis base
TextureAxisFromPlane(&f->plane, ex, ey);
CrossProduct(ex, ey, ez);
VectorCopy(ex, aux);
VectorScale(aux, -f->texdef.shift[0], aux);
VectorCopy(aux, p1);
VectorCopy(ey, aux);
VectorScale(aux, -f->texdef.shift[1], aux);
VectorAdd(p1, aux, p1);
VectorCopy(p1, p2);
VectorAdd(p2, ex, p2);
VectorCopy(p1, p3);
VectorAdd(p3, ey, p3);
VectorCopy(ez, aux);
VectorScale(aux, -f->texdef.rotate, aux);
VectorRotate(p1, aux, p1);
VectorRotate(p2, aux, p2);
VectorRotate(p3, aux, p3);
// computing rotated local axis base
VectorCopy(ex, rex);
VectorRotate(rex, aux, rex);
VectorCopy(ey, rey);
VectorRotate(rey, aux, rey);
ComputeScale(rex,rey,p1,f);
ComputeScale(rex,rey,p2,f);
ComputeScale(rex,rey,p3,f);
// project on normal plane
// along ez
// assumes plane normal is normalized
ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p1);
ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p2);
ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p3);
}
void AbsoluteToLocal(plane_t normal2, face_t *f, vec3_t p1, vec3_t p2, vec3_t p3)
{
vec3_t ex,ey,ez;
vec3_t aux;
vec3_t rex,rey;
vec_t x;
vec_t y;
// computing new local axis base
TextureAxisFromPlane(&normal2, ex, ey);
CrossProduct(ex, ey, ez);
// projecting back on (ex,ey)
Back(ez,p1);
Back(ez,p2);
Back(ez,p3);
// rotation
VectorCopy(p2, aux);
VectorSubtract(aux, p1,aux);
x = DotProduct(aux,ex);
y = DotProduct(aux,ey);
f->texdef.rotate = 180 * atan2(y,x) / Q_PI;
// computing rotated local axis base
VectorCopy(ez, aux);
VectorScale(aux, f->texdef.rotate, aux);
VectorCopy(ex, rex);
VectorRotate(rex, aux, rex);
VectorCopy(ey, rey);
VectorRotate(rey, aux, rey);
// scale
VectorCopy(p2, aux);
VectorSubtract(aux, p1, aux);
f->texdef.scale[0] = DotProduct(aux, rex);
VectorCopy(p3, aux);
VectorSubtract(aux, p1, aux);
f->texdef.scale[1] = DotProduct(aux, rey);
// shift
// only using p1
x = DotProduct(rex,p1);
y = DotProduct(rey,p1);
x /= f->texdef.scale[0];
y /= f->texdef.scale[1];
VectorCopy(rex, p1);
VectorScale(p1, x, p1);
VectorCopy(rey, aux);
VectorScale(aux, y, aux);
VectorAdd(p1, aux, p1);
VectorCopy(ez, aux);
VectorScale(aux, -f->texdef.rotate, aux);
VectorRotate(p1, aux, p1);
f->texdef.shift[0] = -DotProduct(p1, ex);
f->texdef.shift[1] = -DotProduct(p1, ey);
// stored rot is good considering local axis base
// change it if necessary
f->texdef.rotate = -f->texdef.rotate;
Clamp(&f->texdef.shift[0], f->d_texture->width);
Clamp(&f->texdef.shift[1], f->d_texture->height);
Clamp(&f->texdef.rotate, 360);
}
void RotateFaceTexture(face_t* f, int axis, float deg)
{
vec3_t p1,p2,p3, rota;
plane_t normal2;
vec3_t normal;
p1[0] = p1[1] = p1[2] = 0;
VectorCopy(p1, p2);
VectorCopy(p1, p3);
VectorCopy(p1, rota);
ComputeAbsolute(f, p1, p2, p3);
rota[axis] = deg;
VectorRotate2(p1, rota, select_origin, p1);
VectorRotate2(p2, rota, select_origin, p2);
VectorRotate2(p3, rota, select_origin, p3);
normal[0] = f->plane.normal[0];
normal[1] = f->plane.normal[1];
normal[2] = f->plane.normal[2];
VectorRotate(normal, rota, normal);
normal2.normal[0] = normal[0];
normal2.normal[1] = normal[1];
normal2.normal[2] = normal[2];
AbsoluteToLocal(normal2, f, p1, p2 ,p3);
}
void RotateTextures(int axis, float deg, vec3_t origin)
{
brush_t *b;
face_t *f;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
for (f=b->brush_faces ; f ; f=f->next)
{
RotateFaceTexture(f, axis, deg);
Brush_Build(b);
}
Brush_Build(b);
}
}
void Select_RotateAxis (int axis, float deg)
{
/*
vec3_t temp;
int i, j;
vec_t c, s;
if (deg == 0)
return;
Select_GetMid (select_origin);
select_fliporder = false;
if (deg == 90)
{
for (i=0 ; i<3 ; i++)
{
VectorCopy (vec3_origin, select_matrix[i]);
select_matrix[i][i] = 1;
}
i = (axis+1)%3;
j = (axis+2)%3;
VectorCopy (select_matrix[i], temp);
VectorCopy (select_matrix[j], select_matrix[i]);
VectorSubtract (vec3_origin, temp, select_matrix[j]);
}
else
{
deg = -deg;
if (deg == -180)
{
c = -1;
s = 0;
}
else if (deg == -270)
{
c = 0;
s = -1;
}
else
{
c = cos(deg * Q_PI / 180.0);
s = sin(deg * Q_PI / 180.0);
}
for (i=0 ; i<3 ; i++)
{
VectorCopy (vec3_origin, select_matrix[i]);
select_matrix[i][i] = 1;
}
switch (axis)
{
case 0:
select_matrix[1][1] = c;
select_matrix[1][2] = -s;
select_matrix[2][1] = s;
select_matrix[2][2] = c;
break;
case 1:
select_matrix[0][0] = c;
select_matrix[0][2] = s;
select_matrix[2][0] = -s;
select_matrix[2][2] = c;
break;
case 2:
select_matrix[0][0] = c;
select_matrix[0][1] = -s;
select_matrix[1][0] = s;
select_matrix[1][1] = c;
break;
}
}
*/
int i;
vec_t c, s;
while(deg >= 360)
deg -= 360;
while(deg < 0)
deg += 360;
if (deg == 0)
return;
Select_GetMid (select_origin);
select_fliporder = false;
deg = -deg;
c = cos(deg * Q_PI / 180.0);
s = sin(deg * Q_PI / 180.0);
for (i=0 ; i<3 ; i++)
{
VectorCopy (vec3_origin, select_matrix[i]);
select_matrix[i][i] = 1;
}
switch (axis)
{
case 0:
select_matrix[1][1] = c;
select_matrix[1][2] = -s;
select_matrix[2][1] = s;
select_matrix[2][2] = c;
break;
case 1:
select_matrix[0][0] = c;
select_matrix[0][2] = s;
select_matrix[2][0] = -s;
select_matrix[2][2] = c;
break;
case 2:
select_matrix[0][0] = c;
select_matrix[0][1] = -s;
select_matrix[1][0] = s;
select_matrix[1][1] = c;
break;
}
if(g_qeglobals.d_textures_lock)
RotateTextures(axis, deg, select_origin);
Select_AplyMatrix ();
Sys_UpdateWindows(W_ALL);
}
void Select_FitTexture(int height, int width)
{
brush_t *b;
if(selected_brushes.next == &selected_brushes && !select_face_count)
return;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
Brush_FitTexture(b, height, width);
Brush_Build(b);
}
// sikk---> Multiple Face Selection
if (select_face_count)
{
int i;
for (i = 0; i < select_face_count; i++)
{
Face_FitTexture(selected_faces[i], height, width);
Brush_Build(selected_faces[i]->owner);
}
}
// <---sikk
Sys_UpdateWindows (W_CAMERA);
}
/*
================================================================
GROUP SELECTIONS
================================================================
*/
void Select_CompleteTall (void)
{
brush_t *b, *next;
// int i;
vec3_t mins, maxs;
int dim1, dim2;
if (!QE_SingleBrush ())
return;
g_qeglobals.d_select_mode = sel_brush;
VectorCopy (selected_brushes.next->mins, mins);
VectorCopy (selected_brushes.next->maxs, maxs);
Select_Delete ();
dim1 = (g_qeglobals.d_viewtype == YZ) ? 1 : 0;
dim2 = (g_qeglobals.d_viewtype == XY) ? 1 : 2;
for (b=active_brushes.next ; b != &active_brushes ; b=next)
{
next = b->next;