diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
| commit | 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch) | |
| tree | 428986b49c32e21d3f7a3c2dfa41858ae0153209 /09-september/tomcat/renderer/entity.c | |
Initial commit
Diffstat (limited to '09-september/tomcat/renderer/entity.c')
| -rw-r--r-- | 09-september/tomcat/renderer/entity.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/09-september/tomcat/renderer/entity.c b/09-september/tomcat/renderer/entity.c new file mode 100644 index 0000000..d5e7429 --- /dev/null +++ b/09-september/tomcat/renderer/entity.c @@ -0,0 +1,33 @@ +#include "renderer.h" + +Mat4 Entity_GetModelTransform(Entity* entity) +{ + Mat4 temp; + Mat4 rotation = mat4_rotate_x(entity->rotX); + temp = mat4_rotate_y(entity->rotY); + rotation = mat4_mul(&rotation, &temp); + temp = mat4_rotate_z(entity->rotZ); + rotation = mat4_mul(&rotation, &temp); + + temp = mat4_translate(&entity->position); + + Mat4 modelTransform = mat4_mul(&temp, &rotation); + temp = mat4_scale(entity->scale[0], entity->scale[1], entity->scale[2]); + modelTransform = mat4_mul(&modelTransform, &temp); + + return modelTransform; +} + +Vec2 Entity_GetTexOffset(Entity *entity) +{ + /* Offset inside a texture atlas should default to (0, 0)*/ + Vec2 tex_offset; + Texture *t = entity->texture; + + int column = entity->index % t->number_of_rows; + int row = entity->index / t->number_of_rows; + tex_offset.x = (float)column / t->number_of_rows; + tex_offset.y = (float)row / t->number_of_rows; + + return tex_offset; +} |
