blob: d5e7429e1ba6649b4d4352ba6b4ba47637d4c692 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
}
|