Rotate the camera
| 163 | |
| 164 | // Rotate the camera |
| 165 | void Scene::rotate(int xMouse, int yMouse) { |
| 166 | |
| 167 | const double deltaXMouse = mLastMouseX - xMouse; |
| 168 | const double deltaYMouse = mLastMouseY - yMouse; |
| 169 | |
| 170 | double deltaHorizRotationAngle = deltaXMouse / mWindowWidth * MOUSE_CAMERA_ROTATION_SCALING_FACTOR * M_PI; |
| 171 | double deltaVertRotationAngle = deltaYMouse / mWindowHeight * MOUSE_CAMERA_ROTATION_SCALING_FACTOR * M_PI; |
| 172 | |
| 173 | const double newVerticalAngle = mCurrentCameraVerticalAngle + deltaVertRotationAngle; |
| 174 | |
| 175 | // Limit Vertical angle |
| 176 | constexpr double piOver2 = M_PI * 0.5f; |
| 177 | if (newVerticalAngle > piOver2 || newVerticalAngle < -piOver2) { |
| 178 | deltaVertRotationAngle = 0; |
| 179 | } |
| 180 | |
| 181 | Vector3 localVertAxis = mCamera.getTransformMatrix().getUpperLeft3x3Matrix().getInverse() * Vector3(0, 1, 0); |
| 182 | mCamera.rotateAroundLocalPoint(Vector3(1, 0, 0), deltaVertRotationAngle, mCenterScene); |
| 183 | mCamera.rotateAroundLocalPoint(localVertAxis, deltaHorizRotationAngle, mCenterScene); |
| 184 | |
| 185 | mCurrentCameraVerticalAngle += deltaVertRotationAngle; |
| 186 | } |
nothing calls this directly
no test coverage detected