| 5233 | |
| 5234 | |
| 5235 | static void updateRoamingCamera(float dt) { |
| 5236 | static Roaming::RoamingCamera prevDeltaCamera; |
| 5237 | static bool inited = false; |
| 5238 | static int prevMouseBits = 0; |
| 5239 | int currMouseBits = (leftMouseButton ? leftMouseBit : 0) | |
| 5240 | (rightMouseButton ? rightMouseBit : 0) | |
| 5241 | (middleMouseButton ? middleMouseBit : 0); |
| 5242 | |
| 5243 | if (!inited) { |
| 5244 | memset(&prevDeltaCamera, 0, sizeof(Roaming::RoamingCamera)); |
| 5245 | inited = true; |
| 5246 | } |
| 5247 | |
| 5248 | Roaming::RoamingCamera deltaCamera; |
| 5249 | memset(&deltaCamera, 0, sizeof(Roaming::RoamingCamera)); |
| 5250 | |
| 5251 | // move roaming camera |
| 5252 | if (myTank) { |
| 5253 | int mx, my; |
| 5254 | mainWindow->getMousePosition(mx, my); |
| 5255 | |
| 5256 | const MouseCtrlPair currCtrl = mouseCtrlMap[currMouseBits]; |
| 5257 | const MouseCtrlPair prevCtrl = mouseCtrlMap[prevMouseBits]; |
| 5258 | |
| 5259 | if (currCtrl.x == prevCtrl.x) { |
| 5260 | if (currCtrl.y != prevCtrl.y) { |
| 5261 | mainWindow->warpMouseCenterY(); |
| 5262 | my = 0; |
| 5263 | } |
| 5264 | } |
| 5265 | else if (currCtrl.y == prevCtrl.y) { |
| 5266 | mainWindow->warpMouseCenterX(); |
| 5267 | mx = 0; |
| 5268 | } |
| 5269 | else { |
| 5270 | mainWindow->warpMouse(); |
| 5271 | mx = my = 0; |
| 5272 | } |
| 5273 | |
| 5274 | if (currMouseBits != 0) { |
| 5275 | // mouse control |
| 5276 | const float spinMult = -100.0f; |
| 5277 | const float shiftMult = -1000.0f; |
| 5278 | const int wx = mainWindow->getWidth(); |
| 5279 | const int wy = mainWindow->getViewHeight(); |
| 5280 | const int ws = (wx < wy) ? wx : wy; |
| 5281 | const float wf = 1.0f / (float(ws * ws) * 0.25f); |
| 5282 | const float sx = float(mx * abs(mx)) * wf; |
| 5283 | const float sy = float(my * abs(my)) * wf; |
| 5284 | switch (currCtrl.x) { |
| 5285 | case SpinZ: { deltaCamera.theta = spinMult * sx; break; } |
| 5286 | case ShiftX: { deltaCamera.pos[1] = shiftMult * sx; break; } |
| 5287 | default: { break; } |
| 5288 | } |
| 5289 | switch (currCtrl.y) { |
| 5290 | case SpinX: { deltaCamera.phi = spinMult * sy; break; } |
| 5291 | case ShiftY: { deltaCamera.pos[0] = shiftMult * sy; break; } |
| 5292 | case ShiftZ: { deltaCamera.pos[2] = shiftMult * sy; break; } |
no test coverage detected