diff options
| author | Ray <raysan5@gmail.com> | 2017-09-02 17:42:22 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2017-09-02 17:42:22 +0200 |
| commit | fb334e2fd11ade79377a2d95a83000763c047975 (patch) | |
| tree | 660ae9ac9e3e631f8b94684c4ab563917fd22521 /src/models.c | |
| parent | 12cb3afd9eca6ba3322273da1e6dd3a3ae080cf8 (diff) | |
| download | raylib-fb334e2fd11ade79377a2d95a83000763c047975.tar.gz raylib-fb334e2fd11ade79377a2d95a83000763c047975.zip | |
Testing shapes generation using additional library
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/models.c b/src/models.c index 315b51d4..63b18ce9 100644 --- a/src/models.c +++ b/src/models.c @@ -51,6 +51,9 @@ #include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 +#define PAR_SHAPES_IMPLEMENTATION +#include "external/par_shapes.h" + //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- @@ -650,6 +653,7 @@ Mesh GenMeshCube(float width, float height, float length) { Mesh mesh = { 0 }; + /* float vertices[] = { -width/2, -height/2, length/2, width/2, -height/2, length/2, @@ -759,6 +763,39 @@ Mesh GenMeshCube(float width, float height, float length) mesh.vertexCount = 24; mesh.triangleCount = 12; + */ + + // TODO: Just testing par_shapes mesh generation functions + //-------------------------------------------------------- + par_shapes_mesh *cube = par_shapes_create_cube(); // No normals/texcoords generated!!! + par_shapes_scale(cube, width, height, length); + par_shapes_compute_normals(cube); + + mesh.vertices = (float *)malloc(cube->ntriangles*3*3*sizeof(float)); + mesh.texcoords = (float *)malloc(cube->ntriangles*3*2*sizeof(float)); + mesh.normals = (float *)malloc(cube->ntriangles*3*3*sizeof(float)); + + mesh.vertexCount = cube->ntriangles*3; + mesh.triangleCount = cube->ntriangles; + + //for (int i = 0; i < cube->ntriangles*3; i++) printf("%i ", cube->triangles[i]); + //for (int i = 0; i < cube->npoints*3; i += 3) printf("\nv%.1f %.1f %.1f ", cube->points[i], cube->points[i + 1], cube->points[i + 2]); + + for (int k = 0; k < mesh.vertexCount; k++) + { + mesh.vertices[k*3] = cube->points[cube->triangles[k]*3]; + mesh.vertices[k*3 + 1] = cube->points[cube->triangles[k]*3 + 1]; + mesh.vertices[k*3 + 2] = cube->points[cube->triangles[k]*3 + 2]; + + mesh.normals[k*3] = cube->normals[cube->triangles[k]*3]; + mesh.normals[k*3 + 1] = cube->normals[cube->triangles[k]*3 + 1]; + mesh.normals[k*3 + 2] = cube->normals[cube->triangles[k]*3 + 2]; + + mesh.texcoords[k*2] = 0.0f;//cube->tcoords[cube->triangles[k]*2]; + mesh.texcoords[k*2 + 1] = 0.0f;//cube->tcoords[cube->triangles[k]*2 + 1]; + } + + par_shapes_free_mesh(cube); // Upload vertex data to GPU (static mesh) rlLoadMesh(&mesh, false); @@ -766,6 +803,11 @@ Mesh GenMeshCube(float width, float height, float length) return mesh; } +//RLAPI Mesh GenMeshSphere(float radius, int rings, int slices); // Generate sphere mesh (standard sphere) +//RLAPI Mesh GenMeshCylinder(float radiusTop, float radiusBottom, float height, int slices); // Generate cylinder mesh +//RLAPI Mesh GenMeshTorus(float radius1, float radius2, int radSeg, int sides); // Generate torus mesh +//RLAPI Mesh GenMeshTube(float radius1, float radius2, float height, int sides); // Generate tube mesh + // Generate a mesh from heightmap // NOTE: Vertex data is uploaded to GPU Mesh GenMeshHeightmap(Image heightmap, Vector3 size) |
