Rotate around entity center, update math notation
Change #define math functions to uppercase for consistency
This commit is contained in:
parent
b1875077b7
commit
0551f05e73
@ -257,7 +257,7 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
|||||||
}
|
}
|
||||||
#endif
|
#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);
|
u32 *fontBitmap = PLATFORM_MEM_ALLOC(bitmapSize, u32);
|
||||||
const i32 pitch = MAX_TEXTURE_SIZE * TARGET_BYTES_PER_PIXEL;
|
const i32 pitch = MAX_TEXTURE_SIZE * TARGET_BYTES_PER_PIXEL;
|
||||||
|
|
||||||
|
@ -123,7 +123,12 @@ void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v4 color,
|
|||||||
{
|
{
|
||||||
shader_use(renderer->shader);
|
shader_use(renderer->shader);
|
||||||
mat4 transMatrix = mat4_translate(pos.x, pos.y, 0.0f);
|
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
|
// 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
|
// TODO(doyle): We should have a notion of hitbox size and texture size
|
||||||
|
@ -299,7 +299,7 @@ INTERNAL void parseInput(GameState *state, const f32 dt)
|
|||||||
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
||||||
f32 epsilon = 15.0f;
|
f32 epsilon = 15.0f;
|
||||||
v2 epsilonDpos = v2_sub(V2(epsilon, epsilon),
|
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)
|
if (epsilonDpos.x >= 0.0f && epsilonDpos.y >= 0.0f)
|
||||||
{
|
{
|
||||||
hero->dPos = V2(0.0f, 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)
|
acceleration = (a/2) * (t^2)
|
||||||
old velocity = (v*t)
|
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 dPos = v2_scale(hero->dPos, dt);
|
||||||
v2 newHeroP = v2_add(v2_add(ddPosNew, dPos), hero->pos);
|
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++)
|
for (i32 i = 0; i < world->freeEntityIndex; i++)
|
||||||
{
|
{
|
||||||
Entity *const entity = &world->entities[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));
|
V4(1, 1, 1, 1));
|
||||||
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
@ -472,7 +482,6 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
|||||||
strPos, 0, color);
|
strPos, 0, color);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(doyle): Clean up lines
|
// TODO(doyle): Clean up lines
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "Dengine/Common.h"
|
#include "Dengine/Common.h"
|
||||||
|
|
||||||
#define squared(x) (x * x)
|
#define MATH_PI 3.14159265359f
|
||||||
#define absolute(x) ((x) > 0 ? (x) : -(x))
|
#define SQUARED(x) (x * x)
|
||||||
|
#define ABS(x) ((x) > 0 ? (x) : -(x))
|
||||||
|
#define DEGREES_TO_RADIANS(x) (x * (MATH_PI / 180.0f))
|
||||||
|
|
||||||
/* VECTORS */
|
/* VECTORS */
|
||||||
typedef union v2i
|
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 sinVal = sinf(radians);
|
||||||
f32 cosVal = cosf(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][1] = ((y * z * (1.0f - cosVal)) + (z * sinVal));
|
||||||
result.e[0][2] = ((z * x * (1.0f - cosVal)) - (y * 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][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[1][2] = ((z * y * (1.0f - cosVal)) + (x * sinVal));
|
||||||
|
|
||||||
result.e[2][0] = ((x * z * (1.0f - cosVal)) + (y * 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][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;
|
result.e[3][3] = 1;
|
||||||
|
|
||||||
@ -270,8 +272,8 @@ INTERNAL inline v4 getRect(v2 origin, v2 size)
|
|||||||
|
|
||||||
INTERNAL inline v2 getRectSize(v4 rect)
|
INTERNAL inline v2 getRectSize(v4 rect)
|
||||||
{
|
{
|
||||||
f32 width = absolute(rect.x - rect.z);
|
f32 width = ABS(rect.x - rect.z);
|
||||||
f32 height = absolute(rect.y - rect.w);
|
f32 height = ABS(rect.y - rect.w);
|
||||||
|
|
||||||
v2 result = V2(width, height);
|
v2 result = V2(width, height);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user