Skip to content

Commit

Permalink
Orthographic projection now maintains zoom level when switching to fu…
Browse files Browse the repository at this point in the history
…ll screen
  • Loading branch information
Robadob committed Mar 12, 2023
1 parent 35b428c commit 4019b87
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/flamegpu/visualiser/Visualiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ namespace visualiser {
#define ONE_SECOND_MS 1000
#define VSYNC 1

#define DEFAULT_WINDOW_WIDTH 1280
#define DEFAULT_WINDOW_HEIGHT 720

#define MOVEMENT_MULTIPLIER 1.f
#define AXIS_LEFT_DEAD_ZONE 0.2f
#define AXIS_RIGHT_DEAD_ZONE 0.15f
Expand Down Expand Up @@ -750,12 +747,18 @@ void Visualiser::resizeWindow() {
modelConfig.nearFarClip[0],
modelConfig.nearFarClip[1]);
} else {
// Scale ortho zoom according to screen resolution
// So that zoom naturally scales with screen resolution
// This assures the full screen remains in frame with non uniform scaling
const float width_ratio = static_cast<float>(modelConfig.windowDimensions[0]) / static_cast<float>(this->windowDims.x);
const float height_ratio = static_cast<float>(modelConfig.windowDimensions[1]) / static_cast<float>(this->windowDims.y);
const float orthoZoom = modelConfig.orthoZoom * std::max<float>(width_ratio, height_ratio);
// Ortho has no reason for near/far plane
this->projMat = glm::ortho<float>(
modelConfig.orthoZoom * -static_cast<float>(this->windowDims.x) / 2.0f,
modelConfig.orthoZoom * static_cast<float>(this->windowDims.x) / 2.0f,
modelConfig.orthoZoom * -static_cast<float>(this->windowDims.y) / 2.0f,
modelConfig.orthoZoom * static_cast<float>(this->windowDims.y) / 2.0f,
orthoZoom * -static_cast<float>(this->windowDims.x) / 2.0f,
orthoZoom * static_cast<float>(this->windowDims.x) / 2.0f,
orthoZoom * -static_cast<float>(this->windowDims.y) / 2.0f,
orthoZoom * static_cast<float>(this->windowDims.y) / 2.0f,
modelConfig.nearFarClip[0],
modelConfig.nearFarClip[1]);
}
Expand Down

0 comments on commit 4019b87

Please sign in to comment.