Skip to content

Commit e2e708e

Browse files
committed
3D views: alternative pan mouse control
1 parent 4290b6e commit e2e708e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

libs/gui/src/CGlCanvasBase.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
+------------------------------------------------------------------------+ */
99

1010
#include "gui-precomp.h" // Precompiled headers
11+
#include "mrpt/math/geometry.h"
1112
//
1213
#include <mrpt/core/round.h>
1314
#include <mrpt/gui/CGlCanvasBase.h>
@@ -142,10 +143,19 @@ void CGlCanvasBase::updatePan(CamaraParams& params, int x, int y) const
142143
float Ay = -(x - m_mouseClickX);
143144
float Ax = -(y - m_mouseClickY);
144145
float D = 0.001f * params.cameraZoomDistance;
145-
params.cameraPointingX +=
146-
D * (Ax * cos(DEG2RAD(params.cameraAzimuthDeg)) - Ay * sin(DEG2RAD(params.cameraAzimuthDeg)));
147-
params.cameraPointingY +=
148-
D * (Ax * sin(DEG2RAD(params.cameraAzimuthDeg)) + Ay * cos(DEG2RAD(params.cameraAzimuthDeg)));
146+
147+
const double cos_az = cos(DEG2RAD(params.cameraAzimuthDeg));
148+
const double sin_az = sin(DEG2RAD(params.cameraAzimuthDeg));
149+
const double cos_el = cos(DEG2RAD(params.cameraElevationDeg));
150+
const double sin_el = sin(DEG2RAD(params.cameraElevationDeg));
151+
152+
const auto forward = mrpt::math::TVector3D(-cos_az * cos_el, -sin_az * cos_el, -sin_el);
153+
const auto up = mrpt::math::TVector3D(-cos_az * sin_el, -sin_az * sin_el, -cos_el);
154+
const auto right = mrpt::math::crossProduct3D(forward, up);
155+
156+
params.cameraPointingX += D * (Ay * right.x - Ax * up.x);
157+
params.cameraPointingY += D * (Ay * right.y - Ax * up.y);
158+
params.cameraPointingZ += D * (Ay * right.z - Ax * up.z);
149159
}
150160

151161
void CGlCanvasBase::updateRoll(CamaraParams& params, int x, int y, float scale) const

0 commit comments

Comments
 (0)