|
8 | 8 | +------------------------------------------------------------------------+ */ |
9 | 9 |
|
10 | 10 | #include "gui-precomp.h" // Precompiled headers |
| 11 | +#include "mrpt/math/geometry.h" |
11 | 12 | // |
12 | 13 | #include <mrpt/core/round.h> |
13 | 14 | #include <mrpt/gui/CGlCanvasBase.h> |
@@ -142,10 +143,19 @@ void CGlCanvasBase::updatePan(CamaraParams& params, int x, int y) const |
142 | 143 | float Ay = -(x - m_mouseClickX); |
143 | 144 | float Ax = -(y - m_mouseClickY); |
144 | 145 | 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); |
149 | 159 | } |
150 | 160 |
|
151 | 161 | void CGlCanvasBase::updateRoll(CamaraParams& params, int x, int y, float scale) const |
|
0 commit comments