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