core_3d_camera_free.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Initialize 3d camera free
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2015 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 [core] example - 3d camera free");
  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. Vector3 cubePosition = { 0.0, 0.0, 0.0 };
  22. SetCameraMode(CAMERA_FREE); // Set a free camera mode
  23. SetCameraPosition(camera.position); // Set internal camera position to match our camera position
  24. SetCameraTarget(camera.target); // Set internal camera target to match our camera target
  25. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  26. //--------------------------------------------------------------------------------------
  27. // Main game loop
  28. while (!WindowShouldClose()) // Detect window close button or ESC key
  29. {
  30. // Update
  31. //----------------------------------------------------------------------------------
  32. UpdateCamera(&camera); // Update internal camera and our camera
  33. //----------------------------------------------------------------------------------
  34. // Draw
  35. //----------------------------------------------------------------------------------
  36. BeginDrawing();
  37. ClearBackground(WHITE);
  38. Begin3dMode(camera);
  39. DrawCube(cubePosition, 2, 2, 2, RED);
  40. DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
  41. DrawGrid(10.0, 1.0);
  42. End3dMode();
  43. DrawText("Free camera default controls:", 20, 20, 10, GRAY);
  44. DrawText("- Mouse Wheel to Zoom in-out", 40, 50, 10, DARKGRAY);
  45. DrawText("- Mouse Wheel Pressed to Pan", 40, 70, 10, DARKGRAY);
  46. DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 90, 10, DARKGRAY);
  47. DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 110, 10, DARKGRAY);
  48. DrawText("- Z to zoom to (0, 0, 0)", 40, 130, 10, DARKGRAY);
  49. EndDrawing();
  50. //----------------------------------------------------------------------------------
  51. }
  52. // De-Initialization
  53. //--------------------------------------------------------------------------------------
  54. CloseWindow(); // Close window and OpenGL context
  55. //--------------------------------------------------------------------------------------
  56. return 0;
  57. }