Добавление MeshLoader, он умеет загружать геометрию и нормали из .obj файлов

This commit is contained in:
2023-03-23 18:34:14 +03:00
parent 1b623c947a
commit bd12a62be1
10 changed files with 243 additions and 14 deletions

View File

@@ -18,6 +18,7 @@
#include "window/Events.h"
#include "graphics/Mesh.h"
#include "graphics/Shader.h"
#include "graphics/MeshLoader.h"
#define SPEED_FACTOR 2.5f
@@ -78,6 +79,7 @@ static void updateCameraPosition(Camera& cam, float delta) {
static Mesh* world;
static Mesh* model_mesh;
static Shader* shader;
static void drawWorld(Camera& cam) {
auto projview = cam.getProjection() * cam.getView();
@@ -96,7 +98,8 @@ static void drawWorld(Camera& cam) {
angle += 0.001f;
shader->uniformMatrix("projview", projview * model_scale * model_translate * model_rotate);
world->draw();
// world->draw();
model_mesh->draw();
}
@@ -141,20 +144,22 @@ void mainloop(Camera& camera) {
void loadResources() {
const float buffer[] = {
// треугольник
// X Y Z Light
-1, -1, 0.5, 0.5,
1, -1, 0.5, 0.1,
0, 1, 0.5, 0.9,
// X Y Z nX nY nZ
-1, -1, 0.5, 0, 0, 1,
1, -1, 0.5, 0, 0, 1,
0, 1, 0.5, 0, 0, 1,
-1, -1, -0.5, 0.5,
1, -1, -0.5, 0.1,
0, 1, -0.5, 0.9,
-1, -1, -0.5, 0, 0, -1,
1, -1, -0.5, 0, 0, -1,
0, 1, -0.5, 0, 0, -1,
};
const int mesh_attrs[] {
3, 1, 0
3, 3, 0
};
world = new Mesh(buffer, 6, mesh_attrs);
model_mesh = MeshLoader::loadMesh("res/cube");
shader = Shader::loadShader("res/main.vsh", "res/main.fsh");
}