I've been getting started with personal experimentation and have been working on a project for a few days now using SDL2. It is a 2D game, and at this stage I have it rendering game objects in a fixed-size viewport that can navigate around the 'game world'.
I'm not terribly well-versed in linear algebra yet, so it's possible that the answer to this question is somewhere in that curriculum that I have yet to tackle.
The game space has its own coordinates, organized in the same way that they are on an
SDL_Window. The "viewport" then has its own coordinates (indicated by it's top left corner) in the game space. Game objects are then given transformed coordinates in the viewport's own coordinate space, which corresponds to the
SDL_Window's coordinate space i.e. they start at
(0, 0) at the upper left, which is essentially an offset given the viewport's coordinates, e.g.:
Entity x's gamespace coordinates are
(100, 200) and the viewport's gamespace coordinates are
(20, 20), the entity's "viewport" coordinates would be
(100 - 20, 200 - 20) or
I've started to think about implementing 'zoom' functionality. At the moment, all that means is that the viewport is scaled up or down (to certain size limits), and the game entity's dimensions are scaled up or down correspondingly. What isn't transformed are the coordinates.
Visually, this is the basic problem:
At maximum size, where the viewport's dimensions are the same as the game space's dimensions (they have the same aspect ratio), the positions of all objects in the viewport space would be the same as they are in the game space, but they would have to be positioned using completely different coordinates in the viewport space.
What are the mathematical techniques/principles I should be studying to figure this one out? Thank you!