You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.5 KiB

  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. camera.fovy = 45.0f; // Camera field-of-view Y
  25. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  26. SetCameraMode(CAMERA_FREE); // Set a free camera mode
  27. SetCameraPosition(camera.position); // Set internal camera position to match our camera position
  28. SetCameraTarget(camera.target); // Set internal camera target to match our camera target
  29. SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. UpdateCamera(&camera); // Update internal camera and our camera
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. Begin3dMode(camera);
  44. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  45. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  46. DrawGrid(10, 1.0f);
  47. End3dMode();
  48. DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f));
  49. DrawRectangleLines( 10, 10, 320, 133, BLUE);
  50. DrawText("Free camera default controls:", 20, 20, 10, BLACK);
  51. DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
  52. DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
  53. DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
  54. DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
  55. DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
  56. EndDrawing();
  57. //----------------------------------------------------------------------------------
  58. }
  59. // De-Initialization
  60. //--------------------------------------------------------------------------------------
  61. CloseWindow(); // Close window and OpenGL context
  62. //--------------------------------------------------------------------------------------
  63. return 0;
  64. }