MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / rotate

Method rotate

testbed/src/Scene.cpp:165–186  ·  view source on GitHub ↗

Rotate the camera

Source from the content-addressed store, hash-verified

163
164// Rotate the camera
165void 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}

Callers

nothing calls this directly

Calls 4

getUpperLeft3x3MatrixMethod · 0.80
Vector3Class · 0.50
getInverseMethod · 0.45

Tested by

no test coverage detected