void CRotOverheadController::KeyMove(float3 move) { move *= math::sqrt(move.z) * 400; float3 flatForward = camera->forward; if(camera->forward.y < -0.9f) flatForward += camera->up; flatForward.y = 0; flatForward.ANormalize(); pos += (flatForward * move.y + camera->right * move.x) * scrollSpeed; UpdateVectors(); }
void SmoothController::MouseMove(float3 move) { if (flipped) { move.x = -move.x; move.y = -move.y; } move *= 100 * middleClickScrollSpeed; // do little smoothing here (and because its little it won't hurt if it depends on framerate) static float3 lastMove = ZeroVector; const float3 thisMove( move.x * pixelSize * (1 + keyInput->GetKeyState(SDLK_LSHIFT) * 3) * scrollSpeed, 0.0f, move.y * pixelSize * (1 + keyInput->GetKeyState(SDLK_LSHIFT) * 3) * scrollSpeed ); pos += (thisMove + lastMove) / 2.0f; lastMove = (thisMove + lastMove) / 2.0f; UpdateVectors(); }
void SmoothController::SetPos(const float3& newPos) { pos = newPos; UpdateVectors(); }
void SmoothController::MouseWheelMove(float move) { if (move == 0.0f) return; camHandler->CameraTransition(0.05f); const float shiftSpeed = (keyInput->IsKeyPressed(SDLK_LSHIFT) ? 3.0f : 1.0f); const float altZoomDist = height * move * 0.007f * shiftSpeed; // tilt the camera if LCTRL is pressed // // otherwise holding down LALT uses 'instant-zoom' // from here to the end of the function (smoothed) if (keyInput->IsKeyPressed(SDLK_LCTRL)) { zscale *= (1.0f + (0.01f * move * tiltSpeed * shiftSpeed)); zscale = Clamp(zscale, 0.05f, 10.0f); } else { if (move < 0.0f) { // ZOOM IN to mouse cursor instead of mid screen float3 cpos = pos - dir * height; float dif = -altZoomDist; if ((height - dif) < 60.0f) { dif = height - 60.0f; } if (keyInput->IsKeyPressed(SDLK_LALT)) { // instazoom in to standard view dif = (height - oldAltHeight) / mouse->dir.y * dir.y; } float3 wantedPos = cpos + mouse->dir * dif; float newHeight = ground->LineGroundCol(wantedPos, wantedPos + dir * 15000, false); if (newHeight < 0.0f) { newHeight = height * (1.0f + move * 0.007f * shiftSpeed); } if ((wantedPos.y + (dir.y * newHeight)) < 0.0f) { newHeight = -wantedPos.y / dir.y; } if (newHeight < maxHeight) { height = newHeight; pos = wantedPos + dir * height; } } else { // ZOOM OUT from mid screen if (keyInput->IsKeyPressed(SDLK_LALT)) { // instazoom out to maximum height if (height < maxHeight*0.5f && changeAltHeight) { oldAltHeight = height; changeAltHeight = false; } height = maxHeight; pos.x = gs->mapx * 4; pos.z = gs->mapy * 4.8f; // somewhat longer toward bottom } else { height *= (1.0f + (altZoomDist / height)); } } // instant-zoom: turn on the smooth transition and reset the camera tilt if (keyInput->IsKeyPressed(SDLK_LALT)) { zscale = 0.5f; camHandler->CameraTransition(1.0f); } else { changeAltHeight = true; } } UpdateVectors(); }
virtual void SetOperator(const Operator &op) { IterativeSolver::SetOperator(op); UpdateVectors(); }
glm::mat4 CCamera::GetMatrix() { UpdateVectors(); return glm::lookAt(this->pos, this->pos + this->front, this->up); }
void CRotOverheadController::SetPos(const float3& newPos) { CCameraController::SetPos(newPos); pos.y = ground->GetHeightAboveWater(pos.x, pos.z, false) + oldHeight; UpdateVectors(); }