Skip to content

Commit

Permalink
big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed Feb 27, 2024
1 parent 13563e4 commit 71c9556
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 287 deletions.
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
CMakeFiles/*
CMakeCache.txt
*.cmake
Makefile
.vscode
*/Makefile
*.3d
*/CMakeCache.txt
generator/CMakeFiles/*
engine/CMakeFiles/*
generator
visualizer
bin/*
engine
models/*
.idea/*
71 changes: 0 additions & 71 deletions CMakeLists.txt

This file was deleted.

Empty file added engine/CMakeLists.txt
Empty file.
3 changes: 3 additions & 0 deletions engine/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//
// Created by juliojpinto on 27-02-2024.
//
12 changes: 12 additions & 0 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})


17 changes: 17 additions & 0 deletions generator/include/shapes/plane.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef SOLAR_SYSTEM_PLANE_HPP
#define SOLAR_SYSTEM_PLANE_HPP


#include <vector>
#include <string>
#include "../utils.hpp"

std::vector<Point> calculateTriangles(float length, int divisions);

void saveToFile(const std::vector<Point>& points, const std::string& filepath);

bool generatePlane(float length, int divisions, const char* filepath);



#endif //SOLAR_SYSTEM_PLANE_HPP
21 changes: 21 additions & 0 deletions generator/include/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef SOLAR_SYSTEM_UTILS_HPP
#define SOLAR_SYSTEM_UTILS_HPP

#include <string>
#include <sstream>

// 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
38 changes: 38 additions & 0 deletions generator/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <string>
#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;
}
70 changes: 70 additions & 0 deletions generator/src/shapes/plane.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "utils.hpp"

#include <iostream>
#include <fstream>
#include <vector>

float planeWidth = 5.0f;
float planeLength = 5.0f;
int divisions = 3;

std::vector<Point> calculateTriangles(float length, int divisions) {
float half = length / 2.0f;
float steps = length / divisions;

std::vector<Point> 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<Point>& 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<Point> triangles = calculateTriangles(length, divisions);

if (triangles.empty()) {
std::cerr << "Error: Empty vector of triangles.\n";
return false;
}

saveToFile(triangles, filepath);

return true;
}
9 changes: 9 additions & 0 deletions generator/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "utils.hpp"
#include <string>
#include <sstream>

std::string pointToString(Point point) {
std::ostringstream oss;
oss << point.x << " " << point.y << " " << point.z << "\n";
return oss.str();
}
15 changes: 0 additions & 15 deletions include/figure.hpp

This file was deleted.

48 changes: 0 additions & 48 deletions include/figure_generator.hpp

This file was deleted.

Loading

0 comments on commit 71c9556

Please sign in to comment.