1#pragma once
2
3#include <vector>
4
5#include "globals.h"
6#include "util_math.h"
7
8using std::vector;
9
10struct Face {
11 int vertex_idx;
12 int vertex_texture_idx;
13 int vertex_normal_idx;
14 u32 mat_idx;
15};
16
17struct Transform {
18 vec3f position{4.0, 0, 0};
19 vec3f rotation{0, 0, 0};
20 vec3f scale{1.0, 1.0, 1.0};
21
22 Mat4 model_matrix() const {
23 Mat4 scale_matrix = Mat4::scale(scale.x, scale.y, scale.z);
24 Mat4 rx = Mat4::rotation_x(rotation.x);
25 Mat4 ry = Mat4::rotation_y(rotation.y);
26 Mat4 rz = Mat4::rotation_z(rotation.z);
27 Mat4 rotation_matrix = rx * ry * rz;
28 Mat4 translate_matrix = Mat4::translate(position.x, position.y, position.z);
29 return scale_matrix * rotation_matrix * translate_matrix;
30 }
31};
32
33struct Material {
34 char name[128];
35 char texture_path[512];
36 vec3f ambient; // Ka
37 vec3f diffuse; // Kd;
38 vec3f specular; // Ks;
39 u32 texture_img_idx; // 0 sentinel for missing, populated in initialize_scene()
40};
41extern vector<Material> materials;
42
43struct Mesh {
44 vector<vec3f> vertices;
45 vector<vec2f> texcoords;
46 vector<vec3f> normals;
47 vector<Face> faces;
48 Transform transform;
49 vec3f color;
50};
51
52Mesh parse_obj(const char *filename);