From 26b4b82a7be2c029491f3009b66b3cbf8db5d93c Mon Sep 17 00:00:00 2001 From: vimene Date: Thu, 2 Jan 2025 13:25:14 +0100 Subject: various improvements - cleaned up the computation of the camera's matrix - changed VertexData to being a struct which transmit data between the "vertex shader" and the "fragment shader" - started working on keyboard and mouse controls - added fov (field of view) - changed quaternion to euler angles conversion, from zyx to zxy - fixed computations of z coordinates in triangle rendering - improved naming in the triangle rasterizer --- src/obj_parser.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/obj_parser.cpp') diff --git a/src/obj_parser.cpp b/src/obj_parser.cpp index ad71935..f765f5c 100644 --- a/src/obj_parser.cpp +++ b/src/obj_parser.cpp @@ -34,7 +34,7 @@ float parse_float(const std::string& s) { if (s[ind++] == '-') positive = !positive; - // improve error checking + // TODO: improve error checking if (ind == s.length()) return 0.f; @@ -45,7 +45,7 @@ float parse_float(const std::string& s) { if (ind == s.length()) return (positive ? 1.f : -1.f) * static_cast(n); - // improve error checking + // TODO: improve error checking if (s[ind] != '.') return 0.f; @@ -58,7 +58,7 @@ float parse_float(const std::string& s) { decimal_fac *= .1f; } - // improve error checking + // TODO: improve error checking if (ind != s.length()) return 0.f; @@ -72,7 +72,7 @@ float parse_int(const std::string& s) { if (s[ind++] == '-') positive = !positive; - // improve error checking + // TODO: improve error checking if (ind == s.length()) return 0.f; @@ -80,7 +80,7 @@ float parse_int(const std::string& s) { while (ind < s.length() && s[ind] >= '0' && s[ind] <= '9') n = n * 10 + static_cast(s[ind++]) - static_cast('0'); - // improve error checking + // TODO: improve error checking if (ind != s.length()) return 0.f; @@ -91,7 +91,6 @@ float parse_int(const std::string& s) { o3d::Mesh parse_object(const std::string& obj_path) { o3d::Mesh mesh; - mesh.vertices_data.push_back(o3d::VertexData(0.f, 0.f)); std::ifstream obj_file(obj_path); std::string line; while (std::getline(obj_file, line)) { @@ -119,13 +118,12 @@ o3d::Mesh parse_object(const std::string& obj_path) { // } // std::cout << "Smooth: " << std::boolalpha << smooth << std::endl; } else if (line.rfind("f ", 0) == 0) { - std::array, 3> indices; + std::array, 3> indices; auto line_split = split(line.substr(2), ' '); for (int i = 0; i < 3; i++) { auto indices_s_group = split(line_split[i], '/'); indices[i][0] = parse_int(indices_s_group[0]) - 1; indices[i][1] = parse_int(indices_s_group[2]) - 1; - indices[i][2] = 0; } // std::cout << "Face:" // << " 1: vertex: " << indices[0][0] << " normal: " << indices[0][1] -- cgit v1.2.3