Hmm maybe I'm not understanding this correctly.
Or maybe I have just written this wrong (as these snippets are not from the handmade_hero source. I wrote it by following the tutorials).
But the setCamera
function takes in the new camera position in the tilemap coordiantes:
internal void
SetCamera(game_state *GameState, tile_map_position NewCameraP) {
tile_map *TileMap = GameState->World->TileMap;
tile_map_difference dCameraP = Subtract(TileMap, &NewCameraP, &GameState->CameraP);
GameState->CameraP = NewCameraP;
uint32 TileSpanX = 17 * 3;
uint32 TileSpanY = 9 * 3;
rectangle2 CameraBounds = RectCenterDim(
// TileMap->TileSideInMeters * v2{(real32)NewCameraP.AbsTileX, (real32)NewCameraP.AbsTileY},
v2{0, 0},
TileMap->TileSideInMeters * v2{(real32)TileSpanX, (real32)TileSpanY});
v2 EntityOffsetForFrame = -dCameraP.dXY;
OffsetAndCheckFrequencyByArea(GameState, EntityOffsetForFrame, CameraBounds);
And we set the camera position when the game starts like this
tile_map_position NewCameraP = {};
NewCameraP.AbsTileX = 17/2;
NewCameraP.AbsTileY = 9/2;
NewCameraP.AbsTileZ = 0;
SetCamera(GameState, NewCameraP);
Memory->IsInitialized = true;
So, it seems to me that definitely the coordinate axes are centered at the bottom of the screen and there are 17/9 tiles in all. Then we are placing the camera at the center of this.
This is also clear if you change the initialization call of the hero which puts the hero at bottom left for 0, 0.
And hence, I think this is an error. Now the tilespan is so big that making this change doesn't really make any difference. So, even if you do calculate the bounds with the center of the rectangle2 at the bottomleft, it works fine.
I will go through the video again though and see if I can make sense of this.