1#pragma once
2
3#include <vector>
4
5#include "math.hpp"
6
7using std::vector;
8
9struct Face {
10 int vertex_idx;
11 int vertex_texture_idx;
12 int vertex_normal_idx;
13};
14
15struct Transform {
16 vec3f position{4.0, 0, 0};
17 vec3f rotation{0, 0, 0};
18 vec3f scale{1.0, 1.0, 1.0};
19
20 Mat4 model_matrix() const {
21 Mat4 scale_matrix = Mat4::scale(scale.x, scale.y, scale.z);
22 Mat4 rx = Mat4::rotation_x(rotation.x);
23 Mat4 ry = Mat4::rotation_y(rotation.y);
24 Mat4 rz = Mat4::rotation_z(rotation.z);
25 Mat4 rotation_matrix = rx * ry * rz;
26 Mat4 translate_matrix = Mat4::translate(position.x, position.y, position.z);
27 return scale_matrix * rotation_matrix * translate_matrix;
28 }
29};
30
31struct Mesh {
32 vector<vec3f> vertices;
33 vector<vec2f> texcoords;
34 vector<vec3f> normals;
35 vector<Face> faces;
36 Transform transform;
37 vec3f color;
38};
39
40Mesh parse_obj(const char *filename);