Solar System - demo scence

Functions

static void model_cone_vertex (const float r, const float height, const float theta, const float h, unsigned int *pos, float *points)
 
void model_cone_vertices (const float r, const float height, const unsigned int slices, const unsigned int stacks, float points[])
 
static unsigned int model_cone_nVertices (const unsigned int stacks, const unsigned int slices)
 
void model_cone_write (const char *filepath, const float radius, const float height, const unsigned int slices, const unsigned int stacks)
 

Detailed Description

Function Documentation

◆ model_cone_nVertices()

static unsigned int model_cone_nVertices ( const unsigned int  stacks,
const unsigned int  slices 
)
inlinestatic
235 {
236 return slices * stacks * 9;
237}

Referenced by model_cone_write().

◆ model_cone_vertex()

static void model_cone_vertex ( const float  r,
const float  height,
const float  theta,
const float  h,
unsigned int *  pos,
float *  points 
)
inlinestatic

\begin{aligned} x &= r⋅\frac{h}{\textrm{height}} ⋅ \cos(θ)\\[2em] y &= h + \textrm{height}\\[2em] z &= r⋅\frac{h}{\textrm{height}} ⋅ \sin(θ) \end{aligned}


\begin{aligned} r &≥ 0\\ θ &∈ \left\{-π + i⋅s : s = \frac{2π}{\textrm{slices}} ∧ i ∈ \{0,...,\textrm{slices}\} \right\}\\ h &∈ \left\{- \textrm{height} + j⋅t : t = \frac{\textrm{height}}{\textrm{stacks}} ∧ j ∈ \{0,...,\textrm{stacks}\} \right\} \end{aligned}

See the 3d model.

188 {
189 /*
190 x = r ⋅ (h/height) ⋅ cos(θ)
191 y = 2 ⋅ (height + h)
192 z = r ⋅ (h/height) ⋅ sin(θ)
193
194 r ≥ 0
195 θ ∈ {-π + i⋅s : s = 2π/slices ∧ i ∈ {0,...,slices} }
196 h ∈ {-height + j⋅t : t = height/stacks ∧ j ∈ {0,...,stacks} }
197
198 check:
199 1. https://www.math3d.org/7oeSkmuns
200 */
201 points_vertex(r * h / height * cos(theta), height + h, r * h / height * sin(theta), pos, points);
202}
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_cone_vertices().

◆ model_cone_vertices()

void model_cone_vertices ( const float  r,
const float  height,
const unsigned int  slices,
const unsigned int  stacks,
float  points[] 
)
205 {
206
207 const float s = 2.0f * (float) M_PI / (float) slices;
208 const float t = height / (float) stacks;
209 const float theta = -M_PI;
210 const float h = -height;
211
212 unsigned int pos = 0;
213
214 for (unsigned int m = 1; m <= slices; m++) {
215 for (unsigned int n = 1; n <= stacks; n++) {
216 float i = (float) m;
217 float j = (float) n;
218
219 //base
220 points_vertex(0, 0, 0, &pos, points); //O
221 model_cone_vertex(r, height, theta + s * (i - 1), h, &pos, points); //P1
222 model_cone_vertex(r, height, theta + s * i, h, &pos, points); //P2
223
224 model_cone_vertex(r, height, theta + s * i, h + t * (j - 1), &pos, points); // P2
225 model_cone_vertex(r, height, theta + s * (i - 1), h + t * j, &pos, points); // P1'
226 model_cone_vertex(r, height, theta + s * i, h + t * j, &pos, points); //P2'
227
228 model_cone_vertex(r, height, theta + s * i, h + t * (j - 1), &pos, points); // P2
229 model_cone_vertex(r, height, theta + s * (i - 1), h + t * (j - 1), &pos, points); // P1
230 model_cone_vertex(r, height, theta + s * (i - 1), h + t * j, &pos, points); // P1'
231 }
232 }
233}
static void model_cone_vertex(const float r, const float height, const float theta, const float h, unsigned int *pos, float *points)
Definition: generator.cpp:187

References model_cone_vertex(), and points_vertex().

Referenced by model_cone_write().

◆ model_cone_write()

void model_cone_write ( const char *  filepath,
const float  radius,
const float  height,
const unsigned int  slices,
const unsigned int  stacks 
)
240 {
241 const unsigned int nVertices = model_cone_nVertices(stacks, slices);
242 float points[3 * nVertices];
243 model_cone_vertices(radius, height, slices, stacks, points);
244 points_write(filepath, nVertices, points);
245}
static unsigned int model_cone_nVertices(const unsigned int stacks, const unsigned int slices)
Definition: generator.cpp:235
void model_cone_vertices(const float r, const float height, const unsigned int slices, const unsigned int stacks, float points[])
Definition: generator.cpp:204
void points_write(const char *filename, const unsigned int nVertices, const float points[])
Definition: generator.cpp:27

References model_cone_nVertices(), model_cone_vertices(), and points_write().

Referenced by main().