-
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
96ab0d9
commit cbcf6b6
Showing
4 changed files
with
96 additions
and
7 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 CYLINDER_HPP | ||
#define CYLINDER_HPP | ||
|
||
#include <string> | ||
|
||
#include "cylinder.hpp" | ||
|
||
bool generateCylinder(float radius, float height, int slices, | ||
const char* filepath); | ||
|
||
#endif // CYLINDER_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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
#define SOLAR_SYSTEM_PLANE_HPP | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "../utils.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "../../include/shapes/cylinder.hpp" | ||
|
||
#include <cmath> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
#include "utils.hpp" | ||
|
||
std::vector<Point> cylinderTriangles(const float radius, const float height, | ||
const int slices) { | ||
std::vector<Point> vertex; | ||
|
||
float alpha = 2 * M_PI / slices; | ||
float r = 0; | ||
|
||
for (int i = 0; i < slices; i++) { | ||
// base | ||
float px = radius * sin(r); | ||
float pz = radius * cos(r); | ||
vertex.push_back(Point(px, 0, pz)); | ||
vertex.push_back(Point(0, 0, 0)); | ||
r += alpha; | ||
px = radius * sin(r); | ||
pz = radius * cos(r); | ||
vertex.push_back(Point(px, 0, pz)); | ||
|
||
// face | ||
vertex.push_back(Point(px, 0, pz)); | ||
vertex.push_back(Point(px, height, pz)); | ||
r -= alpha; | ||
px = radius * sin(r); | ||
pz = radius * cos(r); | ||
vertex.push_back(Point(px, height, pz)); | ||
|
||
vertex.push_back(Point(px, height, pz)); | ||
vertex.push_back(Point(px, 0, pz)); | ||
r += alpha; | ||
px = radius * sin(r); | ||
pz = radius * cos(r); | ||
vertex.push_back(Point(px, 0, pz)); | ||
|
||
// topo | ||
r += alpha; | ||
px = radius * sin(r); | ||
pz = radius * cos(r); | ||
vertex.push_back(Point(px, height, pz)); | ||
vertex.push_back(Point(0, height, 0)); | ||
r -= alpha; | ||
px = radius * sin(r); | ||
pz = radius * cos(r); | ||
vertex.push_back(Point(px, height, pz)); | ||
} | ||
|
||
return vertex; | ||
} | ||
|
||
bool generateCylinder(float radius, float height, int slices, | ||
const char* filepath) { | ||
std::vector<Point> triangles = cylinderTriangles(radius, height, slices); | ||
|
||
if (triangles.empty()) { | ||
std::cerr << "Error: Empty vector of triangles.\n"; | ||
return false; | ||
} | ||
|
||
saveToFile(triangles, filepath); | ||
|
||
return true; | ||
} |