Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5338: Move camera movement (discrete) to CamWnd.
  • Loading branch information
codereader committed Sep 26, 2020
1 parent a976390 commit 2cce849
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 104 deletions.
88 changes: 82 additions & 6 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -1246,32 +1246,108 @@ void CamWnd::handleKeyEvent(KeyEventType eventType, unsigned int freeMoveFlags,

void CamWnd::onForwardKey(KeyEventType eventType)
{
handleKeyEvent(eventType, MOVE_FORWARD, [this]() { _camera.moveForwardDiscrete(SPEED_MOVE); });
handleKeyEvent(eventType, MOVE_FORWARD, [this]() { moveForwardDiscrete(SPEED_MOVE); });
}

void CamWnd::onBackwardKey(KeyEventType eventType)
{
handleKeyEvent(eventType, MOVE_BACK, [this]() { _camera.moveBackDiscrete(SPEED_MOVE); });
handleKeyEvent(eventType, MOVE_BACK, [this]() { moveBackDiscrete(SPEED_MOVE); });
}

void CamWnd::onLeftKey(KeyEventType eventType)
{
handleKeyEvent(eventType, MOVE_STRAFELEFT, [this]() { _camera.rotateLeftDiscrete(); });
handleKeyEvent(eventType, MOVE_STRAFELEFT, [this]() { rotateLeftDiscrete(); });
}

void CamWnd::onRightKey(KeyEventType eventType)
{
handleKeyEvent(eventType, MOVE_STRAFERIGHT, [this]() { _camera.rotateRightDiscrete(); });
handleKeyEvent(eventType, MOVE_STRAFERIGHT, [this]() { rotateRightDiscrete(); });
}

void CamWnd::onUpKey(KeyEventType eventType)
{
handleKeyEvent(eventType, MOVE_UP, [this]() { _camera.moveUpDiscrete(SPEED_MOVE); });
handleKeyEvent(eventType, MOVE_UP, [this]() { moveUpDiscrete(SPEED_MOVE); });
}

void CamWnd::onDownKey(KeyEventType eventType)
{
handleKeyEvent(eventType, MOVE_DOWN, [this]() { _camera.moveDownDiscrete(SPEED_MOVE); });
handleKeyEvent(eventType, MOVE_DOWN, [this]() { moveDownDiscrete(SPEED_MOVE); });
}

void CamWnd::pitchUpDiscrete()
{
Vector3 angles = getCameraAngles();

angles[camera::CAMERA_PITCH] += SPEED_TURN;
if (angles[camera::CAMERA_PITCH] > 90)
angles[camera::CAMERA_PITCH] = 90;

setCameraAngles(angles);
}

void CamWnd::pitchDownDiscrete()
{
Vector3 angles = getCameraAngles();

angles[camera::CAMERA_PITCH] -= SPEED_TURN;
if (angles[camera::CAMERA_PITCH] < -90)
angles[camera::CAMERA_PITCH] = -90;

setCameraAngles(angles);
}

void CamWnd::moveForwardDiscrete(double units)
{
//moveUpdateAxes();
setCameraOrigin(getCameraOrigin() - _camera.getForwardVector() * fabs(units));
}

void CamWnd::moveBackDiscrete(double units)
{
//moveUpdateAxes();
setCameraOrigin(getCameraOrigin() + _camera.getForwardVector() * fabs(units));
}

void CamWnd::moveUpDiscrete(double units)
{
Vector3 origin = getCameraOrigin();

origin[2] += fabs(units);

setCameraOrigin(origin);
}

void CamWnd::moveDownDiscrete(double units)
{
Vector3 origin = getCameraOrigin();
origin[2] -= fabs(units);
setCameraOrigin(origin);
}

void CamWnd::moveLeftDiscrete(double units)
{
//moveUpdateAxes();
setCameraOrigin(getCameraOrigin() - _camera.getRightVector() * fabs(units));
}

void CamWnd::moveRightDiscrete(double units)
{
//moveUpdateAxes();
setCameraOrigin(getCameraOrigin() + _camera.getRightVector() * fabs(units));
}

void CamWnd::rotateLeftDiscrete()
{
Vector3 angles = getCameraAngles();
angles[camera::CAMERA_YAW] += SPEED_TURN;
setCameraAngles(angles);
}

void CamWnd::rotateRightDiscrete()
{
Vector3 angles = getCameraAngles();
angles[camera::CAMERA_YAW] -= SPEED_TURN;
setCameraAngles(angles);
}

// -------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions radiant/camera/CamWnd.h
Expand Up @@ -169,6 +169,17 @@ class CamWnd :
void onUpKey(KeyEventType eventType);
void onDownKey(KeyEventType eventType);

void pitchUpDiscrete();
void pitchDownDiscrete();
void rotateRightDiscrete();
void rotateLeftDiscrete();
void moveRightDiscrete(double units);
void moveLeftDiscrete(double units);
void moveDownDiscrete(double units);
void moveUpDiscrete(double units);
void moveBackDiscrete(double units);
void moveForwardDiscrete(double units);

protected:
void handleFreeMoveKeyEvent(KeyEventType eventType, unsigned int movementFlags);
void handleKeyEvent(KeyEventType eventType, unsigned int freeMoveFlags, const std::function<void()>& discreteMovement);
Expand Down
79 changes: 2 additions & 77 deletions radiant/camera/Camera.cpp
Expand Up @@ -201,7 +201,8 @@ void Camera::forceRedraw()
_forceRedraw();
}

void Camera::moveUpdateAxes() {
void Camera::moveUpdateAxes()
{
double ya = degrees_to_radians(_angles[camera::CAMERA_YAW]);

// the movement matrix is kept 2d
Expand Down Expand Up @@ -231,80 +232,4 @@ void Camera::updateProjection()
_view.Construct(_projection, _modelview, _width, _height);
}

void Camera::pitchUpDiscrete()
{
Vector3 angles = getCameraAngles();

angles[camera::CAMERA_PITCH] += SPEED_TURN;
if (angles[camera::CAMERA_PITCH] > 90)
angles[camera::CAMERA_PITCH] = 90;

setCameraAngles(angles);
}

void Camera::pitchDownDiscrete()
{
Vector3 angles = getCameraAngles();

angles[camera::CAMERA_PITCH] -= SPEED_TURN;
if (angles[camera::CAMERA_PITCH] < -90)
angles[camera::CAMERA_PITCH] = -90;

setCameraAngles(angles);
}

void Camera::moveForwardDiscrete(double units)
{
moveUpdateAxes();
setCameraOrigin(getCameraOrigin() + _forward * fabs(units));
}

void Camera::moveBackDiscrete(double units)
{
moveUpdateAxes();
setCameraOrigin(getCameraOrigin() + _forward * (-fabs(units)));
}

void Camera::moveUpDiscrete(double units)
{
Vector3 origin = getCameraOrigin();

origin[2] += fabs(units);

setCameraOrigin(origin);
}

void Camera::moveDownDiscrete(double units)
{
Vector3 origin = getCameraOrigin();
origin[2] -= fabs(units);
setCameraOrigin(origin);
}

void Camera::moveLeftDiscrete(double units)
{
moveUpdateAxes();
setCameraOrigin(getCameraOrigin() + _right * (-fabs(units)));
}

void Camera::moveRightDiscrete(double units)
{
moveUpdateAxes();
setCameraOrigin(getCameraOrigin() + _right * fabs(units));
}

void Camera::rotateLeftDiscrete()
{
Vector3 angles = getCameraAngles();
angles[camera::CAMERA_YAW] += SPEED_TURN;
setCameraAngles(angles);
}

void Camera::rotateRightDiscrete()
{
Vector3 angles = getCameraAngles();
angles[camera::CAMERA_YAW] -= SPEED_TURN;
setCameraAngles(angles);
}

} // namespace
11 changes: 0 additions & 11 deletions radiant/camera/Camera.h
Expand Up @@ -74,17 +74,6 @@ class Camera :
void queueDraw() override;
void forceRedraw() override;

void pitchUpDiscrete();
void pitchDownDiscrete();
void rotateRightDiscrete();
void rotateLeftDiscrete();
void moveRightDiscrete(double units);
void moveLeftDiscrete(double units);
void moveDownDiscrete(double units);
void moveUpDiscrete(double units);
void moveBackDiscrete(double units);
void moveForwardDiscrete(double units);

private:
void updateProjection();
};
Expand Down
20 changes: 10 additions & 10 deletions radiant/camera/GlobalCameraWndManager.cpp
Expand Up @@ -344,27 +344,27 @@ void GlobalCameraWndManager::moveCameraCmd(const cmd::ArgumentList& args)

if (arg == "up")
{
camWnd->getCamera().moveUpDiscrete(amount);
camWnd->moveUpDiscrete(amount);
}
else if (arg == "down")
{
camWnd->getCamera().moveDownDiscrete(amount);
camWnd->moveDownDiscrete(amount);
}
else if (arg == "left")
{
camWnd->getCamera().moveLeftDiscrete(amount);
camWnd->moveLeftDiscrete(amount);
}
if (arg == "right")
{
camWnd->getCamera().moveRightDiscrete(amount);
camWnd->moveRightDiscrete(amount);
}
else if (arg == "forward")
{
camWnd->getCamera().moveForwardDiscrete(amount);
camWnd->moveForwardDiscrete(amount);
}
else if (arg == "back")
{
camWnd->getCamera().moveBackDiscrete(amount);
camWnd->moveBackDiscrete(amount);
}
else
{
Expand Down Expand Up @@ -415,22 +415,22 @@ void GlobalCameraWndManager::onMoveDownKey(ui::KeyEventType eventType)

void GlobalCameraWndManager::moveLeftDiscrete(const cmd::ArgumentList& args)
{
doWithActiveCamWnd([](CamWnd& cam) { cam.getCamera().moveLeftDiscrete(SPEED_MOVE); });
doWithActiveCamWnd([](CamWnd& cam) { cam.moveLeftDiscrete(SPEED_MOVE); });
}

void GlobalCameraWndManager::moveRightDiscrete(const cmd::ArgumentList& args)
{
doWithActiveCamWnd([](CamWnd& cam) { cam.getCamera().moveRightDiscrete(SPEED_MOVE); });
doWithActiveCamWnd([](CamWnd& cam) { cam.moveRightDiscrete(SPEED_MOVE); });
}

void GlobalCameraWndManager::pitchUpDiscrete(const cmd::ArgumentList& args)
{
doWithActiveCamWnd([](CamWnd& cam) { cam.getCamera().pitchUpDiscrete(); });
doWithActiveCamWnd([](CamWnd& cam) { cam.pitchUpDiscrete(); });
}

void GlobalCameraWndManager::pitchDownDiscrete(const cmd::ArgumentList& args)
{
doWithActiveCamWnd([](CamWnd& cam) { cam.getCamera().pitchDownDiscrete(); });
doWithActiveCamWnd([](CamWnd& cam) { cam.pitchDownDiscrete(); });
}

float GlobalCameraWndManager::getCameraStrafeSpeed()
Expand Down

0 comments on commit 2cce849

Please sign in to comment.