Switch rendering to xy bottom left, zw top right
This commit is contained in:
		
							parent
							
								
									cb857cfaa6
								
							
						
					
					
						commit
						5cd7239c8a
					
				| @ -295,16 +295,16 @@ void debug_drawUi(GameState *state, f32 dt) | ||||
| 	if (camera.pos.x <= world->bounds.x) | ||||
| 		camera.pos.x = world->bounds.x; | ||||
| 
 | ||||
| 	// TODO(doyle): Do the Y component when we need it
 | ||||
| 	// TODO(doyle): Allow Y panning when we need it
 | ||||
| 	f32 cameraTopBoundInPixels = camera.pos.y + camera.size.h; | ||||
| 	if (cameraTopBoundInPixels >= world->bounds.y) | ||||
| 		camera.pos.y = (world->bounds.y - camera.size.h); | ||||
| 	if (cameraTopBoundInPixels >= world->bounds.w) | ||||
| 		camera.pos.y = (world->bounds.w - camera.size.h); | ||||
| 
 | ||||
| 	f32 cameraRightBoundInPixels = camera.pos.x + camera.size.w; | ||||
| 	if (cameraRightBoundInPixels >= world->bounds.z) | ||||
| 		camera.pos.x = (world->bounds.z - camera.size.w); | ||||
| 
 | ||||
| 	if (camera.pos.y <= world->bounds.w) camera.pos.y = world->bounds.w; | ||||
| 	if (camera.pos.y <= world->bounds.y) camera.pos.y = world->bounds.y; | ||||
| 
 | ||||
| 	Font *font = &GLOBAL_debug.font; | ||||
| 	if (world->numEntitiesInBattle > 0) | ||||
|  | ||||
| @ -51,8 +51,8 @@ INTERNAL void updateBufferObject(Renderer *const renderer, | ||||
| INTERNAL RenderQuad createTexQuad(Renderer *renderer, v4 quadRect, | ||||
|                                   RenderTex renderTex) | ||||
| { | ||||
| 	// NOTE(doyle): Draws a series of triangles (three-sided polygons) using
 | ||||
| 	// vertices v0, v1, v2, then v2, v1, v3 (note the order)
 | ||||
| 	// NOTE(doyle): Draws a series of triangles using vertices v0, v1, v2, then
 | ||||
| 	// v2, v1, v3 (note the order)
 | ||||
| 	RenderQuad result = {0}; | ||||
| 
 | ||||
| 	/* Convert screen coordinates to normalised device coordinates */ | ||||
| @ -75,6 +75,7 @@ INTERNAL RenderQuad createTexQuad(Renderer *renderer, v4 quadRect, | ||||
| 	} | ||||
| 
 | ||||
| 	/* Form the quad */ | ||||
| #if 0 | ||||
| 	result.vertex[0] = V4(quadRectNdc.x, quadRectNdc.y, texRectNdc.x, | ||||
| 	                      texRectNdc.y); // Top left
 | ||||
| 	result.vertex[1] = V4(quadRectNdc.x, quadRectNdc.w, texRectNdc.x, | ||||
| @ -83,6 +84,16 @@ INTERNAL RenderQuad createTexQuad(Renderer *renderer, v4 quadRect, | ||||
| 	                      texRectNdc.y); // Top right
 | ||||
| 	result.vertex[3] = V4(quadRectNdc.z, quadRectNdc.w, texRectNdc.z, | ||||
| 	                      texRectNdc.w); // Bottom right
 | ||||
| #else | ||||
| 	result.vertex[0] = V4(quadRectNdc.x, quadRectNdc.w, texRectNdc.x, | ||||
| 	                      texRectNdc.w); // Top left
 | ||||
| 	result.vertex[1] = V4(quadRectNdc.x, quadRectNdc.y, texRectNdc.x, | ||||
| 	                      texRectNdc.y); // Bottom left
 | ||||
| 	result.vertex[2] = V4(quadRectNdc.z, quadRectNdc.w, texRectNdc.z, | ||||
| 	                      texRectNdc.w); // Top right
 | ||||
| 	result.vertex[3] = V4(quadRectNdc.z, quadRectNdc.y, texRectNdc.z, | ||||
| 	                      texRectNdc.y); // Bottom right
 | ||||
| #endif | ||||
| 	return result; | ||||
| } | ||||
| 
 | ||||
| @ -91,7 +102,11 @@ createDefaultTexQuad(Renderer *renderer, RenderTex renderTex) | ||||
| { | ||||
| 	RenderQuad result = {0}; | ||||
| 	// TODO(doyle): We need to switch this so its xy bottom left, zw top right!!
 | ||||
| #if 0 | ||||
| 	v4 defaultQuad    = V4(0.0f, renderer->size.h, renderer->size.w, 0.0f); | ||||
| #else | ||||
| 	v4 defaultQuad = V4(0.0f, 0.0f, renderer->size.w, renderer->size.h); | ||||
| #endif | ||||
| 	result            = createTexQuad(renderer, defaultQuad, renderTex); | ||||
| 	return result; | ||||
| } | ||||
| @ -100,10 +115,11 @@ INTERNAL void renderObject(Renderer *renderer, v2 pos, v2 size, v2 pivotPoint, | ||||
|                            f32 rotate, v4 color, Texture *tex) | ||||
| { | ||||
| 	mat4 transMatrix  = mat4_translate(pos.x, pos.y, 0.0f); | ||||
| 	// NOTE(doyle): Rotate from pivot point of the object, (0, 0) is top left
 | ||||
| 	// NOTE(doyle): Rotate from pivot point of the object, (0, 0) is bottom left
 | ||||
| 	mat4 rotateMatrix = mat4_translate(pivotPoint.x, pivotPoint.y, 0.0f); | ||||
| 	rotateMatrix = mat4_mul(rotateMatrix, mat4_rotate(rotate, 0.0f, 0.0f, 1.0f)); | ||||
| 	rotateMatrix = mat4_mul(rotateMatrix, mat4_translate(-pivotPoint.x, -pivotPoint.y, 0.0f)); | ||||
| 	rotateMatrix = mat4_mul(rotateMatrix, | ||||
| 	                        mat4_translate(-pivotPoint.x, -pivotPoint.y, 0.0f)); | ||||
| 
 | ||||
| 	// NOTE(doyle): We draw everything as a unit square in OGL. Scale it to size
 | ||||
| 	mat4 scaleMatrix = mat4_scale(size.x, size.y, 1.0f); | ||||
| @ -245,13 +261,12 @@ void renderer_entity(Renderer *renderer, Rect camera, Entity *entity, | ||||
| 	    math_pointInRect(camera, rightAlignedP)) | ||||
| 	{ | ||||
| 		EntityAnim_ *entityAnim = &entity->anim[entity->currAnimId]; | ||||
| 		Animation *anim = entityAnim->anim; | ||||
| 		i32 frameIndex = anim->frameIndex[entityAnim->currFrame]; | ||||
| 		v4 animTexRect = anim->atlas->texRect[frameIndex]; | ||||
| 		Animation *anim         = entityAnim->anim; | ||||
| 		i32 frameIndex          = anim->frameIndex[entityAnim->currFrame]; | ||||
| 		v4 animTexRect          = anim->atlas->texRect[frameIndex]; | ||||
| 
 | ||||
| 		if (entity->direction == direction_east) | ||||
| 		{ | ||||
| 			// NOTE(doyle): Flip the x coordinates to flip the tex
 | ||||
| 			flipTexCoord(&animTexRect, TRUE, FALSE); | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
| @ -115,16 +115,16 @@ void worldTraveller_gameInit(GameState *state, v2 windowSize) | ||||
| 	                       "data/textures/WorldTraveller/TerraSprite1024.png", | ||||
| 	                       texlist_hero); | ||||
| 	TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero); | ||||
| 	heroAtlas->texRect[herorects_idle]       = V4(746, 1018, 804, 920); | ||||
| 	heroAtlas->texRect[herorects_walkA]      = V4(641, 1018, 699, 920); | ||||
| 	heroAtlas->texRect[herorects_walkB]      = V4(849, 1018, 904, 920); | ||||
| 	heroAtlas->texRect[herorects_head]       = V4(108, 1024, 159, 975); | ||||
| 	heroAtlas->texRect[herorects_waveA]      = V4(944, 918, 1010, 816); | ||||
| 	heroAtlas->texRect[herorects_waveB]      = V4(944, 812, 1010, 710); | ||||
| 	heroAtlas->texRect[herorects_battlePose] = V4(8, 910, 71, 814); | ||||
| 	heroAtlas->texRect[herorects_castA]      = V4(428, 910, 493, 814); | ||||
| 	heroAtlas->texRect[herorects_castB]      = V4(525, 919, 590, 816); | ||||
| 	heroAtlas->texRect[herorects_castC]      = V4(640, 916, 698, 816); | ||||
| 	heroAtlas->texRect[herorects_idle]       = V4(746, 920, 804, 1018); | ||||
| 	heroAtlas->texRect[herorects_walkA]      = V4(641, 920, 699, 1018); | ||||
| 	heroAtlas->texRect[herorects_walkB]      = V4(849, 920, 904, 1018); | ||||
| 	heroAtlas->texRect[herorects_head]       = V4(108, 975, 159, 1024); | ||||
| 	heroAtlas->texRect[herorects_waveA]      = V4(944, 816, 1010, 918); | ||||
| 	heroAtlas->texRect[herorects_waveB]      = V4(944, 710, 1010, 812); | ||||
| 	heroAtlas->texRect[herorects_battlePose] = V4(8, 814, 71, 910); | ||||
| 	heroAtlas->texRect[herorects_castA]      = V4(428, 814, 493, 910); | ||||
| 	heroAtlas->texRect[herorects_castB]      = V4(525, 816, 590, 919); | ||||
| 	heroAtlas->texRect[herorects_castC]      = V4(640, 816, 698, 916); | ||||
| 
 | ||||
| 	asset_loadTextureImage(assetManager, | ||||
| 	                       "data/textures/WorldTraveller/Terrain.png", | ||||
| @ -133,10 +133,10 @@ void worldTraveller_gameInit(GameState *state, v2 windowSize) | ||||
| 	    asset_getTextureAtlas(assetManager, texlist_terrain); | ||||
| 	f32 atlasTileSize = 128.0f; | ||||
| 	const i32 texSize = 1024; | ||||
| 	v2 texOrigin = V2(0, CAST(f32)(texSize - 128)); | ||||
| 	v2 texOrigin = V2(0, 768); | ||||
| 	terrainAtlas->texRect[terrainrects_ground] = | ||||
| 	    V4(texOrigin.x, texOrigin.y, texOrigin.x + atlasTileSize, | ||||
| 	       texOrigin.y - atlasTileSize); | ||||
| 	       texOrigin.y + atlasTileSize); | ||||
| 
 | ||||
| 	/* Load shaders */ | ||||
| 	asset_loadShaderFiles(assetManager, arena, "data/shaders/sprite.vert.glsl", | ||||
| @ -628,12 +628,13 @@ INTERNAL void parseInput(GameState *state, const f32 dt) | ||||
| 		hero->dPos = v2_add(hero->dPos, v2_scale(ddPos, dt)); | ||||
| 		hero->pos  = newHeroP; | ||||
| 
 | ||||
| 		v2 offsetFromHeroToOrigin = | ||||
| 		// NOTE(doyle): Set the camera such that the hero is centered
 | ||||
| 		v2 offsetFromHeroToCameraOrigin = | ||||
| 		    V2((hero->pos.x - (0.5f * state->renderer.size.w)), (0.0f)); | ||||
| 
 | ||||
| 		// NOTE(doyle): Hero position is offset to the center so -recenter it
 | ||||
| 		offsetFromHeroToOrigin.x += (hero->hitboxSize.x * 0.5f); | ||||
| 		world->cameraPos = offsetFromHeroToOrigin; | ||||
| 		// NOTE(doyle): Account for the hero's origin being the bottom left
 | ||||
| 		offsetFromHeroToCameraOrigin.x += (hero->hitboxSize.x * 0.5f); | ||||
| 		world->cameraPos = offsetFromHeroToCameraOrigin; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| @ -644,16 +645,16 @@ INTERNAL Rect createWorldBoundedCamera(World *world, v2 size) | ||||
| 	if (camera.pos.x <= world->bounds.x) | ||||
| 		camera.pos.x = world->bounds.x; | ||||
| 
 | ||||
| 	// TODO(doyle): Do the Y component when we need it
 | ||||
| 	// TODO(doyle): Allow Y panning when we need it
 | ||||
| 	f32 cameraTopBoundInPixels = camera.pos.y + camera.size.h; | ||||
| 	if (cameraTopBoundInPixels >= world->bounds.y) | ||||
| 		camera.pos.y = (world->bounds.y - camera.size.h); | ||||
| 	if (cameraTopBoundInPixels >= world->bounds.w) | ||||
| 		camera.pos.y = (world->bounds.w - camera.size.h); | ||||
| 
 | ||||
| 	f32 cameraRightBoundInPixels = camera.pos.x + camera.size.w; | ||||
| 	if (cameraRightBoundInPixels >= world->bounds.z) | ||||
| 		camera.pos.x = (world->bounds.z - camera.size.w); | ||||
| 
 | ||||
| 	if (camera.pos.y <= world->bounds.w) camera.pos.y = world->bounds.w; | ||||
| 	if (camera.pos.y <= world->bounds.y) camera.pos.y = world->bounds.y; | ||||
| 	return camera; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -307,11 +307,8 @@ INTERNAL inline b32 math_pointInRect(Rect rect, v2 point) | ||||
| 
 | ||||
| INTERNAL inline v4 math_getRect(v2 origin, v2 size) | ||||
| { | ||||
| 	v2 upperLeftBound  = v2_add(origin, V2(0.0f, size.y)); | ||||
| 	v2 lowerRightBound = v2_add(origin, V2(size.x, 0.0f)); | ||||
| 
 | ||||
| 	v4 result = V4(upperLeftBound.x, upperLeftBound.y, lowerRightBound.x, | ||||
| 	               lowerRightBound.y); | ||||
| 	v2 upperRightBound = v2_add(origin, V2(size.x, size.y)); | ||||
| 	v4 result = V4(origin.x, origin.y, upperRightBound.x, upperRightBound.y); | ||||
| 
 | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user