core_3d_camera_free.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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;
  21. camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
  22. camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
  23. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  24. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  25. SetCameraMode(CAMERA_FREE); // Set a free camera mode
  26. SetCameraPosition(camera.position); // Set internal camera position to match our camera position
  27. SetCameraTarget(camera.target); // Set internal camera target to match our camera target
  28. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  29. //--------------------------------------------------------------------------------------
  30. // Main game loop
  31. while (!WindowShouldClose()) // Detect window close button or ESC key
  32. {
  33. // Update
  34. //----------------------------------------------------------------------------------
  35. UpdateCamera(&camera); // Update internal camera and our camera
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. Begin3dMode(camera);
  42. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  43. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  44. DrawGrid(10, 1.0f);
  45. End3dMode();
  46. DrawText("Free camera default controls:", 20, 20, 10, GRAY);
  47. DrawText("- Mouse Wheel to Zoom in-out", 40, 50, 10, DARKGRAY);
  48. DrawText("- Mouse Wheel Pressed to Pan", 40, 70, 10, DARKGRAY);
  49. DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 90, 10, DARKGRAY);
  50. DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 110, 10, DARKGRAY);
  51. DrawText("- Z to zoom to (0, 0, 0)", 40, 130, 10, DARKGRAY);
  52. EndDrawing();
  53. //----------------------------------------------------------------------------------
  54. }
  55. // De-Initialization
  56. //--------------------------------------------------------------------------------------
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }