Skip to content

Commit

Permalink
fix: formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Feb 29, 2024
1 parent 787f549 commit 854af3d
Show file tree
Hide file tree
Showing 3 changed files with 654 additions and 49 deletions.
6 changes: 3 additions & 3 deletions generator/include/shapes/sphere.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef SOLAR_SYSTEM_SPHERE_HPP
#define SOLAR_SYSTEM_SPHERE_HPP


#include <vector>
#include <string>
#include <vector>

#include "../utils.hpp"

bool generateSphere(float radius, int slices, int stacks, const char* filepath);

#endif //SOLAR_SYSTEM_SPHERE_HPP
#endif // SOLAR_SYSTEM_SPHERE_HPP
97 changes: 51 additions & 46 deletions generator/src/shapes/sphere.cpp
Original file line number Diff line number Diff line change
@@ -1,61 +1,66 @@
#include <cmath>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>

#include "utils.hpp"

std::vector<Point> sphereTriangles(float radius, int slices, int stacks) {
std::vector<Point> points;

for (int i = 0; i < slices; ++i) {
float theta1 = static_cast<float>(i) * static_cast<float>(M_PI) / static_cast<float>(slices);
float theta2 = static_cast<float>(i + 1) * static_cast<float>(M_PI) / static_cast<float>(slices);

for (int j = 0; j < stacks; ++j) {
float phi1 = static_cast<float>(j) * 2.0f * static_cast<float>(M_PI) / static_cast<float>(stacks);
float phi2 = static_cast<float>(j + 1) * 2.0f * static_cast<float>(M_PI) / static_cast<float>(stacks);

// Vertices
float x1 = radius * std::sin(theta1) * std::cos(phi1);
float y1 = radius * std::sin(theta1) * std::sin(phi1);
float z1 = radius * std::cos(theta1);

float x2 = radius * std::sin(theta1) * std::cos(phi2);
float y2 = radius * std::sin(theta1) * std::sin(phi2);
float z2 = radius * std::cos(theta1);

float x3 = radius * std::sin(theta2) * std::cos(phi1);
float y3 = radius * std::sin(theta2) * std::sin(phi1);
float z3 = radius * std::cos(theta2);

float x4 = radius * std::sin(theta2) * std::cos(phi2);
float y4 = radius * std::sin(theta2) * std::sin(phi2);
float z4 = radius * std::cos(theta2);

// Push vertices in counter-clockwise order
points.push_back(Point(x1, y1, z1));
points.push_back(Point(x2, y2, z2));
points.push_back(Point(x4, y4, z4));

points.push_back(Point(x1, y1, z1));
points.push_back(Point(x4, y4, z4));
points.push_back(Point(x3, y3, z3));
}
std::vector<Point> points;

for (int i = 0; i < slices; ++i) {
float theta1 = static_cast<float>(i) * static_cast<float>(M_PI) /
static_cast<float>(slices);
float theta2 = static_cast<float>(i + 1) * static_cast<float>(M_PI) /
static_cast<float>(slices);

for (int j = 0; j < stacks; ++j) {
float phi1 = static_cast<float>(j) * 2.0f * static_cast<float>(M_PI) /
static_cast<float>(stacks);
float phi2 = static_cast<float>(j + 1) * 2.0f * static_cast<float>(M_PI) /
static_cast<float>(stacks);

// Vertices
float x1 = radius * std::sin(theta1) * std::cos(phi1);
float y1 = radius * std::sin(theta1) * std::sin(phi1);
float z1 = radius * std::cos(theta1);

float x2 = radius * std::sin(theta1) * std::cos(phi2);
float y2 = radius * std::sin(theta1) * std::sin(phi2);
float z2 = radius * std::cos(theta1);

float x3 = radius * std::sin(theta2) * std::cos(phi1);
float y3 = radius * std::sin(theta2) * std::sin(phi1);
float z3 = radius * std::cos(theta2);

float x4 = radius * std::sin(theta2) * std::cos(phi2);
float y4 = radius * std::sin(theta2) * std::sin(phi2);
float z4 = radius * std::cos(theta2);

// Push vertices in counter-clockwise order
points.push_back(Point(x1, y1, z1));
points.push_back(Point(x2, y2, z2));
points.push_back(Point(x4, y4, z4));

points.push_back(Point(x1, y1, z1));
points.push_back(Point(x4, y4, z4));
points.push_back(Point(x3, y3, z3));
}
}

return points;
return points;
}

bool generateSphere(float radius, int slices, int stacks, const char* filepath) {
std::vector<Point> triangles = sphereTriangles(radius, slices, stacks);
bool generateSphere(float radius, int slices, int stacks,
const char* filepath) {
std::vector<Point> triangles = sphereTriangles(radius, 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;
}
Loading

0 comments on commit 854af3d

Please sign in to comment.