Add sweet_geometry_cube
This commit is contained in:
parent
d13e891219
commit
9ef75edb27
@ -475,6 +475,10 @@ sweet_geometry_subdivide_mesh_v (unsigned int nb_iterations, float scale,
|
||||
}
|
||||
|
||||
/* Icosphere */
|
||||
|
||||
#define NB_INDICES 60
|
||||
#define NB_VERTICES 12
|
||||
|
||||
static float icosphere_vertices_v[36] = {
|
||||
-1, SWEET_GOLDEN_RATIO, 0,
|
||||
1, SWEET_GOLDEN_RATIO, 0,
|
||||
@ -492,7 +496,7 @@ static float icosphere_vertices_v[36] = {
|
||||
-SWEET_GOLDEN_RATIO, 0, 1
|
||||
};
|
||||
|
||||
static unsigned int icosphere_indices_v[60] = {
|
||||
static unsigned int icosphere_indices_v[NB_INDICES] = {
|
||||
0, 11, 5,
|
||||
0, 5, 1,
|
||||
0, 1, 7,
|
||||
@ -518,8 +522,6 @@ static unsigned int icosphere_indices_v[60] = {
|
||||
9, 8, 1
|
||||
};
|
||||
|
||||
static unsigned int nb_indices = 60;
|
||||
static unsigned int nb_vertices_v = 12;
|
||||
|
||||
int
|
||||
sweet_geometry_icosphere (unsigned int nb_iterations, float scale,
|
||||
@ -527,7 +529,69 @@ sweet_geometry_icosphere (unsigned int nb_iterations, float scale,
|
||||
unsigned int * count_vertices, float ** mesh_vertices)
|
||||
{
|
||||
return sweet_geometry_subdivide_mesh_v (nb_iterations, scale,
|
||||
nb_indices, icosphere_indices_v, nb_vertices_v, icosphere_vertices_v,
|
||||
NB_INDICES, icosphere_indices_v, NB_VERTICES, icosphere_vertices_v,
|
||||
count_indices, mesh_indices, count_vertices, mesh_vertices);
|
||||
}
|
||||
#undef NB_INDICES
|
||||
#undef NB_VERTICES
|
||||
|
||||
#define NB_INDICES 36
|
||||
#define NB_VERTICES 8
|
||||
|
||||
static float cube_vertices_v[24] = {
|
||||
-0.5, -0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
-0.5, 0.5, -0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, 0.5, 0.5,
|
||||
-0.5, 0.5, 0.5
|
||||
};
|
||||
|
||||
static unsigned int cube_indices_v[NB_INDICES] = {
|
||||
2, 3, 0,
|
||||
0, 1, 2,
|
||||
4, 7, 6,
|
||||
6, 5, 4,
|
||||
0, 3, 7,
|
||||
7, 4, 0,
|
||||
6, 2, 1,
|
||||
1, 5, 6,
|
||||
0, 4, 1,
|
||||
1, 4, 5,
|
||||
3, 2, 6,
|
||||
6, 7, 3
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
sweet_geometry_cube (float scale,
|
||||
unsigned int * count_indices, unsigned int ** mesh_indices,
|
||||
unsigned int * count_vertices, float ** mesh_vertices)
|
||||
{
|
||||
int i;
|
||||
|
||||
*mesh_vertices = NULL;
|
||||
*mesh_indices = NULL;
|
||||
*count_indices = NB_INDICES;
|
||||
*count_vertices = NB_VERTICES;
|
||||
|
||||
*mesh_vertices = malloc (NB_VERTICES * 3 * sizeof (float));
|
||||
if (*mesh_vertices == NULL) { return 0; }
|
||||
*mesh_indices = malloc (NB_INDICES * sizeof (unsigned int));
|
||||
if (*mesh_indices == NULL) { return 0; }
|
||||
|
||||
for (i = 0; i < NB_VERTICES * 3; i++)
|
||||
{
|
||||
(*mesh_vertices)[i] = cube_vertices_v[i] * scale;
|
||||
}
|
||||
|
||||
for (i = 0; i < NB_INDICES; i++)
|
||||
{
|
||||
(*mesh_indices)[i] = cube_indices_v[i];
|
||||
}
|
||||
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
@ -36,5 +36,10 @@ int sweet_geometry_icosphere (unsigned int nb_iterations, float scale,
|
||||
unsigned int * count_indices, unsigned int ** mesh_indices,
|
||||
unsigned int * count_vertices, float ** mesh_vertices);
|
||||
|
||||
int
|
||||
sweet_geometry_cube (float scale,
|
||||
unsigned int * count_indices, unsigned int ** mesh_indices,
|
||||
unsigned int * count_vertices, float ** mesh_vertices);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user