-
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
c8781d6
commit e44dfc0
Showing
10 changed files
with
497 additions
and
544 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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
#ifndef CONE_HPP | ||
#define CONE_HPP | ||
|
||
#include <iostream> | ||
#include <cmath> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
#include <cmath> | ||
|
||
#include "../utils.hpp" | ||
|
||
bool generateCone(float radius, float height, int slices, int stacks, const char* filepath); | ||
bool generateCone(float radius, float height, int slices, int stacks, | ||
const char* filepath); | ||
|
||
#endif //CONE_HPP | ||
#endif // CONE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#ifndef CUBE_HPP | ||
#define CUBE_HPP | ||
|
||
|
||
#include <vector> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "../utils.hpp" | ||
|
||
bool generateCube(float length, int divisions, const char* filepath); | ||
|
||
#endif //CUBE_HPP | ||
#endif // CUBE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#ifndef SOLAR_SYSTEM_PLANE_HPP | ||
#define SOLAR_SYSTEM_PLANE_HPP | ||
|
||
|
||
#include <vector> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "../utils.hpp" | ||
|
||
bool generatePlane(float length, int divisions, const char* filepath); | ||
|
||
#endif //SOLAR_SYSTEM_PLANE_HPP | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
#include "utils.hpp" | ||
|
||
#include <iostream> | ||
#include <cmath> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
#include <cmath> | ||
|
||
std::vector<Point> coneTriangles(float radius, float height, int slices, int stacks) { | ||
std::vector<Point> points; | ||
float alfa = 2.0f * M_PI / slices; | ||
float yT = height / 2.0f; | ||
float yB = -height / 2.0f; | ||
float lastX = radius * cos(0); | ||
float lastZ = radius * sin(0); | ||
|
||
for (int i = 1; i <= slices; ++i) { | ||
float a = i * alfa; | ||
float x = radius * cos(a); | ||
float z = radius * sin(a); | ||
|
||
|
||
// Side triangles | ||
points.emplace_back(0, height, 0); | ||
points.emplace_back(x, 0, z); | ||
points.emplace_back(lastX, 0, lastZ); | ||
|
||
// Bottom triangles | ||
points.emplace_back(lastX, 0, lastZ); | ||
points.emplace_back(x, 0, z); | ||
points.emplace_back(0, 0, 0); | ||
|
||
lastX = x; | ||
lastZ = z; | ||
} | ||
|
||
return points; | ||
#include "utils.hpp" | ||
|
||
std::vector<Point> coneTriangles(float radius, float height, int slices, | ||
int stacks) { | ||
std::vector<Point> points; | ||
float alfa = 2.0f * M_PI / slices; | ||
float yT = height / 2.0f; | ||
float yB = -height / 2.0f; | ||
float lastX = radius * cos(0); | ||
float lastZ = radius * sin(0); | ||
|
||
for (int i = 1; i <= slices; ++i) { | ||
float a = i * alfa; | ||
float x = radius * cos(a); | ||
float z = radius * sin(a); | ||
|
||
// Side triangles | ||
points.emplace_back(0, height, 0); | ||
points.emplace_back(x, 0, z); | ||
points.emplace_back(lastX, 0, lastZ); | ||
|
||
// Bottom triangles | ||
points.emplace_back(lastX, 0, lastZ); | ||
points.emplace_back(x, 0, z); | ||
points.emplace_back(0, 0, 0); | ||
|
||
lastX = x; | ||
lastZ = z; | ||
} | ||
|
||
return points; | ||
} | ||
|
||
bool generateCone(float radius, float height, int slices, int stacks, const char* filepath) { | ||
std::vector<Point> triangles = coneTriangles(radius, height, slices, stacks); | ||
bool generateCone(float radius, float height, int slices, int stacks, | ||
const char* filepath) { | ||
std::vector<Point> triangles = coneTriangles(radius, height, slices, stacks); | ||
|
||
if (triangles.empty()) { | ||
std::cerr << "Error: Empty vector of triangles.\n"; | ||
return false; | ||
} | ||
if (triangles.empty()) { | ||
std::cerr << "Error: Empty vector of triangles.\n"; | ||
return false; | ||
} | ||
|
||
saveToFile(triangles, filepath); | ||
saveToFile(triangles, filepath); | ||
|
||
return true; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,90 @@ | ||
#include "utils.hpp" | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <iostream> | ||
#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(x1, y2, halfSize)); | ||
points.push_back(Point(x2, y1, halfSize)); | ||
points.push_back(Point(x2, 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(x1, y2, -halfSize)); | ||
points.push_back(Point(x2, y2, -halfSize)); | ||
points.push_back(Point(x2, y1, -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, 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)); | ||
} | ||
} | ||
|
||
// Right face | ||
for(int j = 0; j < divisions; ++j) { | ||
for(int i = 0; i < divisions; ++i) { | ||
float y1 = -halfSize + j * step; | ||
float z1 = -halfSize + i * 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, y1, z2)); | ||
points.push_back(Point(halfSize, y2, z1)); | ||
points.push_back(Point(halfSize, y2, z2)); | ||
} | ||
} | ||
|
||
// 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(x1, halfSize, z2)); | ||
points.push_back(Point(x2, halfSize, z1)); | ||
|
||
points.push_back(Point(x1, halfSize, z2)); | ||
points.push_back(Point(x2, halfSize, z2)); | ||
points.push_back(Point(x2, halfSize, z1)); | ||
} | ||
} | ||
#include "utils.hpp" | ||
|
||
// 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(x2, -halfSize, z1)); | ||
points.push_back(Point(x1, -halfSize, z2)); | ||
|
||
points.push_back(Point(x1, -halfSize, z2)); | ||
points.push_back(Point(x2, -halfSize, z1)); | ||
points.push_back(Point(x2, -halfSize, z2)); | ||
} | ||
std::vector<Point> cubeTriangles(float length, int divisions) { | ||
float halfSize = length / 2.0f; | ||
float step = length / divisions; | ||
|
||
std::vector<Point> points; | ||
|
||
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; | ||
|
||
// Front Face | ||
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(x1, y2, halfSize)); | ||
points.push_back(Point(x2, y1, halfSize)); | ||
points.push_back(Point(x2, y2, halfSize)); | ||
|
||
// Back Face | ||
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(x1, y2, -halfSize)); | ||
points.push_back(Point(x2, y2, -halfSize)); | ||
points.push_back(Point(x2, y1, -halfSize)); | ||
|
||
// Left Face | ||
points.push_back(Point(-halfSize, x1, y1)); | ||
points.push_back(Point(-halfSize, x1, y2)); | ||
points.push_back(Point(-halfSize, x2, y1)); | ||
|
||
points.push_back(Point(-halfSize, x1, y2)); | ||
points.push_back(Point(-halfSize, x2, y2)); | ||
points.push_back(Point(-halfSize, x2, y1)); | ||
|
||
// Right Face | ||
points.push_back(Point(halfSize, x1, y1)); | ||
points.push_back(Point(halfSize, x2, y1)); | ||
points.push_back(Point(halfSize, x1, y2)); | ||
|
||
points.push_back(Point(halfSize, x1, y2)); | ||
points.push_back(Point(halfSize, x2, y1)); | ||
points.push_back(Point(halfSize, x2, y2)); | ||
|
||
// Top Face | ||
points.push_back(Point(x1, halfSize, y1)); | ||
points.push_back(Point(x1, halfSize, y2)); | ||
points.push_back(Point(x2, halfSize, y1)); | ||
|
||
points.push_back(Point(x1, halfSize, y2)); | ||
points.push_back(Point(x2, halfSize, y2)); | ||
points.push_back(Point(x2, halfSize, y1)); | ||
|
||
// Bottom Face | ||
points.push_back(Point(x1, -halfSize, y1)); | ||
points.push_back(Point(x2, -halfSize, y1)); | ||
points.push_back(Point(x1, -halfSize, y2)); | ||
|
||
points.push_back(Point(x1, -halfSize, y2)); | ||
points.push_back(Point(x2, -halfSize, y1)); | ||
points.push_back(Point(x2, -halfSize, y2)); | ||
} | ||
} | ||
|
||
return points; | ||
return points; | ||
} | ||
|
||
bool generateCube(float length, int divisions, const char* filepath) { | ||
std::vector<Point> triangles = cubeTriangles(length, divisions); | ||
std::vector<Point> triangles = cubeTriangles(length, divisions); | ||
|
||
if (triangles.empty()) { | ||
std::cerr << "Error: Empty vector of triangles.\n"; | ||
return false; | ||
} | ||
if (triangles.empty()) { | ||
std::cerr << "Error: Empty vector of triangles.\n"; | ||
return false; | ||
} | ||
|
||
saveToFile(triangles, filepath); | ||
saveToFile(triangles, filepath); | ||
|
||
return true; | ||
return true; | ||
} |
Oops, something went wrong.