aboutsummaryrefslogtreecommitdiff
path: root/src/obj_parser.cpp
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2025-01-02 13:25:14 +0100
committervimene <vincent.menegaux@gmail.com>2025-01-02 13:25:14 +0100
commit26b4b82a7be2c029491f3009b66b3cbf8db5d93c (patch)
treeddc247a0600b5933185677212f158ebea5a87530 /src/obj_parser.cpp
parent9fdb5881d46f5d80626f961f9c9f133cc25dab70 (diff)
downloadengine-26b4b82a7be2c029491f3009b66b3cbf8db5d93c.tar.gz
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
Diffstat (limited to 'src/obj_parser.cpp')
-rw-r--r--src/obj_parser.cpp14
1 files changed, 6 insertions, 8 deletions
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<float>(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<int>(s[ind++]) - static_cast<int>('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<std::array<std::size_t, 3>, 3> indices;
+ std::array<std::array<std::size_t, 2>, 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]