@@ -590,6 +590,7 @@ void GPUDisplay::ReSizeGLScene(int width, int height, bool init)
590590 if (init) {
591591 mResetScene = 1 ;
592592 mViewMatrix = MY_HMM_IDENTITY;
593+ mModelMatrix = MY_HMM_IDENTITY;
593594 }
594595}
595596
@@ -1350,6 +1351,8 @@ int GPUDisplay::DrawGLScene_internal(bool mixAnimation, float mAnimateTime)
13501351 mBackend ->mMouseWheel = 0 ;
13511352 bool lookOrigin = mCamLookOrigin ^ mBackend ->mKeys [mBackend ->KEY_ALT ];
13521353 bool yUp = mCamYUp ^ mBackend ->mKeys [mBackend ->KEY_CTRL ] ^ lookOrigin;
1354+ bool rotateModel = mBackend ->mKeys [mBackend ->KEY_RCTRL ] || mBackend ->mKeys [mBackend ->KEY_RALT ];
1355+ bool rotateModelTPC = mBackend ->mKeys [mBackend ->KEY_RALT ];
13531356
13541357 // Calculate rotation / translation scaling factors
13551358 float scalefactor = mBackend ->mKeys [mBackend ->KEY_SHIFT ] ? 0.2 : 1.0 ;
@@ -1465,6 +1468,8 @@ int GPUDisplay::DrawGLScene_internal(bool mixAnimation, float mAnimateTime)
14651468 }
14661469 } else if (mResetScene ) {
14671470 nextViewMatrix = nextViewMatrix * HMM_Translate ({0 , 0 , param ().par .ContinuousTracking ? (-mMaxClusterZ / GL_SCALE_FACTOR - 8 ) : -8 });
1471+ mViewMatrix = MY_HMM_IDENTITY;
1472+ mModelMatrix = MY_HMM_IDENTITY;
14681473
14691474 mCfg .pointSize = 2.0 ;
14701475 mCfg .drawSlice = -1 ;
@@ -1548,22 +1553,37 @@ int GPUDisplay::DrawGLScene_internal(bool mixAnimation, float mAnimateTime)
15481553 nextViewMatrix = nextViewMatrix * HMM_LookAt ({mXYZ [0 ], mXYZ [1 ], mXYZ [2 ]}, {0 , 0 , 0 }, {0 , 1 , 0 });
15491554 } else {
15501555 nextViewMatrix = nextViewMatrix * HMM_Translate ({moveX, moveY, moveZ});
1551- if (rotYaw != 0 .f ) {
1552- nextViewMatrix = nextViewMatrix * HMM_Rotate (rotYaw, {0 , 1 , 0 });
1553- }
1554- if (rotPitch != 0 .f ) {
1555- nextViewMatrix = nextViewMatrix * HMM_Rotate (rotPitch, {1 , 0 , 0 });
1556- }
1557- if (!yUp && rotRoll != 0 .f ) {
1558- nextViewMatrix = nextViewMatrix * HMM_Rotate (rotRoll, {0 , 0 , 1 });
1556+ if (!rotateModel) {
1557+ if (rotYaw != 0 .f ) {
1558+ nextViewMatrix = nextViewMatrix * HMM_Rotate (rotYaw, {0 , 1 , 0 });
1559+ }
1560+ if (rotPitch != 0 .f ) {
1561+ nextViewMatrix = nextViewMatrix * HMM_Rotate (rotPitch, {1 , 0 , 0 });
1562+ }
1563+ if (!yUp && rotRoll != 0 .f ) {
1564+ nextViewMatrix = nextViewMatrix * HMM_Rotate (rotRoll, {0 , 0 , 1 });
1565+ }
15591566 }
1560-
15611567 nextViewMatrix = nextViewMatrix * mViewMatrix ; // Apply previous translation / rotation
1562-
15631568 if (yUp) {
15641569 calcXYZ (&nextViewMatrix.Elements [0 ][0 ]);
15651570 nextViewMatrix = HMM_Rotate (mAngle [2 ] * 180 .f / M_PI, {0 , 0 , 1 }) * nextViewMatrix;
15661571 }
1572+ if (rotateModel) {
1573+ if (rotYaw != 0 .f ) {
1574+ mModelMatrix = HMM_Rotate (rotYaw, {nextViewMatrix.Elements [0 ][1 ], nextViewMatrix.Elements [1 ][1 ], nextViewMatrix.Elements [2 ][1 ]}) * mModelMatrix ;
1575+ }
1576+ if (rotPitch != 0 .f ) {
1577+ mModelMatrix = HMM_Rotate (rotPitch, {nextViewMatrix.Elements [0 ][0 ], nextViewMatrix.Elements [1 ][0 ], nextViewMatrix.Elements [2 ][0 ]}) * mModelMatrix ;
1578+ }
1579+ if (rotRoll != 0 .f ) {
1580+ if (rotateModelTPC) {
1581+ mModelMatrix = HMM_Rotate (-rotRoll, {0 , 0 , 1 }) * mModelMatrix ;
1582+ } else {
1583+ mModelMatrix = HMM_Rotate (-rotRoll, {nextViewMatrix.Elements [0 ][2 ], nextViewMatrix.Elements [1 ][2 ], nextViewMatrix.Elements [2 ][2 ]}) * mModelMatrix ;
1584+ }
1585+ }
1586+ }
15671587 }
15681588
15691589 // Graphichs Options
@@ -1835,6 +1855,7 @@ int GPUDisplay::DrawGLScene_internal(bool mixAnimation, float mAnimateTime)
18351855 {
18361856 const float zFar = ((param ().par .ContinuousTracking ? (mMaxClusterZ / GL_SCALE_FACTOR) : 8 .f ) + 50 .f ) * 2 .f ;
18371857 const hmm_mat4 proj = HMM_Perspective (mFOV , (GLfloat)mScreenwidth / (GLfloat)mScreenheight , 0 .1f , zFar);
1858+ nextViewMatrix = nextViewMatrix * mModelMatrix ;
18381859#ifndef GPUCA_DISPLAY_OPENGL_CORE
18391860 CHKERR (glMatrixMode (GL_PROJECTION));
18401861 CHKERR (glLoadMatrixf (&proj.Elements [0 ][0 ]));
0 commit comments