models_geometric_shapes.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Draw some basic geometric shapes (cube, sphere, cylinder...) (adapted for HTML5 platform)
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. // Define the camera to look into our 3d world
  21. Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
  22. //----------------------------------------------------------------------------------
  23. // Module Functions Declaration
  24. //----------------------------------------------------------------------------------
  25. void UpdateDrawFrame(void); // Update and Draw one frame
  26. //----------------------------------------------------------------------------------
  27. // Main Enry Point
  28. //----------------------------------------------------------------------------------
  29. int main()
  30. {
  31. // Initialization
  32. //--------------------------------------------------------------------------------------
  33. InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
  34. #if defined(PLATFORM_WEB)
  35. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  36. #else
  37. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  38. //--------------------------------------------------------------------------------------
  39. // Main game loop
  40. while (!WindowShouldClose()) // Detect window close button or ESC key
  41. {
  42. UpdateDrawFrame();
  43. }
  44. #endif
  45. // De-Initialization
  46. //--------------------------------------------------------------------------------------
  47. CloseWindow(); // Close window and OpenGL context
  48. //--------------------------------------------------------------------------------------
  49. return 0;
  50. }
  51. //----------------------------------------------------------------------------------
  52. // Module Functions Definition
  53. //----------------------------------------------------------------------------------
  54. void UpdateDrawFrame(void)
  55. {
  56. // Update
  57. //----------------------------------------------------------------------------------
  58. // TODO: Update your variables here
  59. //----------------------------------------------------------------------------------
  60. // Draw
  61. //----------------------------------------------------------------------------------
  62. BeginDrawing();
  63. ClearBackground(RAYWHITE);
  64. Begin3dMode(camera);
  65. DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
  66. DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
  67. DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
  68. DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
  69. DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
  70. DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
  71. DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
  72. DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
  73. DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
  74. DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
  75. DrawGrid(10, 1.0f); // Draw a grid
  76. End3dMode();
  77. DrawFPS(10, 10);
  78. EndDrawing();
  79. //----------------------------------------------------------------------------------
  80. }