@@ -362,7 +362,39 @@ static void markselected(const mjVisual* vis, mjvGeom* geom) {
362
362
363
363
364
364
365
- //----------------------------- camera functions ---------------------------------------------------
365
+ // draw 3 cylinders representing a "frame" decor element
366
+ void addFrameGeoms (mjvScene * scn , int i , mjtNum * pos , mjtNum * rot , float length , float width ) {
367
+ // draw separate geoms for each axis
368
+ for (int j = 0 ; j < 3 ; j ++ ) {
369
+ mjtNum axis [3 ];
370
+ for (int k = 0 ; k < 3 ; k ++ ) {
371
+ axis [k ] = (j == k ? length : 0 );
372
+ }
373
+
374
+ mjtNum vec [3 ];
375
+ mju_mulMatVec (vec , rot , axis , 3 , 3 );
376
+
377
+ // create a cylinder
378
+ mjtNum to [3 ];
379
+ mju_add3 (to , pos , vec );
380
+
381
+ mjvGeom * thisgeom = acquireGeom (scn , i , mjCAT_DECOR , mjOBJ_UNKNOWN );
382
+ if (!thisgeom ) {
383
+ return ;
384
+ }
385
+
386
+ mjv_connector (thisgeom , mjGEOM_CYLINDER , width , pos , to );
387
+ for (int k = 0 ; k < 3 ; k ++ ) {
388
+ thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
389
+ }
390
+ thisgeom -> rgba [3 ] = 1 ;
391
+ releaseGeom (& thisgeom , scn );
392
+ }
393
+ }
394
+
395
+
396
+
397
+ //----------------------------- camera functions --------------------------------------------------
366
398
367
399
// computes the camera frustum
368
400
static void getFrustum (float zver [2 ], float zhor [2 ], float znear ,
@@ -509,7 +541,7 @@ void mjv_cameraFrustum(float zver[2], float zhor[2], float zclip[2], const mjMod
509
541
static void addContactGeom (const mjModel * m , mjData * d , const mjtByte * flags ,
510
542
const mjvOption * vopt , mjvScene * scn ) {
511
543
int objtype = mjOBJ_UNKNOWN , category = mjCAT_DECOR ;
512
- mjtNum mat [9 ], tmp [9 ], vec [3 ], frc [3 ], confrc [6 ], axis [ 3 ] ;
544
+ mjtNum mat [9 ], tmp [9 ], vec [3 ], frc [3 ], confrc [6 ];
513
545
mjtNum framewidth , framelength , scl = m -> stat .meansize ;
514
546
mjContact * con ;
515
547
mjvGeom * thisgeom ;
@@ -614,34 +646,7 @@ static void addContactGeom(const mjModel* m, mjData* d, const mjtByte* flags,
614
646
// set length and width of axis cylinders using half regular frame scaling
615
647
framelength = m -> vis .scale .framelength * scl / 2 ;
616
648
framewidth = m -> vis .scale .framewidth * scl / 2 ;
617
-
618
- // draw the three axes (separate geoms)
619
- for (int j = 0 ; j < 3 ; j ++ ) {
620
- thisgeom = acquireGeom (scn , i , category , objtype );
621
- if (!thisgeom ) {
622
- return ;
623
- }
624
-
625
- // prepare axis
626
- for (int k = 0 ; k < 3 ; k ++ ) {
627
- axis [k ] = (j == k ? framelength : 0 );
628
- }
629
- mju_mulMatVec (vec , mat , axis , 3 , 3 );
630
-
631
- // create a cylinder
632
- mjtNum * from = con -> pos ;
633
- mjtNum to [3 ];
634
- mju_add3 (to , from , vec );
635
- mjv_connector (thisgeom , mjGEOM_CYLINDER , framewidth , from , to );
636
-
637
- // set color: R, G or B depending on axis
638
- for (int k = 0 ; k < 3 ; k ++ ) {
639
- thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
640
- }
641
- thisgeom -> rgba [3 ] = 1 ;
642
-
643
- releaseGeom (& thisgeom , scn );
644
- }
649
+ addFrameGeoms (scn , i , con -> pos , mat , framelength , framewidth );
645
650
}
646
651
647
652
// nothing else to do for excluded contacts
@@ -1302,34 +1307,7 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
1302
1307
1303
1308
mjtNum * xmat = vopt -> flags [mjVIS_INERTIA ] ? d -> ximat + 9 * i : d -> xmat + 9 * i ;
1304
1309
mjtNum * xpos = vopt -> flags [mjVIS_INERTIA ] ? d -> xipos + 3 * i : d -> xpos + 3 * i ;
1305
-
1306
- // draw the three axes (separate geoms)
1307
- for (int j = 0 ; j < 3 ; j ++ ) {
1308
- thisgeom = acquireGeom (scn , i , category , objtype );
1309
- if (!thisgeom ) {
1310
- return ;
1311
- }
1312
-
1313
- // prepare axis
1314
- for (int k = 0 ; k < 3 ; k ++ ) {
1315
- axis [k ] = (j == k ? sz [1 ] : 0 );
1316
- }
1317
- mju_mulMatVec (vec , xmat , axis , 3 , 3 );
1318
-
1319
- // create a cylinder
1320
- mjtNum * from = xpos ;
1321
- mjtNum to [3 ];
1322
- mju_add3 (to , from , vec );
1323
- mjv_connector (thisgeom , mjGEOM_CYLINDER , sz [0 ], from , to );
1324
-
1325
- // set color: R, G or B depending on axis
1326
- for (int k = 0 ; k < 3 ; k ++ ) {
1327
- thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
1328
- }
1329
- thisgeom -> rgba [3 ] = 1 ;
1330
-
1331
- releaseGeom (& thisgeom , scn );
1332
- }
1310
+ addFrameGeoms (scn , i , xpos , xmat , sz [1 ], sz [0 ]);
1333
1311
}
1334
1312
}
1335
1313
@@ -1839,32 +1817,7 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
1839
1817
objtype = mjOBJ_UNKNOWN ;
1840
1818
sz [0 ] = m -> vis .scale .framewidth * scl ;
1841
1819
sz [1 ] = m -> vis .scale .framelength * scl ;
1842
- for (int j = 0 ; j < 3 ; j ++ ) {
1843
- thisgeom = acquireGeom (scn , i , category , objtype );
1844
- if (!thisgeom ) {
1845
- return ;
1846
- }
1847
-
1848
- // prepare axis
1849
- for (int k = 0 ; k < 3 ; k ++ ) {
1850
- axis [k ] = (j == k ? sz [1 ] : 0 );
1851
- }
1852
- mju_mulMatVec (vec , d -> geom_xmat + 9 * i , axis , 3 , 3 );
1853
-
1854
- // create a cylinder
1855
- mjtNum * from = d -> geom_xpos + 3 * i ;
1856
- mjtNum to [3 ];
1857
- mju_add3 (to , from , vec );
1858
- mjv_connector (thisgeom , mjGEOM_CYLINDER , sz [0 ], from , to );
1859
-
1860
- // set color: R, G or B depending on axis
1861
- for (int k = 0 ; k < 3 ; k ++ ) {
1862
- thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
1863
- }
1864
- thisgeom -> rgba [3 ] = 1 ;
1865
-
1866
- releaseGeom (& thisgeom , scn );
1867
- }
1820
+ addFrameGeoms (scn , i , d -> geom_xpos + 3 * i , d -> geom_xmat + 9 * i , sz [1 ], sz [0 ]);
1868
1821
}
1869
1822
}
1870
1823
@@ -1920,32 +1873,7 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
1920
1873
objtype = mjOBJ_UNKNOWN ;
1921
1874
sz [0 ] = m -> vis .scale .framewidth * scl ;
1922
1875
sz [1 ] = m -> vis .scale .framelength * scl ;
1923
- for (int j = 0 ; j < 3 ; j ++ ) {
1924
- thisgeom = acquireGeom (scn , i , category , objtype );
1925
- if (!thisgeom ) {
1926
- return ;
1927
- }
1928
-
1929
- // prepare axis
1930
- for (int k = 0 ; k < 3 ; k ++ ) {
1931
- axis [k ] = (j == k ? sz [1 ] : 0 );
1932
- }
1933
- mju_mulMatVec (vec , d -> site_xmat + 9 * i , axis , 3 , 3 );
1934
-
1935
- // create a cylinder
1936
- mjtNum * from = d -> site_xpos + 3 * i ;
1937
- mjtNum to [3 ];
1938
- mju_add3 (to , from , vec );
1939
- mjv_connector (thisgeom , mjGEOM_CYLINDER , sz [0 ], from , to );
1940
-
1941
- // set color: R, G or B depending on axis
1942
- for (int k = 0 ; k < 3 ; k ++ ) {
1943
- thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
1944
- }
1945
- thisgeom -> rgba [3 ] = 1 ;
1946
-
1947
- releaseGeom (& thisgeom , scn );
1948
- }
1876
+ addFrameGeoms (scn , i , d -> site_xpos + 3 * i , d -> site_xmat + 9 * i , sz [1 ], sz [0 ]);
1949
1877
}
1950
1878
}
1951
1879
@@ -2105,32 +2033,7 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
2105
2033
objtype = mjOBJ_UNKNOWN ;
2106
2034
sz [0 ] = m -> vis .scale .framewidth * scl ;
2107
2035
sz [1 ] = m -> vis .scale .framelength * scl ;
2108
- for (int j = 0 ; j < 3 ; j ++ ) {
2109
- thisgeom = acquireGeom (scn , i , category , objtype );
2110
- if (!thisgeom ) {
2111
- return ;
2112
- }
2113
-
2114
- // prepare axis
2115
- for (int k = 0 ; k < 3 ; k ++ ) {
2116
- axis [k ] = (j == k ? sz [1 ] : 0 );
2117
- }
2118
- mju_mulMatVec (vec , d -> cam_xmat + 9 * i , axis , 3 , 3 );
2119
-
2120
- // create a cylinder
2121
- mjtNum * from = d -> cam_xpos + 3 * i ;
2122
- mjtNum to [3 ];
2123
- mju_add3 (to , from , vec );
2124
- mjv_connector (thisgeom , mjGEOM_CYLINDER , sz [0 ], from , to );
2125
-
2126
- // set color: R, G or B depending on axis
2127
- for (int k = 0 ; k < 3 ; k ++ ) {
2128
- thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
2129
- }
2130
- thisgeom -> rgba [3 ] = 1 ;
2131
-
2132
- releaseGeom (& thisgeom , scn );
2133
- }
2036
+ addFrameGeoms (scn , i , d -> cam_xpos + 3 * i , d -> cam_xmat + 9 * i , sz [1 ], sz [0 ]);
2134
2037
}
2135
2038
}
2136
2039
@@ -2178,32 +2081,7 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
2178
2081
objtype = mjOBJ_UNKNOWN ;
2179
2082
sz [0 ] = m -> vis .scale .framewidth * scl ;
2180
2083
sz [1 ] = m -> vis .scale .framelength * scl ;
2181
- for (int j = 0 ; j < 3 ; j ++ ) {
2182
- thisgeom = acquireGeom (scn , i , category , objtype );
2183
- if (!thisgeom ) {
2184
- return ;
2185
- }
2186
-
2187
- // prepare axis
2188
- for (int k = 0 ; k < 3 ; k ++ ) {
2189
- axis [k ] = (j == k ? sz [1 ] : 0 );
2190
- }
2191
- mju_mulMatVec (vec , mat , axis , 3 , 3 );
2192
-
2193
- // create a cylinder
2194
- mjtNum * from = d -> light_xpos + 3 * i ;
2195
- mjtNum to [3 ];
2196
- mju_add3 (to , from , vec );
2197
- mjv_connector (thisgeom , mjGEOM_CYLINDER , sz [0 ], from , to );
2198
-
2199
- // set color: R, G or B depending on axis
2200
- for (int k = 0 ; k < 3 ; k ++ ) {
2201
- thisgeom -> rgba [k ] = (j == k ? 0.9 : 0 );
2202
- }
2203
- thisgeom -> rgba [3 ] = 1 ;
2204
-
2205
- releaseGeom (& thisgeom , scn );
2206
- }
2084
+ addFrameGeoms (scn , i , d -> light_xpos + 3 * i , mat , sz [1 ], sz [0 ]);
2207
2085
}
2208
2086
}
2209
2087
0 commit comments