diff --git a/.gitignore b/.gitignore index 49b7584..7996f1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ -CMakeFiles/* -CMakeCache.txt *.cmake -Makefile -.vscode +*/Makefile +*.3d +*/CMakeCache.txt +generator/CMakeFiles/* +engine/CMakeFiles/* generator -visualizer -bin/* \ No newline at end of file +engine +models/* +.idea/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index feccaf0..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -# Project Name -project(visualizer) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) - -# Set the output directory for object files -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/obj) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/obj) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(INCLUDE_PATH "include") - -add_library(visualizer STATIC src/visualizer.cpp) -target_include_directories(visualizer PUBLIC include) -add_executable(${PROJECT_NAME} src/engine.cpp) -add_executable(generator src/generator.cpp) - -find_package(OpenGL REQUIRED) -include_directories(${OpenGL_INCLUDE_DIRS}) -link_directories(${OpenGL_LIBRARY_DIRS}) -add_definitions(${OpenGL_DEFINITIONS}) - -target_include_directories(visualizer PUBLIC include) -target_include_directories(generator PUBLIC include) - -if(NOT OPENGL_FOUND) - message(FATAL_ERROR "OPENGL not found!") -endif(NOT OPENGL_FOUND) - -if(WIN32) - message(STATUS "Toolkits_DIR set to: ${TOOLKITS_FOLDER}") - set(TOOLKITS_FOLDER "" CACHE PATH "Path to Toolkits folder") - - if(NOT EXISTS "${TOOLKITS_FOLDER}/glut/GL/glut.h" OR NOT EXISTS "${TOOLKITS_FOLDER}/glut/glut32.lib") - message(FATAL_ERROR "GLUT not found") - endif(NOT EXISTS "${TOOLKITS_FOLDER}/glut/GL/glut.h" OR NOT EXISTS "${TOOLKITS_FOLDER}/glut/glut32.lib") - - include_directories(${TOOLKITS_FOLDER}/glut) - target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${TOOLKITS_FOLDER}/glut/glut32.lib) - - if(EXISTS "${TOOLKITS_FOLDER}/glut/glut32.dll") - file(COPY ${TOOLKITS_FOLDER}/glut/glut32.dll DESTINATION ${CMAKE_BINARY_DIR}/bin) - endif(EXISTS "${TOOLKITS_FOLDER}/glut/glut32.dll") - - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated") - find_package(GLUT REQUIRED) - include_directories(${GLUT_INCLUDE_DIR}) - link_directories(${GLUT_LIBRARY_DIRS}) - add_definitions(${GLUT_DEFINITIONS}) - - target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES}) - if(NOT GLUT_FOUND) - message(FATAL_ERROR "GLUT not found!") - endif(NOT GLUT_FOUND) -endif() - -# Adding clang-format target -find_program(CLANG_FORMAT_EXECUTABLE NAMES "clang-format") -if(NOT CLANG_FORMAT_EXECUTABLE) - message(WARNING "clang-format not found. Formatting will not be available.") -else() - file(GLOB_RECURSE ALL_SOURCE_FILES src/*.cpp include/*.hpp) - add_custom_target( - format - COMMAND ${CLANG_FORMAT_EXECUTABLE} -style=Google -i ${ALL_SOURCE_FILES} - COMMENT "Running clang-format" - ) -endif() diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/engine/main.cpp b/engine/main.cpp new file mode 100644 index 0000000..316ef16 --- /dev/null +++ b/engine/main.cpp @@ -0,0 +1,3 @@ +// +// Created by juliojpinto on 27-02-2024. +// diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt new file mode 100644 index 0000000..e5a9c8b --- /dev/null +++ b/generator/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.5) + +# Project Name +project(generator) + +# Include directories +include_directories(${PROJECT_NAME} PUBLIC include) # Assuming headers are in the 'include' directory + +file(GLOB SRC_FILES src/shapes/*.cpp src/*.cpp) +add_executable(${PROJECT_NAME} ${SRC_FILES}) + + diff --git a/generator/include/shapes/plane.hpp b/generator/include/shapes/plane.hpp new file mode 100644 index 0000000..eb0a303 --- /dev/null +++ b/generator/include/shapes/plane.hpp @@ -0,0 +1,17 @@ +#ifndef SOLAR_SYSTEM_PLANE_HPP +#define SOLAR_SYSTEM_PLANE_HPP + + +#include +#include +#include "../utils.hpp" + +std::vector calculateTriangles(float length, int divisions); + +void saveToFile(const std::vector& points, const std::string& filepath); + +bool generatePlane(float length, int divisions, const char* filepath); + + + +#endif //SOLAR_SYSTEM_PLANE_HPP diff --git a/generator/include/utils.hpp b/generator/include/utils.hpp new file mode 100644 index 0000000..5a951d0 --- /dev/null +++ b/generator/include/utils.hpp @@ -0,0 +1,21 @@ +#ifndef SOLAR_SYSTEM_UTILS_HPP +#define SOLAR_SYSTEM_UTILS_HPP + +#include +#include + +// Define Point struct +typedef struct Point { + float x; + float y; + float z; + + // Constructor + Point(float x_val = 0.0f, float y_val = 0.0f, float z_val = 0.0f) + : x(x_val), y(y_val), z(z_val) {} +} Point; + +// Function to convert Point to string +std::string pointToString(const Point& point); + +#endif //SOLAR_SYSTEM_UTILS_HPP diff --git a/generator/src/main.cpp b/generator/src/main.cpp new file mode 100644 index 0000000..8b854db --- /dev/null +++ b/generator/src/main.cpp @@ -0,0 +1,38 @@ +#include +#include +#include "../include/shapes/plane.hpp" + +void generateFigure(int argc, char* argv[]) { + if (argc < 5) { + std::cerr << "Insufficient arguments\n"; + return; + } + + std::string figureType = argv[argc - 1]; + std::string figureName = argv[1]; + + if (figureName == "sphere" && figureType == "sphere.3d" && argc == 6) { + // Generate Sphere + std::cout << "Generating Sphere\n"; + } else if (figureName == "box" && figureType == "box.3d" && argc == 5) { + // Generate Box + std::cout << "Generating Box\n"; + } else if (figureName == "plane" && figureType == "plane.3d" && argc == 5) { + // Generate Plane + std::cout << "Generating Plane\n"; // Added newline here + float length = std::stof(argv[2]); + int divisions = std::stoi(argv[3]); + + generatePlane(length, divisions, argv[4]); // Assuming saveToFile is available + } else if (figureName == "cone" && figureType == "cone.3d" && argc == 7) { + // Generate Cone + std::cout << "Generating Cone\n"; + } else { + std::cerr << "Invalid arguments\n"; + } +} + +int main(int argc, char* argv[]) { + generateFigure(argc, argv); + return 0; +} diff --git a/generator/src/shapes/plane.cpp b/generator/src/shapes/plane.cpp new file mode 100644 index 0000000..87428c9 --- /dev/null +++ b/generator/src/shapes/plane.cpp @@ -0,0 +1,70 @@ +#include "utils.hpp" + +#include +#include +#include + +float planeWidth = 5.0f; +float planeLength = 5.0f; +int divisions = 3; + +std::vector calculateTriangles(float length, int divisions) { + float half = length / 2.0f; + float steps = length / divisions; + + std::vector points; + + for (int i = 0; i < divisions; i++) { + for (int j = 0; j < divisions; j++) { + + float x1 = -half + i * steps; + float y1 = 0.0f; // Adjusted for consistency with the Point constructor + float z1 = -half + j * steps; + float x2 = -half + (i + 1) * steps; + float y2 = 0.0f; // Adjusted for consistency with the Point constructor + float z2 = -half + (j + 1) * steps; + + Point p1(x1, y1, z1); // Corrected the constructor usage + Point p2(x2, y1, z1); + Point p3(x1, y1, z2); + Point p4(x2, y1, z2); + + points.push_back(p1); + points.push_back(p2); + points.push_back(p3); + + points.push_back(p2); + points.push_back(p4); + points.push_back(p3); + } + } + + return points; +} + +void saveToFile(const std::vector& points, const char* filepath) { // Changed parameter type to const char* + std::ofstream file(filepath); + + if (file.is_open()) { + for (const auto& point : points) { + file << point.x << " " << point.y << " " << point.z << "\n"; + } + file.close(); + std::cout << "File saved successfully.\n"; + } else { + std::cerr << "Unable to open file: " << filepath << std::endl; + } +} + +bool generatePlane(float length, int divisions, const char* filepath) { // Changed parameter type to const char* + std::vector triangles = calculateTriangles(length, divisions); + + if (triangles.empty()) { + std::cerr << "Error: Empty vector of triangles.\n"; + return false; + } + + saveToFile(triangles, filepath); + + return true; +} \ No newline at end of file diff --git a/generator/src/utils.cpp b/generator/src/utils.cpp new file mode 100644 index 0000000..0f1b3e8 --- /dev/null +++ b/generator/src/utils.cpp @@ -0,0 +1,9 @@ +#include "utils.hpp" +#include +#include + +std::string pointToString(Point point) { + std::ostringstream oss; + oss << point.x << " " << point.y << " " << point.z << "\n"; + return oss.str(); +} diff --git a/include/figure.hpp b/include/figure.hpp deleted file mode 100644 index 98df288..0000000 --- a/include/figure.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include -#include -#include - -typedef std::vector> Point; - -class Figure { - public: - Figure(); - void exportFile(std::string filename); - - private: - std::vector points; -}; \ No newline at end of file diff --git a/include/figure_generator.hpp b/include/figure_generator.hpp deleted file mode 100644 index bd184b8..0000000 --- a/include/figure_generator.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once -#include - -#include "figure.hpp" - -/** - * @brief Generates a plane - * - * @param length the length of the plane - * @param divisions the number of divisions - * - * @return the generated plane - */ -std::unique_ptr
generatePlane(float length, int divisions); - -/** - * @brief Generates a box - * - * @param dimension the dimension of the box - * @param divisions the number of divisions - * - * @return the generated box - */ -std::unique_ptr
generateBox(float dimension, int divisions); - -/** - * @brief Generates a sphere - * - * @param radius the radius of the sphere - * @param slices the number of slices - * @param stacks the number of stacks - * - * @return the generated sphere - */ -std::unique_ptr
generateSphere(float radius, int slices, int stacks); - -/** - * @brief Generates a cone - * - * @param radius the radius of the cone - * @param height the height of the cone - * @param slices the number of slices - * @param stacks the number of stacks - * - * @return the generated cone - */ -std::unique_ptr
generateCone(float radius, float height, int slices, - int stacks); diff --git a/src/engine.cpp b/src/engine.cpp deleted file mode 100644 index 9324e89..0000000 --- a/src/engine.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifdef __APPLE__ -#include -#else -#include -#endif - -#define _USE_MATH_DEFINES -#include - -void changeSize(int w, int h) { - // Prevent a divide by zero, when window is too short - // (you can�t make a window with zero width). - if (h == 0) h = 1; - // compute window's aspect ratio - float ratio = w * 1.0f / h; - // Set the projection matrix as current - glMatrixMode(GL_PROJECTION); - // Load the identity matrix - glLoadIdentity(); - // Set the viewport to be the entire window - glViewport(0, 0, w, h); - // Set the perspective - gluPerspective(45.0f, ratio, 1.0f, 1000.0f); - // return to the model view matrix mode - glMatrixMode(GL_MODELVIEW); -} - -void renderScene(void) { - // clear buffers - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // set camera - glLoadIdentity(); - gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); - - // put drawing instructions here - glutWireTeapot(1); - - // End of frame - glutSwapBuffers(); -} - -int main(int argc, char **argv) { - // put GLUT�s init here - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); - glutInitWindowPosition(100, 100); - glutInitWindowSize(800, 800); - glutCreateWindow("CG@DI"); - - // put callback registry here - glutReshapeFunc(changeSize); - glutIdleFunc(renderScene); - glutDisplayFunc(renderScene); - - // some OpenGL settings - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - - // enter GLUT�s main cycle - glutMainLoop(); - - return 1; -} \ No newline at end of file diff --git a/src/figure.cpp b/src/figure.cpp deleted file mode 100644 index c152513..0000000 --- a/src/figure.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "figure.hpp" - -#include - -Figure::Figure() { points = std::vector(); } - -void Figure::exportFile(std::string filename) { - std::ofstream file(filename); - file << "Test\n"; - file.close(); -} \ No newline at end of file diff --git a/src/figure_generator.cpp b/src/figure_generator.cpp deleted file mode 100644 index 6ff9982..0000000 --- a/src/figure_generator.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "figure_generator.hpp" - -#include - -// This is a placeholder for the actual implementation of the functions - -std::unique_ptr
generatePlane(float length, int divisions) { - std::cout << "Generating Plane\n"; - return std::make_unique
(); -} - -std::unique_ptr
generateBox(float dimension, int divisions) { - std::cout << "Generating Box\n"; - return std::make_unique
(); -} - -std::unique_ptr
generateSphere(float radius, int slices, int stacks) { - std::cout << "Generating Sphere\n"; - return std::make_unique
(); -} - -std::unique_ptr
generateCone(float radius, float height, int slices, - int stacks) { - std::cout << "Generating Cone\n"; - return std::make_unique
(); -} diff --git a/src/generator.cpp b/src/generator.cpp deleted file mode 100644 index 18159b0..0000000 --- a/src/generator.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include - -#include - -#include "figure.hpp" -#include "figure_generator.hpp" // Include the figure_generator header - -inline std::unique_ptr
generateFigure(int argc, char* argv[]) { - if (argc < 5) { - std::cerr << "Insufficient arguments\n"; - return nullptr; - } - - std::string figureType = argv[argc - 1]; - std::string figureName = argv[1]; - - if (figureName == "sphere" && figureType == "sphere.3d" && argc == 6) { - // Generate Sphere - std::cout << "Generating Sphere\n"; - return nullptr; - } else if (figureName == "box" && figureType == "box.3d" && argc == 5) { - // Generate Box - std::cout << "Generating Box\n"; - return nullptr; - } else if (figureName == "plane" && figureType == "plane.3d" && argc == 5) { - // Generate Plane - std::cout << "Generating Plane\n"; // Added newline here - float length = std::stof(argv[2]); - int divisions = std::stoi(argv[3]); - // generatePlane(length, divisions); - return nullptr; - } else if (figureName == "cone" && figureType == "cone.3d" && argc == 7) { - // Generate Cone - std::cout << "Generating Cone\n"; - return nullptr; - } else { - std::cerr << "Invalid arguments\n"; - return nullptr; - } -} - -int main(int argc, char* argv[]) { - std::unique_ptr
figure = generateFigure(argc, argv); - return 0; -}