-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71c9556
commit 293d47a
Showing
7 changed files
with
179 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef SOLAR_SYSTEM_CUBE_HPP | ||
#define SOLAR_SYSTEM_CUBE_HPP | ||
|
||
|
||
#include <vector> | ||
#include <string> | ||
#include "../utils.hpp" | ||
|
||
bool generateCube(float length, int divisions, const char* filepath); | ||
|
||
#endif //SOLAR_SYSTEM_PLANE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#include "utils.hpp" | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <vector> | ||
|
||
std::vector<Point> cubeTriangles(float length, int divisions) { | ||
|
||
float halfSize = length / 2.0f; | ||
float step = length / divisions; | ||
|
||
std::vector<Point> points; | ||
|
||
// Front face | ||
for(int i = 0; i < divisions; ++i) { | ||
for(int j = 0; j < divisions; ++j) { | ||
float x1 = -halfSize + i * step; | ||
float y1 = -halfSize + j * step; | ||
float x2 = x1 + step; | ||
float y2 = y1 + step; | ||
|
||
points.push_back(Point(x1, y1, halfSize)); | ||
points.push_back(Point(x2, y1, halfSize)); | ||
points.push_back(Point(x1, y2, halfSize)); | ||
|
||
points.push_back(Point(x2, y1, halfSize)); | ||
points.push_back(Point(x2, y2, halfSize)); | ||
points.push_back(Point(x1, y2, halfSize)); | ||
} | ||
} | ||
|
||
// Back face | ||
for(int i = 0; i < divisions; ++i) { | ||
for(int j = 0; j < divisions; ++j) { | ||
float x1 = -halfSize + i * step; | ||
float y1 = -halfSize + j * step; | ||
float x2 = x1 + step; | ||
float y2 = y1 + step; | ||
|
||
points.push_back(Point(x1, y1, -halfSize)); | ||
points.push_back(Point(x1, y2, -halfSize)); | ||
points.push_back(Point(x2, y1, -halfSize)); | ||
|
||
points.push_back(Point(x2, y1, -halfSize)); | ||
points.push_back(Point(x1, y2, -halfSize)); | ||
points.push_back(Point(x2, y2, -halfSize)); | ||
} | ||
} | ||
|
||
// Left face | ||
for(int i = 0; i < divisions; ++i) { | ||
for(int j = 0; j < divisions; ++j) { | ||
float y1 = -halfSize + i * step; | ||
float z1 = -halfSize + j * step; | ||
float y2 = y1 + step; | ||
float z2 = z1 + step; | ||
|
||
points.push_back(Point(-halfSize, y1, z1)); | ||
points.push_back(Point(-halfSize, y2, z1)); | ||
points.push_back(Point(-halfSize, y1, z2)); | ||
|
||
points.push_back(Point(-halfSize, y2, z1)); | ||
points.push_back(Point(-halfSize, y2, z2)); | ||
points.push_back(Point(-halfSize, y1, z2)); | ||
} | ||
} | ||
|
||
// Right face | ||
for(int i = 0; i < divisions; ++i) { | ||
for(int j = 0; j < divisions; ++j) { | ||
float y1 = -halfSize + i * step; | ||
float z1 = -halfSize + j * step; | ||
float y2 = y1 + step; | ||
float z2 = z1 + step; | ||
|
||
points.push_back(Point(halfSize, y1, z1)); | ||
points.push_back(Point(halfSize, y1, z2)); | ||
points.push_back(Point(halfSize, y2, z1)); | ||
|
||
points.push_back(Point(halfSize, y1, z2)); | ||
points.push_back(Point(halfSize, y2, z2)); | ||
points.push_back(Point(halfSize, y2, z1)); | ||
} | ||
} | ||
|
||
// Top face | ||
for(int i = 0; i < divisions; ++i) { | ||
for(int j = 0; j < divisions; ++j) { | ||
float x1 = -halfSize + i * step; | ||
float z1 = -halfSize + j * step; | ||
float x2 = x1 + step; | ||
float z2 = z1 + step; | ||
|
||
points.push_back(Point(x1, halfSize, z1)); | ||
points.push_back(Point(x2, halfSize, z1)); | ||
points.push_back(Point(x1, halfSize, z2)); | ||
|
||
points.push_back(Point(x2, halfSize, z1)); | ||
points.push_back(Point(x2, halfSize, z2)); | ||
points.push_back(Point(x1, halfSize, z2)); | ||
} | ||
} | ||
|
||
// Bottom face | ||
for(int i = 0; i < divisions; ++i) { | ||
for(int j = 0; j < divisions; ++j) { | ||
float x1 = -halfSize + i * step; | ||
float z1 = -halfSize + j * step; | ||
float x2 = x1 + step; | ||
float z2 = z1 + step; | ||
|
||
points.push_back(Point(x1, -halfSize, z1)); | ||
points.push_back(Point(x1, -halfSize, z2)); | ||
points.push_back(Point(x2, -halfSize, z1)); | ||
|
||
points.push_back(Point(x2, -halfSize, z1)); | ||
points.push_back(Point(x1, -halfSize, z2)); | ||
points.push_back(Point(x2, -halfSize, z2)); | ||
} | ||
} | ||
|
||
return points; | ||
} | ||
|
||
bool generateCube(float length, int divisions, const char* filepath) { // Changed parameter type to const char* | ||
std::vector<Point> triangles = cubeTriangles(length, divisions); | ||
|
||
if (triangles.empty()) { | ||
std::cerr << "Error: Empty vector of triangles.\n"; | ||
return false; | ||
} | ||
|
||
saveToFile(triangles, filepath); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
#include "utils.hpp" | ||
#include <string> | ||
#include <sstream> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <vector> | ||
|
||
std::string pointToString(Point point) { | ||
std::ostringstream oss; | ||
oss << point.x << " " << point.y << " " << point.z << "\n"; | ||
return oss.str(); | ||
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; | ||
} | ||
} |