aboutsummaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2023-12-11 12:42:46 +0100
committervimene <vincent.menegaux@gmail.com>2023-12-11 12:42:46 +0100
commit6b765a85cf81bf4b7162e4c9280dd4054581c611 (patch)
tree4156dff7c632e6511fe18daebeea506744ad1ff7 /src/engine.cpp
parentff2c784d4c4100f0301628e8a52a6910d776d067 (diff)
downloadengine-6b765a85cf81bf4b7162e4c9280dd4054581c611.tar.gz
improved mesh definition
- In the context of mesh definition, splited indices into vertex index, normal index and vertex data index to be able to specify different normals and vertex data for different faces using the same vertex
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 96dfd7b..e8cde92 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -23,9 +23,8 @@
#include "o3d/scene.h"
#include "o3d/mesh.h"
#include "o3d/obj3d.h"
-#include "o3d/vertex.h"
#include "o3d/vertex_data.h"
-#include "o3d/tri_vertex.h"
+#include "o3d/tri.h"
#include "o3d/camera.h"
#include "math/vector.h"
#include "math/mat4.h"
@@ -87,11 +86,16 @@ static void scene_main(engine::Renderer& renderer, engine::math::Matrix4 final_t
for (int i = 0; i < 1; i++) {
auto final_mat = pre_final_mat * mats[i];
const auto& mesh = scene.objs[i].mesh;
- std::vector<engine::o3d::Vertex4> pts;
- for (const auto& vert : mesh.pts)
- pts.push_back({ final_mat * engine::math::Vector4{vert.point}, vert.data });
- for (auto face : mesh.faces)
- renderer.draw_triangle({pts[face[0]], pts[face[1]], pts[face[2]]});
+ std::vector<engine::math::Vector4> vertices;
+ for (const auto& vertex : mesh.vertices)
+ vertices.push_back(final_mat * vertex);
+ for (auto triangle_indices : mesh.indices) {
+ renderer.draw_triangle({
+ {vertices[triangle_indices[0][0]], mesh.normals[triangle_indices[0][1]], mesh.vertices_data[triangle_indices[0][2]]},
+ {vertices[triangle_indices[1][0]], mesh.normals[triangle_indices[1][1]], mesh.vertices_data[triangle_indices[1][2]]},
+ {vertices[triangle_indices[2][0]], mesh.normals[triangle_indices[2][1]], mesh.vertices_data[triangle_indices[2][2]]},
+ });
+ }
}
cont = update_frame();
}