void COrbitController::Orbit() { CCamera* cam = camera; cam->pos = cen + GetOrbitPos(); cam->pos.y = std::max(cam->pos.y, ground->GetHeight2(cam->pos.x, cam->pos.z)); cam->forward = (cen - cam->pos).ANormalize(); cam->up = YVEC; }
void OrbitCamera::MouseMoved(int x, int y, int dx, int dy) { if (!active) { return; } switch (inputHandler->GetLastMouseButton()) { case SDL_BUTTON_LEFT: { // we want translation wrt. coors of last press dx = (inputHandler->GetLastMouseCoors()).x - x; dy = (inputHandler->GetLastMouseCoors()).y - y; // orbit change does not affect distance rotation = cRotation - (dx * 0.25f); elevation = cElevation - (dy * 0.25f); } break; case SDL_BUTTON_RIGHT: { dx = (inputHandler->GetLastMouseCoors()).x - x; dy = (inputHandler->GetLastMouseCoors()).y - y; // distance change does not affect orbit distance = cDistance - (dy * 0.5f * 10.0f); } break; } if (elevation > 89.0f) elevation = 89.0f; if (elevation < -89.0f) elevation = -89.0f; if (distance < 1.0f) distance = 1.0f; switch (inputHandler->GetLastMouseButton()) { case SDL_BUTTON_LEFT: { pos = cen + GetOrbitPos(); vrp = pos + ((cen - pos).inorm3D()); ydir = YVECf; // keep rotations level in xz-plane mat.SetPos(pos); mat.SetYDir(ydir); } break; case SDL_BUTTON_RIGHT: { pos = cen - (zdir * distance); vrp = pos + zdir; mat.SetPos(pos); } break; case SDL_BUTTON_MIDDLE: { const int xsign = (dx > 0)? 1: 1; const int ysign = (dy > 0)? -1: -1; // const float rdx = abs(dx) / hFOVdeg; // const float rdy = abs(dy) / vFOVdeg; HStrafe(xsign, dx * 2); VStrafe(ysign, dy * 2); } break; } }