27 namespace AstcTextures
36 const unsigned int n_vertex_coordinates = 3;
37 const unsigned int n_texture_coordinates = 2;
38 const unsigned int n_normal_coordinates = 3;
39 const unsigned int n_indices_per_vertex = 6;
41 const float R = 1.0f / (
float)(rings - 1);
42 const float S = 1.0f / (
float)(sectors - 1);
59 for (r = 0; r < rings; r++)
61 for (s = 0; s < sectors; s++)
63 const float x = sinf(
M_PI * r * R) * cosf(2 *
M_PI * s * S);
64 const float y = sinf(-M_PI_2 +
M_PI * r * R);
65 const float z = sinf(2.0
f *
M_PI * s * S) * sinf(
M_PI * r * R);
70 *vertices++ = x * radius;
71 *vertices++ = y * radius;
72 *vertices++ = z * radius;
80 for (r = 0; r < rings; r++)
82 for (s = 0; s < sectors; s++)
85 *indices++ = r * sectors + s;
86 *indices++ = r * sectors + (s + 1);
87 *indices++ = (r + 1) * sectors + s;
90 *indices++ = r * sectors + (s + 1);
91 *indices++ = (r + 1) * sectors + (s + 1);
92 *indices++ = (r + 1) * sectors + s;
100 if (vertex_data_size == NULL)
102 LOGF(
"Memory error: vertex_data_size = NULL");
114 if (normal_data_size == NULL)
116 LOGF(
"Memory error: normal_data_size = NULL");
128 if (texcoords_size == NULL)
130 LOGF(
"Memory error: texcoords_size = NULL");
142 if (n_indices == NULL)
144 LOGF(
"Memory error: n_indices = NULL");
#define MALLOC_CHECK(ptr_type, ptr, size)
unsigned short * getSphereIndices(int *n_indices)
Returns sphere indices.
int sphere_normal_data_size
float * getSphereNormalData(int *normal_data_size)
Returns normal coordinates.
float * getSphereTexcoords(int *texcoords_size)
Returns texture coordinates.
GLsizei GLenum const void * indices
int sphere_texcoords_size
int sphere_vertex_data_size
SolidSphere(const float radius, const unsigned int rings, const unsigned int sectors)
Solid sphere constructor. It generates vertex position, normals and texture coordinates data based on...
float * getSphereVertexData(int *vertex_data_size)
Returns sphere vertices.
#define M_PI
The value of pi.
GLint GLint GLint GLint GLint x
unsigned short * sphere_indices