diff --git a/src/AssetManager.c b/src/AssetManager.c index 2c38736..78656d5 100644 --- a/src/AssetManager.c +++ b/src/AssetManager.c @@ -257,7 +257,7 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath) } #endif - i32 bitmapSize = squared(TARGET_TEXTURE_SIZE) * TARGET_BYTES_PER_PIXEL; + i32 bitmapSize = SQUARED(TARGET_TEXTURE_SIZE) * TARGET_BYTES_PER_PIXEL; u32 *fontBitmap = PLATFORM_MEM_ALLOC(bitmapSize, u32); const i32 pitch = MAX_TEXTURE_SIZE * TARGET_BYTES_PER_PIXEL; diff --git a/src/Renderer.c b/src/Renderer.c index 3f4cf1a..27bf989 100644 --- a/src/Renderer.c +++ b/src/Renderer.c @@ -123,7 +123,12 @@ void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v4 color, { shader_use(renderer->shader); mat4 transMatrix = mat4_translate(pos.x, pos.y, 0.0f); - mat4 rotateMatrix = mat4_rotate(rotate, 0.0f, 0.0f, 1.0f); + + // NOTE(doyle): Rotate from the center of the object, not its' origin (i.e. + // top left) + mat4 rotateMatrix = mat4_translate((size.x * 0.5f), (size.y * 0.5f), 0.0f); + rotateMatrix = mat4_mul(rotateMatrix, mat4_rotate(rotate, 0.0f, 0.0f, 1.0f)); + rotateMatrix = mat4_mul(rotateMatrix, mat4_translate((size.x * -0.5f), (size.y * -0.5f), 0.0f)); // NOTE(doyle): We draw everything as a unit square in OGL. Scale it to size // TODO(doyle): We should have a notion of hitbox size and texture size diff --git a/src/WorldTraveller.c b/src/WorldTraveller.c index 019b612..4f722db 100644 --- a/src/WorldTraveller.c +++ b/src/WorldTraveller.c @@ -299,7 +299,7 @@ INTERNAL void parseInput(GameState *state, const f32 dt) // NOTE(doyle): Clipping threshold for snapping velocity to 0 f32 epsilon = 15.0f; v2 epsilonDpos = v2_sub(V2(epsilon, epsilon), - V2(absolute(hero->dPos.x), absolute(hero->dPos.y))); + V2(ABS(hero->dPos.x), ABS(hero->dPos.y))); if (epsilonDpos.x >= 0.0f && epsilonDpos.y >= 0.0f) { hero->dPos = V2(0.0f, 0.0f); @@ -338,7 +338,7 @@ INTERNAL void parseInput(GameState *state, const f32 dt) acceleration = (a/2) * (t^2) old velocity = (v*t) */ - v2 ddPosNew = v2_scale(v2_scale(ddPos, 0.5f), squared(dt)); + v2 ddPosNew = v2_scale(v2_scale(ddPos, 0.5f), SQUARED(dt)); v2 dPos = v2_scale(hero->dPos, dt); v2 newHeroP = v2_add(v2_add(ddPosNew, dPos), hero->pos); @@ -426,7 +426,17 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt) for (i32 i = 0; i < world->freeEntityIndex; i++) { Entity *const entity = &world->entities[i]; - renderer_entity(&state->renderer, cameraBounds, entity, dt, 0.0f, + f32 rotate = 0.0f; + switch (entity->type) + { + case entitytype_hero: + //rotate = DEGREES_TO_RADIANS(90.0f); + break; + default: + break; + } + + renderer_entity(&state->renderer, cameraBounds, entity, dt, rotate, V4(1, 1, 1, 1)); #ifdef DENGINE_DEBUG @@ -472,7 +482,6 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt) strPos, 0, color); } #endif - } // TODO(doyle): Clean up lines diff --git a/src/include/Dengine/Math.h b/src/include/Dengine/Math.h index 4450bd3..229344a 100644 --- a/src/include/Dengine/Math.h +++ b/src/include/Dengine/Math.h @@ -4,8 +4,10 @@ #include #include "Dengine/Common.h" -#define squared(x) (x * x) -#define absolute(x) ((x) > 0 ? (x) : -(x)) +#define MATH_PI 3.14159265359f +#define SQUARED(x) (x * x) +#define ABS(x) ((x) > 0 ? (x) : -(x)) +#define DEGREES_TO_RADIANS(x) (x * (MATH_PI / 180.0f)) /* VECTORS */ typedef union v2i @@ -199,17 +201,17 @@ INTERNAL inline mat4 mat4_rotate(const f32 radians, const f32 x, const f32 y, f32 sinVal = sinf(radians); f32 cosVal = cosf(radians); - result.e[0][0] = (cosVal + (squared(x) * (1.0f - cosVal))); + result.e[0][0] = (cosVal + (SQUARED(x) * (1.0f - cosVal))); result.e[0][1] = ((y * z * (1.0f - cosVal)) + (z * sinVal)); result.e[0][2] = ((z * x * (1.0f - cosVal)) - (y * sinVal)); result.e[1][0] = ((x * y * (1.0f - cosVal)) - (z * sinVal)); - result.e[1][1] = (cosVal + (squared(y) * (1.0f - cosVal))); + result.e[1][1] = (cosVal + (SQUARED(y) * (1.0f - cosVal))); result.e[1][2] = ((z * y * (1.0f - cosVal)) + (x * sinVal)); result.e[2][0] = ((x * z * (1.0f - cosVal)) + (y * sinVal)); result.e[2][1] = ((y * z * (1.0f - cosVal)) - (x * sinVal)); - result.e[2][2] = (cosVal + (squared(z) * (1.0f - cosVal))); + result.e[2][2] = (cosVal + (SQUARED(z) * (1.0f - cosVal))); result.e[3][3] = 1; @@ -270,8 +272,8 @@ INTERNAL inline v4 getRect(v2 origin, v2 size) INTERNAL inline v2 getRectSize(v4 rect) { - f32 width = absolute(rect.x - rect.z); - f32 height = absolute(rect.y - rect.w); + f32 width = ABS(rect.x - rect.z); + f32 height = ABS(rect.y - rect.w); v2 result = V2(width, height);