diff options
Diffstat (limited to 'examples/web/models/models_mesh_generation.c')
| -rw-r--r-- | examples/web/models/models_mesh_generation.c | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/examples/web/models/models_mesh_generation.c b/examples/web/models/models_mesh_generation.c index 32060ca..053672c 100644 --- a/examples/web/models/models_mesh_generation.c +++ b/examples/web/models/models_mesh_generation.c @@ -15,15 +15,15 @@ #include <emscripten/emscripten.h> #endif -#define NUM_MODELS 7 // We generate 7 parametric 3d shapes +#define NUM_MODELS 8 // Parametric 3d shapes to generate //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -int screenWidth = 800; -int screenHeight = 450; +const int screenWidth = 800; +const int screenHeight = 450; -Model models[NUM_MODELS]; +Model models[NUM_MODELS] = { 0 }; // Define the camera to look into our 3d world Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; @@ -39,7 +39,7 @@ int currentModel = 0; void UpdateDrawFrame(void); // Update and Draw one frame //---------------------------------------------------------------------------------- -// Main Enry Point +// Program Main Entry Point //---------------------------------------------------------------------------------- int main(void) { @@ -51,7 +51,7 @@ int main(void) Image checked = GenImageChecked(2, 2, 1, 1, RED, GREEN); Texture2D texture = LoadTextureFromImage(checked); UnloadImage(checked); - + models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5)); models[1] = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f)); models[2] = LoadModelFromMesh(GenMeshSphere(2, 32, 32)); @@ -59,10 +59,11 @@ int main(void) models[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16)); models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32)); models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128)); - + models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f)); + // Set checked texture as default diffuse component for all models material - for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[MAP_DIFFUSE].texture = texture; - + for (int i = 0; i < NUM_MODELS; i++) models[i].materials[0].maps[MAP_DIFFUSE].texture = texture; + SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode #if defined(PLATFORM_WEB) @@ -70,7 +71,7 @@ int main(void) #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -79,10 +80,10 @@ int main(void) #endif // De-Initialization - //-------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------- // Unload models data (GPU VRAM) for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- @@ -97,11 +98,22 @@ void UpdateDrawFrame(void) // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera - + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures } + + if (IsKeyPressed(KEY_RIGHT)) + { + currentModel++; + if (currentModel >= NUM_MODELS) currentModel = 0; + } + else if (IsKeyPressed(KEY_LEFT)) + { + currentModel--; + if (currentModel < 0) currentModel = NUM_MODELS - 1; + } //---------------------------------------------------------------------------------- // Draw @@ -110,18 +122,18 @@ void UpdateDrawFrame(void) ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawModel(models[currentModel], position, 1.0f, WHITE); DrawGrid(10, 1.0); - End3dMode(); - + EndMode3D(); + DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f)); DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f)); DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE); - + switch(currentModel) { case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break; @@ -131,6 +143,7 @@ void UpdateDrawFrame(void) case 4: DrawText("CYLINDER", 680, 10, 20, DARKBLUE); break; case 5: DrawText("TORUS", 680, 10, 20, DARKBLUE); break; case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break; + case 7: DrawText("POLY", 680, 10, 20, DARKBLUE); break; default: break; } |
