Skip to content

Commit

Permalink
fix: problems
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Mar 7, 2024
1 parent e5d8f8d commit d345c2b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ add_subdirectory(generator)
add_subdirectory(engine)
target_include_directories(common PUBLIC common/include)
target_include_directories(generator PUBLIC generator/include)
target_include_directories(engine PUBLIC engine/include)
target_include_directories(engine PUBLIC engine/include)
45 changes: 45 additions & 0 deletions common/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,48 @@ void saveToFile(
std::cerr << "Unable to open file: " << filepath << std::endl;
}
}

std::vector<Point> parseOBJfile(std::string filename, std::string type) {
std::vector<Point> points;
std::vector<Point> sorted_points;
std::ifstream file(filename);

std::string line;
while (std::getline(file, line)) {
std::istringstream iss(line);
std::string type;
iss >> type;
if (type == "v") {
Point point;
iss >> point.x >> point.y >> point.z;
points.push_back(point);
} else if (type == "f") {
std::string vertex;
std::vector<int> vertex_indices;
while (iss >> vertex) {
std::string index = vertex.substr(0, vertex.find("/"));
vertex_indices.push_back(std::stoi(index) - 1);
}
for (int i = 0; i < vertex_indices.size(); i++) {
sorted_points.push_back(points[vertex_indices[i]]);
}
}
}
file.close();

return sorted_points;
}

std::vector<Point> parse3Dfile(std::string filename) {
std::vector<Point> points;
std::ifstream file(filename);

Point point;
while (file >> point.x >> point.y >> point.z) {
points.push_back(point);
}

file.close();

return points;
}
3 changes: 2 additions & 1 deletion generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ cmake_minimum_required(VERSION 3.5)
# Project Name
project(generator)

include_directories(${PROJECT_NAME} PUBLIC include)

file(GLOB SRC_FILES src/shapes/*.cpp src/*.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})

include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} common)
1 change: 0 additions & 1 deletion generator/src/shapes/cone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ bool generateCone(float radius, float height, int slices, int stacks,
std::cerr << "Error: Empty vector of triangles.\n";
return false;
}

saveToFile(triangles, filepath);

return true;
Expand Down
7 changes: 6 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ build_dir=build

cmake -S . -B $build_dir

(cd $build_dir && make)
cd engine
make
cd ..
cd generator
make
cd ..

0 comments on commit d345c2b

Please sign in to comment.