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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2005 Blender Foundation
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/transform/transform_manipulator.c
* \ingroup edtransform
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
#include "DNA_curve_types.h"
#include "DNA_lattice_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
#include "DNA_screen_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "RNA_access.h"
#include "BKE_action.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_editmesh.h"
#include "BKE_lattice.h"
#include "BIF_gl.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_armature.h"
#include "ED_curve.h"
#include "ED_mesh.h"
#include "ED_particle.h"
#include "ED_view3d.h"
#include "UI_resources.h"
/* local module include */
#include "transform.h"
/* return codes for select, and drawing flags */
#define MAN_TRANS_X (1 << 0)
#define MAN_TRANS_Y (1 << 1)
#define MAN_TRANS_Z (1 << 2)
#define MAN_TRANS_C (MAN_TRANS_X | MAN_TRANS_Y | MAN_TRANS_Z)
#define MAN_ROT_X (1 << 3)
#define MAN_ROT_Y (1 << 4)
#define MAN_ROT_Z (1 << 5)
#define MAN_ROT_V (1 << 6)
#define MAN_ROT_T (1 << 7)
#define MAN_ROT_C (MAN_ROT_X | MAN_ROT_Y | MAN_ROT_Z | MAN_ROT_V | MAN_ROT_T)
#define MAN_SCALE_X (1 << 8)
#define MAN_SCALE_Y (1 << 9)
#define MAN_SCALE_Z (1 << 10)
#define MAN_SCALE_C (MAN_SCALE_X | MAN_SCALE_Y | MAN_SCALE_Z)
/* color codes */
#define MAN_RGB 0
#define MAN_GHOST 1
#define MAN_MOVECOL 2
/* transform widget center calc helper for below */
static void calc_tw_center(Scene *scene, const float co[3])
{
float *twcent = scene->twcent;
float *min = scene->twmin;
float *max = scene->twmax;
minmax_v3v3_v3(min, max, co);
add_v3_v3(twcent, co);
}
static void protectflag_to_drawflags(short protectflag, short *drawflags)
{
if (protectflag & OB_LOCK_LOCX)
*drawflags &= ~MAN_TRANS_X;
if (protectflag & OB_LOCK_LOCY)
*drawflags &= ~MAN_TRANS_Y;
if (protectflag & OB_LOCK_LOCZ)
*drawflags &= ~MAN_TRANS_Z;
if (protectflag & OB_LOCK_ROTX)
*drawflags &= ~MAN_ROT_X;
if (protectflag & OB_LOCK_ROTY)
*drawflags &= ~MAN_ROT_Y;
if (protectflag & OB_LOCK_ROTZ)
*drawflags &= ~MAN_ROT_Z;
if (protectflag & OB_LOCK_SCALEX)
*drawflags &= ~MAN_SCALE_X;
if (protectflag & OB_LOCK_SCALEY)
*drawflags &= ~MAN_SCALE_Y;
if (protectflag & OB_LOCK_SCALEZ)
*drawflags &= ~MAN_SCALE_Z;
}
/* for pose mode */
static void stats_pose(Scene *scene, RegionView3D *rv3d, bPoseChannel *pchan)
{
Bone *bone = pchan->bone;
if (bone) {
calc_tw_center(scene, pchan->pose_head);
protectflag_to_drawflags(pchan->protectflag, &rv3d->twdrawflag);
}
}
/* for editmode*/
static void stats_editbone(RegionView3D *rv3d, EditBone *ebo)
{
if (ebo->flag & BONE_EDITMODE_LOCKED)
protectflag_to_drawflags(OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE, &rv3d->twdrawflag);
}
/* could move into BLI_math however this is only useful for display/editing purposes */
static void axis_angle_to_gimbal_axis(float gmat[3][3], float axis[3], float angle)
{
/* X/Y are arbitrary axies, most importantly Z is the axis of rotation */
float cross_vec[3];
float quat[4];
/* this is an un-scientific method to get a vector to cross with
* XYZ intentionally YZX */
cross_vec[0] = axis[1];
cross_vec[1] = axis[2];
cross_vec[2] = axis[0];
/* X-axis */
cross_v3_v3v3(gmat[0], cross_vec, axis);
normalize_v3(gmat[0]);
axis_angle_to_quat(quat, axis, angle);
mul_qt_v3(quat, gmat[0]);
/* Y-axis */
axis_angle_to_quat(quat, axis, M_PI / 2.0);
copy_v3_v3(gmat[1], gmat[0]);
mul_qt_v3(quat, gmat[1]);
/* Z-axis */
copy_v3_v3(gmat[2], axis);
normalize_m3(gmat);
}
static int test_rotmode_euler(short rotmode)
{
return (ELEM(rotmode, ROT_MODE_AXISANGLE, ROT_MODE_QUAT)) ? 0 : 1;
}
int gimbal_axis(Object *ob, float gmat[3][3])
{
if (ob) {
if (ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan = BKE_pose_channel_active(ob);
if (pchan) {
float mat[3][3], tmat[3][3], obmat[3][3];
if (test_rotmode_euler(pchan->rotmode)) {
eulO_to_gimbal_axis(mat, pchan->eul, pchan->rotmode);
}
else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
axis_angle_to_gimbal_axis(mat, pchan->rotAxis, pchan->rotAngle);
}
else { /* quat */
return 0;
}
/* apply bone transformation */
mul_m3_m3m3(tmat, pchan->bone->bone_mat, mat);
if (pchan->parent) {
float parent_mat[3][3];
copy_m3_m4(parent_mat, pchan->parent->pose_mat);
mul_m3_m3m3(mat, parent_mat, tmat);
/* needed if object transformation isn't identity */
copy_m3_m4(obmat, ob->obmat);
mul_m3_m3m3(gmat, obmat, mat);
}
else {
/* needed if object transformation isn't identity */
copy_m3_m4(obmat, ob->obmat);
mul_m3_m3m3(gmat, obmat, tmat);
}
normalize_m3(gmat);
return 1;
}
}
else {
if (test_rotmode_euler(ob->rotmode)) {
eulO_to_gimbal_axis(gmat, ob->rot, ob->rotmode);
}
else if (ob->rotmode == ROT_MODE_AXISANGLE) {
axis_angle_to_gimbal_axis(gmat, ob->rotAxis, ob->rotAngle);
}
else { /* quat */
return 0;
}
if (ob->parent) {
float parent_mat[3][3];
copy_m3_m4(parent_mat, ob->parent->obmat);
normalize_m3(parent_mat);
mul_m3_m3m3(gmat, parent_mat, gmat);
}
return 1;
}
}
return 0;
}
/* centroid, boundbox, of selection */
/* returns total items selected */
int calc_manipulator_stats(const bContext *C)
{
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
Object *obedit = CTX_data_edit_object(C);
ToolSettings *ts = CTX_data_tool_settings(C);
View3D *v3d = sa->spacedata.first;
RegionView3D *rv3d = ar->regiondata;
Base *base;
Object *ob = OBACT;
int a, totsel = 0;
/* transform widget matrix */
unit_m4(rv3d->twmat);
rv3d->twdrawflag = 0xFFFF;
/* transform widget centroid/center */
INIT_MINMAX(scene->twmin, scene->twmax);
zero_v3(scene->twcent);
if (obedit) {
ob = obedit;
if ((ob->lay & v3d->lay) == 0) return 0;
if (obedit->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMEditSelection ese;
float vec[3] = {0, 0, 0};
/* USE LAST SELECTE WITH ACTIVE */
if ((v3d->around == V3D_ACTIVE) && BM_select_history_active_get(em->bm, &ese)) {
BM_editselection_center(&ese, vec);
calc_tw_center(scene, vec);
totsel = 1;
}
else {
BMesh *bm = em->bm;
BMVert *eve;
BMIter iter;
/* do vertices/edges/faces for center depending on selection
* mode. note we can't use just vertex selection flag because
* it is not flush down on changes */
if (ts->selectmode & SCE_SELECT_VERTEX) {
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
totsel++;
calc_tw_center(scene, eve->co);
}
}
}
}
else if (ts->selectmode & SCE_SELECT_EDGE) {
BMIter itersub;
BMEdge *eed;
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
/* check the vertex has a selected edge, only add it once */
BM_ITER_ELEM (eed, &itersub, eve, BM_EDGES_OF_VERT) {
if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
totsel++;
calc_tw_center(scene, eve->co);
break;
}
}
}
}
}
else {
BMIter itersub;
BMFace *efa;
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
/* check the vertex has a selected face, only add it once */
BM_ITER_ELEM (efa, &itersub, eve, BM_FACES_OF_VERT) {
if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
totsel++;
calc_tw_center(scene, eve->co);
break;
}
}
}
}
}
}
} /* end editmesh */
else if (obedit->type == OB_ARMATURE) {
bArmature *arm = obedit->data;
EditBone *ebo;
if ((v3d->around == V3D_ACTIVE) && (ebo = arm->act_edbone)) {
/* doesn't check selection or visibility intentionally */
if (ebo->flag & BONE_TIPSEL) {
calc_tw_center(scene, ebo->tail);
totsel++;
}
if ((ebo->flag & BONE_ROOTSEL) ||
((ebo->flag & BONE_TIPSEL) == FALSE)) /* ensure we get at least one point */
{
calc_tw_center(scene, ebo->head);
totsel++;
}
stats_editbone(rv3d, ebo);
}
else {
for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
if (EBONE_VISIBLE(arm, ebo)) {
if (ebo->flag & BONE_TIPSEL) {
calc_tw_center(scene, ebo->tail);
totsel++;
}
if (ebo->flag & BONE_ROOTSEL) {
calc_tw_center(scene, ebo->head);
totsel++;
}
if (ebo->flag & BONE_SELECTED) {
stats_editbone(rv3d, ebo);
}
}
}
}
}
else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
Curve *cu = obedit->data;
float center[3];
if (v3d->around == V3D_ACTIVE && ED_curve_actSelection(cu, center)) {
calc_tw_center(scene, center);
totsel++;
}
else {
Nurb *nu;
BezTriple *bezt;
BPoint *bp;
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
nu = nurbs->first;
while (nu) {
if (nu->type == CU_BEZIER) {
bezt = nu->bezt;
a = nu->pntsu;
while (a--) {
/* exceptions
* if handles are hidden then only check the center points.
* If the center knot is selected then only use this as the center point.
*/
if (cu->drawflag & CU_HIDE_HANDLES) {
if (bezt->f2 & SELECT) {
calc_tw_center(scene, bezt->vec[1]);
totsel++;
}
}
else if (bezt->f2 & SELECT) {
calc_tw_center(scene, bezt->vec[1]);
totsel++;
}
else {
if (bezt->f1 & SELECT) {
calc_tw_center(scene, bezt->vec[(v3d->around == V3D_LOCAL) ? 1 : 0]);
totsel++;
}
if (bezt->f3 & SELECT) {
calc_tw_center(scene, bezt->vec[(v3d->around == V3D_LOCAL) ? 1 : 2]);
totsel++;
}
}
bezt++;
}
}
else {
bp = nu->bp;
a = nu->pntsu * nu->pntsv;
while (a--) {
if (bp->f1 & SELECT) {
calc_tw_center(scene, bp->vec);
totsel++;
}
bp++;
}
}
nu = nu->next;
}
}
}
else if (obedit->type == OB_MBALL) {
MetaBall *mb = (MetaBall *)obedit->data;
MetaElem *ml /* , *ml_sel = NULL */ /* UNUSED */;
ml = mb->editelems->first;
while (ml) {
if (ml->flag & SELECT) {
calc_tw_center(scene, &ml->x);
/* ml_sel = ml; */ /* UNUSED */
totsel++;
}
ml = ml->next;
}
}
else if (obedit->type == OB_LATTICE) {
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
BPoint *bp;
if ((v3d->around == V3D_ACTIVE) && (bp = BKE_lattice_active_point_get(lt))) {
calc_tw_center(scene, bp->vec);
totsel++;
}
else {
bp = lt->def;
a = lt->pntsu * lt->pntsv * lt->pntsw;
while (a--) {
if (bp->f1 & SELECT) {
calc_tw_center(scene, bp->vec);
totsel++;
}
bp++;
}
}
}
/* selection center */
if (totsel) {
mul_v3_fl(scene->twcent, 1.0f / (float)totsel); // centroid!
mul_m4_v3(obedit->obmat, scene->twcent);
mul_m4_v3(obedit->obmat, scene->twmin);
mul_m4_v3(obedit->obmat, scene->twmax);
}
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
bPoseChannel *pchan;
int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed
int ok = FALSE;
if ((ob->lay & v3d->lay) == 0) return 0;
if ((v3d->around == V3D_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) {
/* doesn't check selection or visibility intentionally */
Bone *bone = pchan->bone;
if (bone) {
stats_pose(scene, rv3d, pchan);
totsel = 1;
ok = TRUE;
}
}
else {
totsel = count_set_pose_transflags(&mode, 0, ob);
if (totsel) {
/* use channels to get stats */
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
Bone *bone = pchan->bone;
if (bone && (bone->flag & BONE_TRANSFORM)) {
stats_pose(scene, rv3d, pchan);
}
}
ok = TRUE;
}
}
if (ok) {
mul_v3_fl(scene->twcent, 1.0f / (float)totsel); // centroid!
mul_m4_v3(ob->obmat, scene->twcent);
mul_m4_v3(ob->obmat, scene->twmin);
mul_m4_v3(ob->obmat, scene->twmax);
}
}
else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
/* pass */
}
else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) {
PTCacheEdit *edit = PE_get_current(scene, ob);
PTCacheEditPoint *point;
PTCacheEditKey *ek;
int k;
if (edit) {
point = edit->points;
for (a = 0; a < edit->totpoint; a++, point++) {
if (point->flag & PEP_HIDE) continue;
for (k = 0, ek = point->keys; k < point->totkey; k++, ek++) {
if (ek->flag & PEK_SELECT) {
calc_tw_center(scene, ek->flag & PEK_USE_WCO ? ek->world_co : ek->co);
totsel++;
}
}
}
/* selection center */
if (totsel)
mul_v3_fl(scene->twcent, 1.0f / (float)totsel); // centroid!
}
}
else {
/* we need the one selected object, if its not active */
ob = OBACT;
if (ob && !(ob->flag & SELECT)) ob = NULL;
for (base = scene->base.first; base; base = base->next) {
if (TESTBASELIB(v3d, base)) {
if (ob == NULL)
ob = base->object;
calc_tw_center(scene, base->object->obmat[3]);
protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag);
totsel++;
}
}
/* selection center */
if (totsel) {
mul_v3_fl(scene->twcent, 1.0f / (float)totsel); // centroid!
}
}
/* global, local or normal orientation? */
if (ob && totsel) {
switch (v3d->twmode) {
case V3D_MANIP_GLOBAL:
{
break; /* nothing to do */
}
case V3D_MANIP_GIMBAL:
{
float mat[3][3];
if (gimbal_axis(ob, mat)) {
copy_m4_m3(rv3d->twmat, mat);
break;
}
/* if not gimbal, fall through to normal */
/* fall-through */
}
case V3D_MANIP_NORMAL:
{
if (obedit || ob->mode & OB_MODE_POSE) {
float mat[3][3];
ED_getTransformOrientationMatrix(C, mat, (v3d->around == V3D_ACTIVE));
copy_m4_m3(rv3d->twmat, mat);
break;
}
/* no break we define 'normal' as 'local' in Object mode */
/* fall-through */
}
case V3D_MANIP_LOCAL:
{
if (ob->mode & OB_MODE_POSE) {
/* each bone moves on its own local axis, but to avoid confusion,
* use the active pones axis for display [#33575], this works as expected on a single bone
* and users who select many bones will understand whats going on and what local means
* when they start transforming */
float mat[3][3];
ED_getTransformOrientationMatrix(C, mat, (v3d->around == V3D_ACTIVE));
copy_m4_m3(rv3d->twmat, mat);
break;
}
copy_m4_m4(rv3d->twmat, ob->obmat);
normalize_m4(rv3d->twmat);
break;
}
case V3D_MANIP_VIEW:
{
float mat[3][3];
copy_m3_m4(mat, rv3d->viewinv);
normalize_m3(mat);
copy_m4_m3(rv3d->twmat, mat);
break;
}
default: /* V3D_MANIP_CUSTOM */
{
float mat[3][3];
if (applyTransformOrientation(C, mat, NULL)) {
copy_m4_m3(rv3d->twmat, mat);
}
break;
}
}
}
return totsel;
}
/* don't draw axis perpendicular to the view */
static void test_manipulator_axis(const bContext *C)
{
RegionView3D *rv3d = CTX_wm_region_view3d(C);
float angle;
float vec[3];
ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], vec);
angle = fabsf(angle_v3v3(rv3d->twmat[0], vec));
if (angle > (float)M_PI / 2.0f) {
angle = (float)M_PI - angle;
}
angle = rv3d->twangle[0] = RAD2DEGF(angle);
if (angle < 5.0f) {
rv3d->twdrawflag &= ~(MAN_TRANS_X | MAN_SCALE_X);
}
angle = fabsf(angle_v3v3(rv3d->twmat[1], vec));
if (angle > (float)M_PI / 2.0f) {
angle = (float)M_PI - angle;
}
angle = rv3d->twangle[1] = RAD2DEGF(angle);
if (angle < 5.0f) {
rv3d->twdrawflag &= ~(MAN_TRANS_Y | MAN_SCALE_Y);
}
angle = fabsf(angle_v3v3(rv3d->twmat[2], vec));
if (angle > (float)M_PI / 2.0f) {
angle = (float)M_PI - angle;
}
angle = rv3d->twangle[2] = RAD2DEGF(angle);
if (angle < 5.0f) {
rv3d->twdrawflag &= ~(MAN_TRANS_Z | MAN_SCALE_Z);
}
}
/* ******************** DRAWING STUFFIES *********** */
static float screen_aligned(RegionView3D *rv3d, float mat[4][4])
{
glTranslatef(mat[3][0], mat[3][1], mat[3][2]);
/* sets view screen aligned */
glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
return len_v3(mat[0]); /* draw scale */
}
/* radring = radius of doughnut rings
* radhole = radius hole
* start = starting segment (based on nrings)
* end = end segment
* nsides = amount of points in ring
* nrigns = amount of rings
*/
static void partial_doughnut(float radring, float radhole, int start, int end, int nsides, int nrings)
{
float theta, phi, theta1;
float cos_theta, sin_theta;
float cos_theta1, sin_theta1;
float ring_delta, side_delta;
int i, j, do_caps = TRUE;
if (start == 0 && end == nrings) do_caps = FALSE;
ring_delta = 2.0f * (float)M_PI / (float)nrings;
side_delta = 2.0f * (float)M_PI / (float)nsides;
theta = (float)M_PI + 0.5f * ring_delta;
cos_theta = cosf(theta);
sin_theta = sinf(theta);
for (i = nrings - 1; i >= 0; i--) {
theta1 = theta + ring_delta;
cos_theta1 = cosf(theta1);
sin_theta1 = sinf(theta1);
if (do_caps && i == start) { // cap
glBegin(GL_POLYGON);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
float cos_phi, sin_phi, dist;
phi += side_delta;
cos_phi = cosf(phi);
sin_phi = sinf(phi);
dist = radhole + radring * cos_phi;
glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
}
glEnd();
}
if (i >= start && i <= end) {
glBegin(GL_QUAD_STRIP);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
float cos_phi, sin_phi, dist;
phi += side_delta;
cos_phi = cosf(phi);
sin_phi = sinf(phi);
dist = radhole + radring * cos_phi;
glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi);
}
glEnd();
}
if (do_caps && i == end) { // cap
glBegin(GL_POLYGON);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
float cos_phi, sin_phi, dist;
phi -= side_delta;
cos_phi = cosf(phi);
sin_phi = sinf(phi);
dist = radhole + radring * cos_phi;
glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi);
}
glEnd();
}
theta = theta1;
cos_theta = cos_theta1;
sin_theta = sin_theta1;
}
}
static char axisBlendAngle(float angle)
{
if (angle > 20)
return 255;
if (angle < 5)
return 0;
return (char)(255.0f * (angle - 5) / 15.0f);
}
/* three colors can be set:
* gray for ghosting
* moving: in transform theme color
* else the red/green/blue
*/
static void manipulator_setcolor(View3D *v3d, char axis, int colcode, unsigned char alpha)
{
unsigned char col[4] = {0};
col[3] = alpha;
if (colcode == MAN_GHOST) {
col[3] = 70;
}
else if (colcode == MAN_MOVECOL) {
UI_GetThemeColor3ubv(TH_TRANSFORM, col);
}
else {
switch (axis) {
case 'C':
UI_GetThemeColor3ubv(TH_TRANSFORM, col);
if (v3d->twmode == V3D_MANIP_LOCAL) {
col[0] = col[0] > 200 ? 255 : col[0] + 55;
col[1] = col[1] > 200 ? 255 : col[1] + 55;
col[2] = col[2] > 200 ? 255 : col[2] + 55;
}
else if (v3d->twmode == V3D_MANIP_NORMAL) {
col[0] = col[0] < 55 ? 0 : col[0] - 55;
col[1] = col[1] < 55 ? 0 : col[1] - 55;
col[2] = col[2] < 55 ? 0 : col[2] - 55;
}
break;
case 'X':
UI_GetThemeColor3ubv(TH_AXIS_X, col);
break;
case 'Y':
UI_GetThemeColor3ubv(TH_AXIS_Y, col);
break;
case 'Z':
UI_GetThemeColor3ubv(TH_AXIS_Z, col);
break;
default:
BLI_assert(0);
break;
}
}
glColor4ubv(col);
}
static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
{
float axis_values[3];
float vec[3];
ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], vec);
axis_values[0] = -dot_v3v3(rv3d->twmat[0], vec);
axis_values[1] = -dot_v3v3(rv3d->twmat[1], vec);
axis_values[2] = -dot_v3v3(rv3d->twmat[2], vec);
axis_sort_v3(axis_values, r_axis_order);
}
/* viewmatrix should have been set OK, also no shademode! */
static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int colcode,
int flagx, int flagy, int flagz, int axis)
{
switch (axis) {
case 0:
/* axes */
if (flagx) {
manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->twangle[0]));
if (flagx & MAN_SCALE_X) glLoadName(MAN_SCALE_X);
else if (flagx & MAN_TRANS_X) glLoadName(MAN_TRANS_X);
glBegin(GL_LINES);
glVertex3f(0.2f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glEnd();
}
break;
case 1:
if (flagy) {
if (flagy & MAN_SCALE_Y) glLoadName(MAN_SCALE_Y);
else if (flagy & MAN_TRANS_Y) glLoadName(MAN_TRANS_Y);
manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->twangle[1]));
glBegin(GL_LINES);
glVertex3f(0.0f, 0.2f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
}
break;
case 2:
if (flagz) {
if (flagz & MAN_SCALE_Z) glLoadName(MAN_SCALE_Z);
else if (flagz & MAN_TRANS_Z) glLoadName(MAN_TRANS_Z);
manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->twangle[2]));
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.2f);
glVertex3f(0.0f, 0.0f, 1.0f);
glEnd();
}
break;
}
}
static void draw_manipulator_axes(View3D *v3d, RegionView3D *rv3d, int colcode,
int flagx, int flagy, int flagz,
const int axis_order[3])
{
int i;
for (i = 0; i < 3; i++) {
draw_manipulator_axes_single(v3d, rv3d, colcode, flagx, flagy, flagz, axis_order[i]);
}
}
static void preOrthoFront(int ortho, float twmat[4][4], int axis)
{
if (ortho == 0) {
float omat[4][4];
copy_m4_m4(omat, twmat);
orthogonalize_m4(omat, axis);
glPushMatrix();
glMultMatrixf(omat);
glFrontFace(is_negative_m4(omat) ? GL_CW : GL_CCW);
}
}
static void postOrtho(int ortho)
{
if (ortho == 0) {
glPopMatrix();
}
}
static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo)
{
double plane[4];
float matt[4][4];
float size, unitmat[4][4];
float cywid = 0.33f * 0.01f * (float)U.tw_handlesize;
float cusize = cywid * 0.65f;
int arcs = (G.debug_value != 2);
int colcode;
int ortho;
if (moving) colcode = MAN_MOVECOL;
else colcode = MAN_RGB;
/* when called while moving in mixed mode, do not draw when... */
if ((drawflags & MAN_ROT_C) == 0) return;
/* Init stuff */
glDisable(GL_DEPTH_TEST);
unit_m4(unitmat);
/* prepare for screen aligned draw */
size = len_v3(rv3d->twmat[0]);
glPushMatrix();
glTranslatef(rv3d->twmat[3][0], rv3d->twmat[3][1], rv3d->twmat[3][2]);
if (arcs) {
/* clipplane makes nice handles, calc here because of multmatrix but with translate! */
copy_v3db_v3fl(plane, rv3d->viewinv[2]);
plane[3] = -0.02f * size; // clip just a bit more
glClipPlane(GL_CLIP_PLANE0, plane);
}
/* sets view screen aligned */
glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
/* Screen aligned help circle */
if (arcs) {
if ((G.f & G_PICKSEL) == 0) {
UI_ThemeColorShade(TH_BACK, -30);
drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
}
}
/* Screen aligned trackball rot circle */
if (drawflags & MAN_ROT_T) {
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_T);
UI_ThemeColor(TH_TRANSFORM);
drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
}
/* Screen aligned view rot circle */
if (drawflags & MAN_ROT_V) {
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_V);
UI_ThemeColor(TH_TRANSFORM);
drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
if (moving) {
float vec[3];
vec[0] = 0; // XXX (float)(t->imval[0] - t->center2d[0]);
vec[1] = 0; // XXX (float)(t->imval[1] - t->center2d[1]);
vec[2] = 0.0f;
normalize_v3(vec);
mul_v3_fl(vec, 1.2f * size);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3fv(vec);
glEnd();
}
}
glPopMatrix();
ortho = is_orthogonal_m4(rv3d->twmat);
/* apply the transform delta */
if (moving) {
copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
if (ortho) {
glMultMatrixf(matt);
glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
}
}
else {
if (ortho) {
glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
glMultMatrixf(rv3d->twmat);
}
}
/* axes */
if (arcs == 0) {
if (!(G.f & G_PICKSEL)) {
if ((combo & V3D_MANIP_SCALE) == 0) {
/* axis */
if ((drawflags & MAN_ROT_X) || (moving && (drawflags & MAN_ROT_Z))) {
preOrthoFront(ortho, rv3d->twmat, 2);
manipulator_setcolor(v3d, 'X', colcode, 255);
glBegin(GL_LINES);
glVertex3f(0.2f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glEnd();
postOrtho(ortho);
}
if ((drawflags & MAN_ROT_Y) || (moving && (drawflags & MAN_ROT_X))) {
preOrthoFront(ortho, rv3d->twmat, 0);
manipulator_setcolor(v3d, 'Y', colcode, 255);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.2f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
postOrtho(ortho);
}
if ((drawflags & MAN_ROT_Z) || (moving && (drawflags & MAN_ROT_Y))) {
preOrthoFront(ortho, rv3d->twmat, 1);
manipulator_setcolor(v3d, 'Z', colcode, 255);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.2f);
glVertex3f(0.0f, 0.0f, 1.0f);
glEnd();
postOrtho(ortho);
}
}
}
}
if (arcs == 0 && moving) {
/* Z circle */
if (drawflags & MAN_ROT_Z) {
preOrthoFront(ortho, matt, 2);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Z);
manipulator_setcolor(v3d, 'Z', colcode, 255);
drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
postOrtho(ortho);
}
/* X circle */
if (drawflags & MAN_ROT_X) {
preOrthoFront(ortho, matt, 0);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_X);
glRotatef(90.0, 0.0, 1.0, 0.0);
manipulator_setcolor(v3d, 'X', colcode, 255);
drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
glRotatef(-90.0, 0.0, 1.0, 0.0);
postOrtho(ortho);
}
/* Y circle */
if (drawflags & MAN_ROT_Y) {
preOrthoFront(ortho, matt, 1);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Y);
glRotatef(-90.0, 1.0, 0.0, 0.0);
manipulator_setcolor(v3d, 'Y', colcode, 255);
drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
glRotatef(90.0, 1.0, 0.0, 0.0);
postOrtho(ortho);
}
if (arcs) glDisable(GL_CLIP_PLANE0);
}
// donut arcs
if (arcs) {
glEnable(GL_CLIP_PLANE0);
/* Z circle */
if (drawflags & MAN_ROT_Z) {
preOrthoFront(ortho, rv3d->twmat, 2);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Z);
manipulator_setcolor(v3d, 'Z', colcode, 255);
partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
postOrtho(ortho);
}
/* X circle */
if (drawflags & MAN_ROT_X) {
preOrthoFront(ortho, rv3d->twmat, 0);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_X);
glRotatef(90.0, 0.0, 1.0, 0.0);
manipulator_setcolor(v3d, 'X', colcode, 255);
partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
glRotatef(-90.0, 0.0, 1.0, 0.0);
postOrtho(ortho);
}
/* Y circle */
if (drawflags & MAN_ROT_Y) {
preOrthoFront(ortho, rv3d->twmat, 1);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Y);
glRotatef(-90.0, 1.0, 0.0, 0.0);
manipulator_setcolor(v3d, 'Y', colcode, 255);
partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
glRotatef(90.0, 1.0, 0.0, 0.0);
postOrtho(ortho);
}
glDisable(GL_CLIP_PLANE0);
}
if (arcs == 0) {
/* Z handle on X axis */
if (drawflags & MAN_ROT_Z) {
preOrthoFront(ortho, rv3d->twmat, 2);
glPushMatrix();
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Z);
manipulator_setcolor(v3d, 'Z', colcode, 255);
partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
glPopMatrix();
postOrtho(ortho);
}
/* Y handle on X axis */
if (drawflags & MAN_ROT_Y) {
preOrthoFront(ortho, rv3d->twmat, 1);
glPushMatrix();
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Y);
manipulator_setcolor(v3d, 'Y', colcode, 255);
glRotatef(90.0, 1.0, 0.0, 0.0);
glRotatef(90.0, 0.0, 0.0, 1.0);
partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
glPopMatrix();
postOrtho(ortho);
}
/* X handle on Z axis */
if (drawflags & MAN_ROT_X) {
preOrthoFront(ortho, rv3d->twmat, 0);
glPushMatrix();
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_X);
manipulator_setcolor(v3d, 'X', colcode, 255);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glRotatef(90.0, 0.0, 0.0, 1.0);
partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
glPopMatrix();
postOrtho(ortho);
}
}
/* restore */
glLoadMatrixf(rv3d->viewmat);
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
}
static void drawsolidcube(float size)
{
static float cube[8][3] = {
{-1.0, -1.0, -1.0},
{-1.0, -1.0, 1.0},
{-1.0, 1.0, 1.0},
{-1.0, 1.0, -1.0},
{ 1.0, -1.0, -1.0},
{ 1.0, -1.0, 1.0},
{ 1.0, 1.0, 1.0},
{ 1.0, 1.0, -1.0},
};
float n[3] = {0.0f};
glPushMatrix();
glScalef(size, size, size);
glBegin(GL_QUADS);
n[0] = -1.0;
glNormal3fv(n);
glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
n[0] = 0;
glEnd();
glBegin(GL_QUADS);
n[1] = -1.0;
glNormal3fv(n);
glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
n[1] = 0;
glEnd();
glBegin(GL_QUADS);
n[0] = 1.0;
glNormal3fv(n);
glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
n[0] = 0;
glEnd();
glBegin(GL_QUADS);
n[1] = 1.0;
glNormal3fv(n);
glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
n[1] = 0;
glEnd();
glBegin(GL_QUADS);
n[2] = 1.0;
glNormal3fv(n);
glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
n[2] = 0;
glEnd();
glBegin(GL_QUADS);
n[2] = -1.0;
glNormal3fv(n);
glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
glEnd();
glPopMatrix();
}
static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo, int colcode)
{
float cywid = 0.25f * 0.01f * (float)U.tw_handlesize;
float cusize = cywid * 0.75f, dz;
int axis_order[3] = {2, 0, 1};
int i;
/* when called while moving in mixed mode, do not draw when... */
if ((drawflags & MAN_SCALE_C) == 0) return;
manipulator_axis_order(rv3d, axis_order);
glDisable(GL_DEPTH_TEST);
/* not in combo mode */
if ((combo & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE)) == 0) {
float size, unitmat[4][4];
int shift = 0; // XXX
/* center circle, do not add to selection when shift is pressed (planar constraint) */
if ((G.f & G_PICKSEL) && shift == 0) glLoadName(MAN_SCALE_C);
manipulator_setcolor(v3d, 'C', colcode, 255);
glPushMatrix();
size = screen_aligned(rv3d, rv3d->twmat);
unit_m4(unitmat);
drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
glPopMatrix();
dz = 1.0;
}
else {
dz = 1.0f - 4.0f * cusize;
}
if (moving) {
float matt[4][4];
copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
glMultMatrixf(matt);
glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
}
else {
glMultMatrixf(rv3d->twmat);
glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
}
/* axis */
/* in combo mode, this is always drawn as first type */
draw_manipulator_axes(v3d, rv3d, colcode,
drawflags & MAN_SCALE_X, drawflags & MAN_SCALE_Y, drawflags & MAN_SCALE_Z,
axis_order);
for (i = 0; i < 3; i++) {
switch (axis_order[i]) {
case 0: /* X cube */
if (drawflags & MAN_SCALE_X) {
glTranslatef(dz, 0.0, 0.0);
if (G.f & G_PICKSEL) glLoadName(MAN_SCALE_X);
manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->twangle[0]));
drawsolidcube(cusize);
glTranslatef(-dz, 0.0, 0.0);
}
break;
case 1: /* Y cube */
if (drawflags & MAN_SCALE_Y) {
glTranslatef(0.0, dz, 0.0);
if (G.f & G_PICKSEL) glLoadName(MAN_SCALE_Y);
manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->twangle[1]));
drawsolidcube(cusize);
glTranslatef(0.0, -dz, 0.0);
}
break;
case 2: /* Z cube */
if (drawflags & MAN_SCALE_Z) {
glTranslatef(0.0, 0.0, dz);
if (G.f & G_PICKSEL) glLoadName(MAN_SCALE_Z);
manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->twangle[2]));
drawsolidcube(cusize);
glTranslatef(0.0, 0.0, -dz);
}
break;
}
}
/* if shiftkey, center point as last, for selectbuffer order */
if (G.f & G_PICKSEL) {
int shift = 0; // XXX
if (shift) {
glTranslatef(0.0, -dz, 0.0);
glLoadName(MAN_SCALE_C);
glBegin(GL_POINTS);
glVertex3f(0.0, 0.0, 0.0);
glEnd();
}
}
/* restore */
glLoadMatrixf(rv3d->viewmat);
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW);
}
static void draw_cone(GLUquadricObj *qobj, float len, float width)
{
glTranslatef(0.0, 0.0, -0.5f * len);
gluCylinder(qobj, width, 0.0, len, 8, 1);
gluQuadricOrientation(qobj, GLU_INSIDE);
gluDisk(qobj, 0.0, width, 8, 1);
gluQuadricOrientation(qobj, GLU_OUTSIDE);
glTranslatef(0.0, 0.0, 0.5f * len);
}
static void draw_cylinder(GLUquadricObj *qobj, float len, float width)
{
width *= 0.8f; // just for beauty
glTranslatef(0.0, 0.0, -0.5f * len);
gluCylinder(qobj, width, width, len, 8, 1);
gluQuadricOrientation(qobj, GLU_INSIDE);
gluDisk(qobj, 0.0, width, 8, 1);
gluQuadricOrientation(qobj, GLU_OUTSIDE);
glTranslatef(0.0, 0.0, len);
gluDisk(qobj, 0.0, width, 8, 1);
glTranslatef(0.0, 0.0, -0.5f * len);
}
static void draw_manipulator_translate(View3D *v3d, RegionView3D *rv3d, int UNUSED(moving), int drawflags, int combo, int colcode)
{
GLUquadricObj *qobj;
float cylen = 0.01f * (float)U.tw_handlesize;
float cywid = 0.25f * cylen, dz, size;
float unitmat[4][4];
int shift = 0; // XXX
int axis_order[3] = {0, 1, 2};
int i;
/* when called while moving in mixed mode, do not draw when... */
if ((drawflags & MAN_TRANS_C) == 0) return;
manipulator_axis_order(rv3d, axis_order);
// XXX if (moving) glTranslatef(t->vec[0], t->vec[1], t->vec[2]);
glDisable(GL_DEPTH_TEST);
/* center circle, do not add to selection when shift is pressed (planar constraint) */
if ((G.f & G_PICKSEL) && shift == 0) glLoadName(MAN_TRANS_C);
manipulator_setcolor(v3d, 'C', colcode, 255);
glPushMatrix();
size = screen_aligned(rv3d, rv3d->twmat);
unit_m4(unitmat);
drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
glPopMatrix();
/* and now apply matrix, we move to local matrix drawing */
glMultMatrixf(rv3d->twmat);
/* axis */
glLoadName(-1);
// translate drawn as last, only axis when no combo with scale, or for ghosting
if ((combo & V3D_MANIP_SCALE) == 0 || colcode == MAN_GHOST) {
draw_manipulator_axes(v3d, rv3d, colcode,
drawflags & MAN_TRANS_X, drawflags & MAN_TRANS_Y, drawflags & MAN_TRANS_Z,
axis_order);
}
/* offset in combo mode, for rotate a bit more */
if (combo & (V3D_MANIP_ROTATE)) dz = 1.0f + 2.0f * cylen;
else if (combo & (V3D_MANIP_SCALE)) dz = 1.0f + 0.5f * cylen;
else dz = 1.0f;
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
for (i = 0; i < 3; i++) {
switch (axis_order[i]) {
case 0: /* Z Cone */
if (drawflags & MAN_TRANS_Z) {
glTranslatef(0.0, 0.0, dz);
if (G.f & G_PICKSEL) glLoadName(MAN_TRANS_Z);
manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->twangle[2]));
draw_cone(qobj, cylen, cywid);
glTranslatef(0.0, 0.0, -dz);
}
break;
case 1: /* X Cone */
if (drawflags & MAN_TRANS_X) {
glTranslatef(dz, 0.0, 0.0);
if (G.f & G_PICKSEL) glLoadName(MAN_TRANS_X);
glRotatef(90.0, 0.0, 1.0, 0.0);
manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->twangle[0]));
draw_cone(qobj, cylen, cywid);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(-dz, 0.0, 0.0);
}
break;
case 2: /* Y Cone */
if (drawflags & MAN_TRANS_Y) {
glTranslatef(0.0, dz, 0.0);
if (G.f & G_PICKSEL) glLoadName(MAN_TRANS_Y);
glRotatef(-90.0, 1.0, 0.0, 0.0);
manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->twangle[1]));
draw_cone(qobj, cylen, cywid);
glRotatef(90.0, 1.0, 0.0, 0.0);
glTranslatef(0.0, -dz, 0.0);
}
break;
}
}
gluDeleteQuadric(qobj);
glLoadMatrixf(rv3d->viewmat);
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
}
static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int moving, int drawflags, int combo, int colcode)
{
GLUquadricObj *qobj;
float size;
float cylen = 0.01f * (float)U.tw_handlesize;
float cywid = 0.25f * cylen;
int axis_order[3] = {2, 0, 1};
int i;
/* when called while moving in mixed mode, do not draw when... */
if ((drawflags & MAN_ROT_C) == 0) return;
manipulator_axis_order(rv3d, axis_order);
/* prepare for screen aligned draw */
glPushMatrix();
size = screen_aligned(rv3d, rv3d->twmat);
glDisable(GL_DEPTH_TEST);
qobj = gluNewQuadric();
/* Screen aligned view rot circle */
if (drawflags & MAN_ROT_V) {
float unitmat[4][4] = MAT4_UNITY;
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_V);
UI_ThemeColor(TH_TRANSFORM);
drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
if (moving) {
float vec[3];
vec[0] = 0; // XXX (float)(t->imval[0] - t->center2d[0]);
vec[1] = 0; // XXX (float)(t->imval[1] - t->center2d[1]);
vec[2] = 0.0f;
normalize_v3(vec);
mul_v3_fl(vec, 1.2f * size);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3fv(vec);
glEnd();
}
}
glPopMatrix();
/* apply the transform delta */
if (moving) {
float matt[4][4];
copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
// XXX if (t->flag & T_USES_MANIPULATOR) {
// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
// XXX }
glMultMatrixf(matt);
}
else {
glMultMatrixf(rv3d->twmat);
}
glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
/* axis */
if ((G.f & G_PICKSEL) == 0) {
// only draw axis when combo didn't draw scale axes
if ((combo & V3D_MANIP_SCALE) == 0) {
draw_manipulator_axes(v3d, rv3d, colcode,
drawflags & MAN_ROT_X, drawflags & MAN_ROT_Y, drawflags & MAN_ROT_Z,
axis_order);
}
/* only has to be set when not in picking */
gluQuadricDrawStyle(qobj, GLU_FILL);
}
for (i = 0; i < 3; i++) {
switch (axis_order[i]) {
case 0: /* X cylinder */
if (drawflags & MAN_ROT_X) {
glTranslatef(1.0, 0.0, 0.0);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_X);
glRotatef(90.0, 0.0, 1.0, 0.0);
manipulator_setcolor(v3d, 'X', colcode, 255);
draw_cylinder(qobj, cylen, cywid);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(-1.0, 0.0, 0.0);
}
break;
case 1: /* Y cylinder */
if (drawflags & MAN_ROT_Y) {
glTranslatef(0.0, 1.0, 0.0);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Y);
glRotatef(-90.0, 1.0, 0.0, 0.0);
manipulator_setcolor(v3d, 'Y', colcode, 255);
draw_cylinder(qobj, cylen, cywid);
glRotatef(90.0, 1.0, 0.0, 0.0);
glTranslatef(0.0, -1.0, 0.0);
}
break;
case 2: /* Z cylinder */
if (drawflags & MAN_ROT_Z) {
glTranslatef(0.0, 0.0, 1.0);
if (G.f & G_PICKSEL) glLoadName(MAN_ROT_Z);
manipulator_setcolor(v3d, 'Z', colcode, 255);
draw_cylinder(qobj, cylen, cywid);
glTranslatef(0.0, 0.0, -1.0);
}
break;
}
}
/* restore */
gluDeleteQuadric(qobj);
glLoadMatrixf(rv3d->viewmat);
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
}
/* ********************************************* */
/* main call, does calc centers & orientation too */
static int drawflags = 0xFFFF; // only for the calls below, belongs in scene...?
void BIF_draw_manipulator(const bContext *C)
{
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d = sa->spacedata.first;
RegionView3D *rv3d = ar->regiondata;
int totsel;
if (!(v3d->twflag & V3D_USE_MANIPULATOR)) return;
{
v3d->twflag &= ~V3D_DRAW_MANIPULATOR;
totsel = calc_manipulator_stats(C);
if (totsel == 0) return;
v3d->twflag |= V3D_DRAW_MANIPULATOR;
/* now we can define center */
switch (v3d->around) {
case V3D_CENTER:
case V3D_ACTIVE:
{
Object *ob;
if (((v3d->around == V3D_ACTIVE) && (scene->obedit == NULL)) &&
((ob = OBACT) && !(ob->mode & OB_MODE_POSE)))
{
copy_v3_v3(rv3d->twmat[3], ob->obmat[3]);
}
else {
mid_v3_v3v3(rv3d->twmat[3], scene->twmin, scene->twmax);
}
break;
}
case V3D_LOCAL:
case V3D_CENTROID:
copy_v3_v3(rv3d->twmat[3], scene->twcent);
break;
case V3D_CURSOR:
copy_v3_v3(rv3d->twmat[3], ED_view3d_cursor3d_get(scene, v3d));
break;
}
mul_mat3_m4_fl(rv3d->twmat, ED_view3d_pixel_size(rv3d, rv3d->twmat[3]) * U.tw_size);
}
/* when looking through a selected camera, the manipulator can be at the
* exact same position as the view, skip so we don't break selection */
if (fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f)
return;
test_manipulator_axis(C);
drawflags = rv3d->twdrawflag; /* set in calc_manipulator_stats */
if (v3d->twflag & V3D_DRAW_MANIPULATOR) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
if (v3d->twtype & V3D_MANIP_ROTATE) {
if (G.debug_value == 3) {
if (G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT))
draw_manipulator_rotate_cyl(v3d, rv3d, 1, drawflags, v3d->twtype, MAN_MOVECOL);
else
draw_manipulator_rotate_cyl(v3d, rv3d, 0, drawflags, v3d->twtype, MAN_RGB);
}
else
draw_manipulator_rotate(v3d, rv3d, 0, drawflags, v3d->twtype);
}
if (v3d->twtype & V3D_MANIP_SCALE) {
draw_manipulator_scale(v3d, rv3d, 0, drawflags, v3d->twtype, MAN_RGB);
}
if (v3d->twtype & V3D_MANIP_TRANSLATE) {
draw_manipulator_translate(v3d, rv3d, 0, drawflags, v3d->twtype, MAN_RGB);
}
glDisable(GL_BLEND);
}
}
static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], float hotspot)
{
View3D *v3d = sa->spacedata.first;
RegionView3D *rv3d = ar->regiondata;
rctf rect;
GLuint buffer[64]; // max 4 items per select, so large enuf
short hits;
extern void setwinmatrixview3d(ARegion *, View3D *, rctf *); // XXX check a bit later on this... (ton)
/* when looking through a selected camera, the manipulator can be at the
* exact same position as the view, skip so we don't break selection */
if (fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f)
return 0;
G.f |= G_PICKSEL;
rect.xmin = mval[0] - hotspot;
rect.xmax = mval[0] + hotspot;
rect.ymin = mval[1] - hotspot;
rect.ymax = mval[1] + hotspot;
setwinmatrixview3d(ar, v3d, &rect);
mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
glSelectBuffer(64, buffer);
glRenderMode(GL_SELECT);
glInitNames(); /* these two calls whatfor? It doesnt work otherwise */
glPushName(-2);
/* do the drawing */
if (v3d->twtype & V3D_MANIP_ROTATE) {
if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, 0, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB);
else draw_manipulator_rotate(v3d, rv3d, 0, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype);
}
if (v3d->twtype & V3D_MANIP_SCALE)
draw_manipulator_scale(v3d, rv3d, 0, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB);
if (v3d->twtype & V3D_MANIP_TRANSLATE)
draw_manipulator_translate(v3d, rv3d, 0, MAN_TRANS_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB);
glPopName();
hits = glRenderMode(GL_RENDER);
G.f &= ~G_PICKSEL;
setwinmatrixview3d(ar, v3d, NULL);
mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
if (hits == 1) return buffer[3];
else if (hits > 1) {
GLuint val, dep, mindep = 0, mindeprot = 0, minval = 0, minvalrot = 0;
int a;
/* we compare the hits in buffer, but value centers highest */
/* we also store the rotation hits separate (because of arcs) and return hits on other widgets if there are */
for (a = 0; a < hits; a++) {
dep = buffer[4 * a + 1];
val = buffer[4 * a + 3];
if (val == MAN_TRANS_C) {
return MAN_TRANS_C;
}
else if (val == MAN_SCALE_C) {
return MAN_SCALE_C;
}
else {
if (val & MAN_ROT_C) {
if (minvalrot == 0 || dep < mindeprot) {
mindeprot = dep;
minvalrot = val;
}
}
else {
if (minval == 0 || dep < mindep) {
mindep = dep;
minval = val;
}
}
}
}
if (minval)
return minval;
else
return minvalrot;
}
return 0;
}
/* return 0; nothing happened */
int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmOperator *op)
{
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = sa->spacedata.first;
ARegion *ar = CTX_wm_region(C);
int constraint_axis[3] = {0, 0, 0};
int val;
int shift = event->shift;
if (!(v3d->twflag & V3D_USE_MANIPULATOR)) return 0;
if (!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return 0;
/* Force orientation */
RNA_enum_set(op->ptr, "constraint_orientation", v3d->twmode);
// find the hotspots first test narrow hotspot
val = manipulator_selectbuf(sa, ar, event->mval, 0.5f * (float)U.tw_hotspot);
if (val) {
// drawflags still global, for drawing call above
drawflags = manipulator_selectbuf(sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
if (drawflags == 0) drawflags = val;
if (drawflags & MAN_TRANS_C) {
switch (drawflags) {
case MAN_TRANS_C:
break;
case MAN_TRANS_X:
if (shift) {
constraint_axis[1] = 1;
constraint_axis[2] = 1;
}
else
constraint_axis[0] = 1;
break;
case MAN_TRANS_Y:
if (shift) {
constraint_axis[0] = 1;
constraint_axis[2] = 1;
}
else
constraint_axis[1] = 1;
break;
case MAN_TRANS_Z:
if (shift) {
constraint_axis[0] = 1;
constraint_axis[1] = 1;
}
else
constraint_axis[2] = 1;
break;
}
RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
WM_operator_name_call(C, "TRANSFORM_OT_translate", WM_OP_INVOKE_DEFAULT, op->ptr);
//wm_operator_invoke(C, WM_operatortype_find("TRANSFORM_OT_translate", 0), event, op->ptr, NULL, FALSE);
}
else if (drawflags & MAN_SCALE_C) {
switch (drawflags) {
case MAN_SCALE_X:
if (shift) {
constraint_axis[1] = 1;
constraint_axis[2] = 1;
}
else
constraint_axis[0] = 1;
break;
case MAN_SCALE_Y:
if (shift) {
constraint_axis[0] = 1;
constraint_axis[2] = 1;
}
else
constraint_axis[1] = 1;
break;
case MAN_SCALE_Z:
if (shift) {
constraint_axis[0] = 1;
constraint_axis[1] = 1;
}
else
constraint_axis[2] = 1;
break;
}
RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
WM_operator_name_call(C, "TRANSFORM_OT_resize", WM_OP_INVOKE_DEFAULT, op->ptr);
//wm_operator_invoke(C, WM_operatortype_find("TRANSFORM_OT_resize", 0), event, op->ptr, NULL, FALSE);
}
else if (drawflags == MAN_ROT_T) { /* trackball need special case, init is different */
/* Do not pass op->ptr!!! trackball has no "constraint" properties!
* See [#34621], it's a miracle it did not cause more problems!!! */
/* However, we need to copy the "release_confirm" property... */
PointerRNA props_ptr;
wmOperatorType *ot = WM_operatortype_find("TRANSFORM_OT_trackball", true);
WM_operator_properties_create_ptr(&props_ptr, ot);
RNA_boolean_set(&props_ptr, "release_confirm", RNA_boolean_get(op->ptr, "release_confirm"));
WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, &props_ptr);
//wm_operator_invoke(C, WM_operatortype_find(ot->idname, 0), event, NULL, NULL, FALSE);
WM_operator_properties_free(&props_ptr);
}
else if (drawflags & MAN_ROT_C) {
switch (drawflags) {
case MAN_ROT_X:
constraint_axis[0] = 1;
break;
case MAN_ROT_Y:
constraint_axis[1] = 1;
break;
case MAN_ROT_Z:
constraint_axis[2] = 1;
break;
}
RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
WM_operator_name_call(C, "TRANSFORM_OT_rotate", WM_OP_INVOKE_DEFAULT, op->ptr);
//wm_operator_invoke(C, WM_operatortype_find("TRANSFORM_OT_rotate", 0), event, op->ptr, NULL, FALSE);
}
}
/* after transform, restore drawflags */
drawflags = 0xFFFF;
return val;
}
|