From cc4ba95edf2927eda63af1aeb79a503bc6fe6182 Mon Sep 17 00:00:00 2001 From: tech kaczynski Date: Thu, 1 Oct 2026 06:19:28 +1000 Subject: reimplemented models properly and removed placeholder entity drawing code. --- ent.c | 75 ++++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'ent.c') diff --git a/ent.c b/ent.c index ca642db..61c6c6a 100644 --- a/ent.c +++ b/ent.c @@ -1,4 +1,5 @@ #include "ent.h" +#include "res.h" typedef struct { u32 gen, dense_id, next_free; @@ -246,33 +247,43 @@ entity_system_clear(void) { } -// static void -// entity_draw_mdl(Entity *ent) { -// Matrix T = MatrixTranslate( -// ent->tr.pos.x, -// ent->tr.pos.y, -// ent->tr.pos.z); - -// Matrix R = MatrixRotateXYZ((Vec3) { -// ent->tr.rot.x * DEG2RAD, -// ent->tr.rot.y * DEG2RAD, -// ent->tr.rot.z * DEG2RAD, -// }); - -// Matrix S = MatrixScale( -// ent->tr.scale.x, -// ent->tr.scale.y, -// ent->tr.scale.z); +static void +entity_draw_mdl(Entity *ent) { + Matrix T = MatrixTranslate( + ent->tr.pos.x, + ent->tr.pos.y, + ent->tr.pos.z); + + // Matrix R = MatrixRotateXYZ((Vec3) { + // ent->tr.rot.x * DEG2RAD, + // ent->tr.rot.y * DEG2RAD, + // ent->tr.rot.z * DEG2RAD, + // }); + + Matrix R = QuaternionToMatrix(ent->tr.rot); + + Matrix S = MatrixScale( + ent->tr.scale.x, + ent->tr.scale.y, + ent->tr.scale.z); + + if (!ent->mdl.mdl) { + Asset *asset = asset_get(ent->mdl.key); + if (!asset) { + return; + } + ent->mdl.mdl = &asset->mdl; + } -// Model mdl = *ent->mdl.mdl; -// mdl.transform = MatrixMultiply(S, MatrixMultiply(R, T)); + Model mdl = *ent->mdl.mdl; + mdl.transform = MatrixMultiply(S, MatrixMultiply(R, T)); -// Color tint = ent->ed.selected ? -// (Color){ 100, 100, 100, 255 } : -// BLACK; + Color tint = ent->ed.selected ? + (Color){ 100, 100, 100, 255 } : + BLACK; -// DrawModel(mdl, (Vec3) {0}, 1, tint); -// } + DrawModel(mdl, (Vec3) {0}, 1, tint); +} // static void // entity_draw_col(u64 id) { @@ -371,14 +382,14 @@ entity_system_update(void) { void entity_system_draw_3d(void) { - // for (u32 i = 0; i < entity_count(); ++i) { - // u64 id = entity_id_at(i); - // Entity *ent = entity_get(id); - - // if (ent->mdl.has && ent->mdl.draw) { - // entity_draw_mdl(ent); - // } - // } + for (u32 i = 0; i < entity_count(); ++i) { + u64 id = entity_id_at(i); + Entity *ent = entity_get(id); + + if (ent->mdl.has && ent->mdl.draw) { + entity_draw_mdl(ent); + } + } } void -- cgit v1.2.3