Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Automatic camera zoom #47

Closed
rm-code opened this issue Nov 19, 2015 · 0 comments
Closed

Automatic camera zoom #47

rm-code opened this issue Nov 19, 2015 · 0 comments

Comments

@rm-code
Copy link
Owner

rm-code commented Nov 19, 2015

We already have the min and max X and Y coordinates of the graph at our disposal. By using them we could compare the width / height of the graph to the dimensions of the LÖVE window. If the graph's rectangle gets too big the camera zoom can be calculated as:

screenW / graphW and screenH / graphH

We just need the smaller value since zooming is always using the same value for x and y scaling. I played around with some code, but this isn't working correctly atm (the zoom isn't working correctly once the graph gets too big):

    local function calculateZoom(zoom, dt)
        local w, h = (maxX * zoom - minX * zoom), (maxY * zoom - minY * zoom);
        local sw, sh = love.graphics.getDimensions();

        -- Automatic Zoom.
        local ratioW, ratioH =  sw / w, sh / h;
        zoom = ratioW <= ratioH and ratioW or ratioH;

        -- Clamp value and return it.
        return math.max(CAMERA_MAX_ZOOM, math.min(zoom, CAMERA_MIN_ZOOM));
    end

I am taking the "current" camera zoom into account since we need to check if the "scaled" version of the graph fits the screen.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant