Make entity rotation work properly

This commit is contained in:
2025-06-03 19:55:36 +02:00
parent 9b87ddef34
commit d27468ea02
3 changed files with 7 additions and 11 deletions
+2 -10
View File
@@ -14,13 +14,6 @@ Chunk_new ()
return chunk;
}
/* Example function for a tick for an entity. */
void
tree_grow (Entity *entity)
{
entity->scale[1] += 0.01;
}
void
Chunk_random (Chunk *chunk, int xoffset, int zoffset)
{
@@ -44,10 +37,9 @@ Chunk_random (Chunk *chunk, int xoffset, int zoffset)
.mesh_type = ENTITY_MESH_X,
.origin = ENTITY_BOTTOM,
.position = { (float) x + xoffset, chunk->heightmap[INDEX (x, z)], (float) z + zoffset },
.scale = { 3.0, 10.0, 3.0 },
.rotation = (rand () % 180) * (M_PI / 180.0),
.scale = { 3.0, (rand()) % 5 + 5, 3.0 },
.rotation = rand () % 180,
.texture = "tree0",
.on_tick = tree_grow
};
EM_ENTADD (tree);
+3 -1
View File
@@ -56,6 +56,8 @@ em_render_internal (gpointer data, gpointer userdata)
}
mat4 model = GLM_MAT4_IDENTITY_INIT;
glm_rotate_at (model, entity->position, DEGTORAD (entity->rotation), (vec3) { 0.0, 1.0, 0.0 });
glm_translate (model, entity->position);
if (entity->origin == ENTITY_BOTTOM)
@@ -64,7 +66,7 @@ em_render_internal (gpointer data, gpointer userdata)
}
glm_scale (model, entity->scale);
program_use (program);
program_set_mat4 (program, "model", model);
+2
View File
@@ -17,6 +17,8 @@
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#define DEGTORAD(deg) ((deg) * (M_PI / 180.0))
#define UNUSED(...) (UNUSED_1 (__VA_ARGS__, 0))
#define UNUSED_1(arg, ...) (void) arg, UNUSED_2 (__VA_ARGS__, 0)
#define UNUSED_2(arg, ...) (void) arg, UNUSED_3 (__VA_ARGS__, 0)