core_3d_camera_mode.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Initialize 3d camera mode
  4. *
  5. * Example complexity rating: [★☆☆☆] 1/4
  6. *
  7. * Example originally created with raylib 1.0, last time updated with raylib 1.0
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera mode");
  26. // Define the camera to look into our 3d world
  27. Camera3D camera = { 0 };
  28. camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
  29. camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
  30. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  31. camera.fovy = 45.0f; // Camera field-of-view Y
  32. camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
  33. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  34. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  35. //--------------------------------------------------------------------------------------
  36. // Main game loop
  37. while (!WindowShouldClose()) // Detect window close button or ESC key
  38. {
  39. // Update
  40. //----------------------------------------------------------------------------------
  41. // TODO: Update your variables here
  42. //----------------------------------------------------------------------------------
  43. // Draw
  44. //----------------------------------------------------------------------------------
  45. BeginDrawing();
  46. ClearBackground(RAYWHITE);
  47. BeginMode3D(camera);
  48. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  49. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  50. DrawGrid(10, 1.0f);
  51. EndMode3D();
  52. DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
  53. DrawFPS(10, 10);
  54. EndDrawing();
  55. //----------------------------------------------------------------------------------
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. CloseWindow(); // Close window and OpenGL context
  60. //--------------------------------------------------------------------------------------
  61. return 0;
  62. }