Solar System - demo scence
Sphere

Functions

static void model_sphere_vertex (const float r, const float theta, const float phi, unsigned int *pos, float *points)
 
static void model_sphere_vertices (const float r, const unsigned int slices, const unsigned int stacks, float points[])
 
static unsigned int model_sphere_nVertices (const unsigned int slices, const unsigned int stacks)
 
void model_sphere_write (const char *filepath, float radius, unsigned int slices, unsigned int stacks)
 

Detailed Description

Function Documentation

◆ model_sphere_nVertices()

static unsigned int model_sphere_nVertices ( const unsigned int  slices,
const unsigned int  stacks 
)
inlinestatic
297 {
298 return slices * stacks * 6;
299}

Referenced by model_sphere_write().

◆ model_sphere_vertex()

static void model_sphere_vertex ( const float  r,
const float  theta,
const float  phi,
unsigned int *  pos,
float *  points 
)
inlinestatic
253 {
254 /*
255 x = r ⋅ sin(θ)cos(φ)
256 y = r ⋅ sin(φ)
257 z = r ⋅ cos(θ)cos(φ)
258
259 r ≥ 0
260 θ ∈ {-π + i⋅s : s = 2π/slices ∧ i ∈ {0,...,slices} }
261 ϕ ∈ {-π/2 + j⋅t : t = π/stacks ∧ j ∈ {0,...,stacks} }
262
263 check
264 1. https://www.math3d.org/EumEEZBKe
265 2. https://www.math3d.org/zE4n6xayX
266 */
267 points_vertex(r * sin(theta) * cos(phi), r * sin(phi), r * cos(theta) * cos(phi), pos, points);
268}
void points_vertex(const float x, const float y, const float z, unsigned int *pos, float points[])
Definition: generator.cpp:20

References points_vertex().

Referenced by model_sphere_vertices().

◆ model_sphere_vertices()

static void model_sphere_vertices ( const float  r,
const unsigned int  slices,
const unsigned int  stacks,
float  points[] 
)
static
270 {
271 // https://www.math3d.org/EumEEZBKe
272 // https://www.math3d.org/zE4n6xayX
273
274 const float s = 2.0f * (float) M_PI / (float) slices;
275 const float t = M_PI / (float) stacks;
276 const float theta = -M_PI;
277 const float phi = -M_PI / 2.0f;
278
279 unsigned int pos = 0;
280
281 for (unsigned int m = 1; m <= slices; m++) {
282 for (unsigned int n = 1; n <= stacks; n++) {
283 float i = (float) m;
284 float j = (float) n;
285
286 model_sphere_vertex(r, theta + s * (i - 1), phi + t * j, &pos, points); // P1'
287 model_sphere_vertex(r, theta + s * i, phi + t * (j - 1), &pos, points); // P2
288 model_sphere_vertex(r, theta + s * i, phi + t * j, &pos, points); //P2'
289
290 model_sphere_vertex(r, theta + s * (i - 1), phi + t * (j - 1), &pos, points); // P1
291 model_sphere_vertex(r, theta + s * i, phi + t * (j - 1), &pos, points); // P2
292 model_sphere_vertex(r, theta + s * (i - 1), phi + t * j, &pos, points); // P1'
293 }
294 }
295}
static void model_sphere_vertex(const float r, const float theta, const float phi, unsigned int *pos, float *points)
Definition: generator.cpp:253

References model_sphere_vertex().

Referenced by model_sphere_write().

◆ model_sphere_write()

void model_sphere_write ( const char *  filepath,
float  radius,
unsigned int  slices,
unsigned int  stacks 
)
301 {
302 const unsigned int nVertices = model_sphere_nVertices(slices, stacks);
303 float points[3 * nVertices];
304 model_sphere_vertices(radius, slices, stacks, points);
305 points_write(filepath, nVertices, points);
306}
void points_write(const char *filename, const unsigned int nVertices, const float points[])
Definition: generator.cpp:27
static unsigned int model_sphere_nVertices(const unsigned int slices, const unsigned int stacks)
Definition: generator.cpp:297
static void model_sphere_vertices(const float r, const unsigned int slices, const unsigned int stacks, float points[])
Definition: generator.cpp:270

References model_sphere_nVertices(), model_sphere_vertices(), and points_write().

Referenced by main().