so i am creating a game similar to super-smash-bros, in which the camera should zoom in on players when they are close together, and scale back when they are apart. I create a window for my game via
m_pWindow = SDL_CreateWindow("First SDL game attempt", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 1000, 1000, SDL_WINDOW_SHOWN);
and then initialise my render via
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED);
and when i call render for my buffer, it simply calls
SDL_SetRenderDrawColor(m_pRenderer, m_clearRed, m_clearGreen, m_clearBlue, 0xff);
SDL_RenderClear(m_pRenderer);
SDL_RenderPresent(m_pRenderer);
Now i am wondering where in this solution should i implement the camera, if you could point me in the right direction that would be great. For example, i have a player positioned at {500, 800}
, and another at {300,800}
. I want to zoom in on this point of the screen. The total window is 1000x1000, but rendering {x = 200->600, y = 600->1000}
is what i want to achieve.
I have currently tried using
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
rect.w = 900; //TEST VALUES
rect.h = 900; //TEST VALUES
SDL_RenderSetViewport(m_pRenderer,
&rect);
But this simply doesn't render part of the screen, as opposed to scaling the entire view.
Any other help would be greatly appreciated