1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-10 12:29:01 +00:00

Clarifies scaling logic.

This commit is contained in:
Thomas Harte 2020-08-17 20:29:46 -04:00
parent 246b474a25
commit 9da79d2d81
2 changed files with 12 additions and 5 deletions

View File

@ -194,12 +194,12 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
// Set the aspect ratio multiplier.
uniforms()->aspectRatioMultiplier = float(modals.aspect_ratio / viewAspectRatio);
// Also work out the proper zoom. Somehow?
// Also work out the proper zoom.
const double fitWidthZoom = (viewAspectRatio / modals.aspect_ratio) / modals.visible_area.size.width;
const double fitHeightZoom = 1.0 / modals.visible_area.size.height;
// The differing signs for offset below reflect the inverted coordinate system in Metal.
uniforms()->zoom = float(std::min(fitWidthZoom, fitHeightZoom));
// Store the offset.
uniforms()->offset.x = -modals.visible_area.origin.x;
uniforms()->offset.y = -modals.visible_area.origin.y;
}

View File

@ -101,9 +101,16 @@ vertex SourceInterpolator scanToDisplay( constant Uniforms &uniforms [[buffer(1)
) / 32.0;
// Hence determine this quad's real shape, using vertexID to pick a corner.
// position2d is now in the range [0, 1].
float2 position2d = start + (float(vertexID&2) * 0.5) * tangent + (float(vertexID&1) - 0.5) * normal * uniforms.lineWidth;
position2d = (position2d + uniforms.offset) * uniforms.zoom * float2(uniforms.aspectRatioMultiplier, 1.0);
position2d = position2d * float2(2.0, -2.0) + float2(-1.0, 1.0);
// Apply the requested offset and zoom, to map the desired area to the range [0, 1].
position2d = (position2d + uniforms.offset) * uniforms.zoom;
// Remap from [0, 1] to Metal's [-1, 1] and then apply the aspect ratio correction.
position2d = (position2d * float2(2.0, -2.0) + float2(-1.0, 1.0)) * float2(uniforms.aspectRatioMultiplier, 1.0);
output.position = float4(
position2d,
0.0,