models_geometric_shapes.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Draw some basic geometric shapes (cube, sphere, cylinder...)
  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. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
  19. // Define the camera to look into our 3d world
  20. Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  22. //--------------------------------------------------------------------------------------
  23. // Main game loop
  24. while (!WindowShouldClose()) // Detect window close button or ESC key
  25. {
  26. // Update
  27. //----------------------------------------------------------------------------------
  28. // TODO: Update your variables here
  29. //----------------------------------------------------------------------------------
  30. // Draw
  31. //----------------------------------------------------------------------------------
  32. BeginDrawing();
  33. ClearBackground(RAYWHITE);
  34. Begin3dMode(camera);
  35. DrawCube((Vector3){-4, 0, 2}, 2, 5, 2, RED);
  36. DrawCubeWires((Vector3){-4, 0, 2}, 2, 5, 2, GOLD);
  37. DrawCubeWires((Vector3){-4, 0, -2}, 3, 6, 2, MAROON);
  38. DrawSphere((Vector3){-1, 0, -2}, 1, GREEN);
  39. DrawSphereWires((Vector3){1, 0, 2}, 2, 16, 16, LIME);
  40. DrawCylinder((Vector3){4, 0, -2}, 1, 2, 3, 4, SKYBLUE);
  41. DrawCylinderWires((Vector3){4, 0, -2}, 1, 2, 3, 4, DARKBLUE);
  42. DrawCylinderWires((Vector3){4.5, -1, 2}, 1, 1, 2, 6, BROWN);
  43. DrawCylinder((Vector3){1, 0, -4}, 0, 1.5, 3, 8, GOLD);
  44. DrawCylinderWires((Vector3){1, 0, -4}, 0, 1.5, 3, 8, PINK);
  45. DrawGrid(10.0, 1.0); // Draw a grid
  46. End3dMode();
  47. DrawFPS(10, 10);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }