diff --git a/engine/include/draw.hpp b/engine/include/draw.hpp index 4c3fb06..6ca1a91 100644 --- a/engine/include/draw.hpp +++ b/engine/include/draw.hpp @@ -2,7 +2,9 @@ #define DRAW_HPP #include + #include + #include "draw.hpp" #include "utils.hpp" @@ -10,4 +12,4 @@ void drawTriangles(const std::vector& points); void drawFile(char* filename); -#endif //DRAW_HPP +#endif // DRAW_HPP diff --git a/engine/src/draw.cpp b/engine/src/draw.cpp index 26c4953..d66ca13 100644 --- a/engine/src/draw.cpp +++ b/engine/src/draw.cpp @@ -6,31 +6,31 @@ #define _USE_MATH_DEFINES #include + #include + #include "draw.hpp" #include "utils.hpp" void drawTriangles(const std::vector& points) { - glBegin(GL_TRIANGLES); - for (size_t i = 0; i < points.size(); i += 3) { - // Draw each triangle - glVertex3f(points[i].x, points[i].y, points[i].z); - glVertex3f(points[i + 1].x, points[i + 1].y, points[i + 1].z); - glVertex3f(points[i + 2].x, points[i + 2].y, points[i + 2].z); - } - glEnd(); + glBegin(GL_TRIANGLES); + for (size_t i = 0; i < points.size(); i += 3) { + // Draw each triangle + glVertex3f(points[i].x, points[i].y, points[i].z); + glVertex3f(points[i + 1].x, points[i + 1].y, points[i + 1].z); + glVertex3f(points[i + 2].x, points[i + 2].y, points[i + 2].z); + } + glEnd(); } void drawFile(char* filename) { + std::string dir = "../models/"; + dir.append(filename); - std::string dir = "../models/"; - dir.append(filename); - - std::vector points = parseFile(dir); - if (points.empty()) { - // File not found or empty, handle this case - return; - } - drawTriangles(points); + std::vector points = parseFile(dir); + if (points.empty()) { + // File not found or empty, handle this case + return; + } + drawTriangles(points); } - diff --git a/engine/src/main.cpp b/engine/src/main.cpp index fae933e..29b8a22 100644 --- a/engine/src/main.cpp +++ b/engine/src/main.cpp @@ -6,8 +6,8 @@ #define _USE_MATH_DEFINES #include -#include "draw.hpp" +#include "draw.hpp" char* file = ""; @@ -39,30 +39,29 @@ void renderScene(void) { // put drawing instructions here glBegin(GL_LINES); - // x-axis (red) - glColor3f(1.0f, 0.0f, 0.0f); - glVertex3f(-1.0f, 0.0f, 0.0f); - glVertex3f(1.0f, 0.0f, 0.0f); - // y-axis (green) - glColor3f(0.0f, 1.0f, 0.0f); - glVertex3f(0.0f, -1.0f, 0.0f); - glVertex3f(0.0f, 1.0f, 0.0f); - // z-axis (blue) - glColor3f(0.0f, 0.0f, 1.0f); - glVertex3f(0.0f, 0.0f, -1.0f); - glVertex3f(0.0f, 0.0f, 1.0f); - glEnd(); + // x-axis (red) + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(-1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, 0.0f, 0.0f); + // y-axis (green) + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(0.0f, -1.0f, 0.0f); + glVertex3f(0.0f, 1.0f, 0.0f); + // z-axis (blue) + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(0.0f, 0.0f, -1.0f); + glVertex3f(0.0f, 0.0f, 1.0f); + glEnd(); glEnd(); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); drawFile(file); - // End of frame glutSwapBuffers(); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { // put GLUT�s init here glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); @@ -76,10 +75,9 @@ int main(int argc, char **argv) { glutIdleFunc(renderScene); glutDisplayFunc(renderScene); - // some OpenGL settings glEnable(GL_DEPTH_TEST); - //glEnable(GL_CULL_FACE); + // glEnable(GL_CULL_FACE); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // enter GLUT�s main cycle diff --git a/engine/src/utils.cpp b/engine/src/utils.cpp index 86aa5d5..c894b88 100644 --- a/engine/src/utils.cpp +++ b/engine/src/utils.cpp @@ -7,18 +7,18 @@ #include std::vector parseFile(std::string filename) { - std::vector points; - std::ifstream file(filename); - - if (!file.is_open()) { - std::cerr << "Error: Unable to open file " << filename << std::endl; - return points; - } + std::vector points; + std::ifstream file(filename); - Point point; - while (file >> point.x >> point.y >> point.z) { - points.push_back(point); - } - file.close(); + if (!file.is_open()) { + std::cerr << "Error: Unable to open file " << filename << std::endl; return points; + } + + Point point; + while (file >> point.x >> point.y >> point.z) { + points.push_back(point); + } + file.close(); + return points; } \ No newline at end of file diff --git a/generator/src/main.cpp b/generator/src/main.cpp index d844a40..ca54dcc 100644 --- a/generator/src/main.cpp +++ b/generator/src/main.cpp @@ -10,7 +10,7 @@ void generateFigure(int argc, char* argv[]) { return; } - std::string figureType = argv[argc - 1]; + char* figureType = argv[argc - 1]; std::string figureName = argv[1]; if (figureName == "sphere" && argc == 6) { @@ -22,7 +22,7 @@ void generateFigure(int argc, char* argv[]) { float length = std::stof(argv[2]); int divisions = std::stoi(argv[3]); - generateCube(length, divisions, argv[4]); + generateCube(length, divisions, figureType); } else if (figureName == "plane" && argc == 5) { // Generate Plane std::cout << "Generating Plane\n"; // Added newline here @@ -30,7 +30,7 @@ void generateFigure(int argc, char* argv[]) { int divisions = std::stoi(argv[3]); generatePlane(length, divisions, - argv[4]); // Assuming saveToFile is available + figureType); // Assuming saveToFile is available } else if (figureName == "cone" && argc == 7) { // Generate Cone std::cout << "Generating Cone\n";