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.

74 lines
3.2 KiB

  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [core] example - Initialize 3d camera free
  4. --
  5. -- This example has been created using raylib 1.6 (www.raylib.com)
  6. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. --
  8. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  9. --
  10. --------------------------------------------------------------------------------------------
  11. -- Initialization
  12. ----------------------------------------------------------------------------------------
  13. local screenWidth = 800
  14. local screenHeight = 450
  15. InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
  16. -- Define the camera to look into our 3d world
  17. local camera = {}
  18. camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position
  19. camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
  20. camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
  21. camera.fovy = 45.0 -- Camera field-of-view Y
  22. local cubePosition = Vector3(0.0, 0.0, 0.0)
  23. SetCameraMode(CameraMode.FREE) -- Set a free camera mode
  24. SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
  25. SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
  26. SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
  27. SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
  28. -------------------------------------------------------------------------------------------
  29. -- Main game loop
  30. while not WindowShouldClose() do -- Detect window close button or ESC key
  31. -- Update
  32. ---------------------------------------------------------------------------------------
  33. camera = UpdateCamera(camera) -- Update internal camera and our camera
  34. ---------------------------------------------------------------------------------------
  35. -- Draw
  36. ---------------------------------------------------------------------------------------
  37. BeginDrawing()
  38. ClearBackground(RAYWHITE)
  39. Begin3dMode(camera)
  40. DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
  41. DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
  42. DrawGrid(10, 1.0)
  43. End3dMode()
  44. DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5))
  45. DrawRectangleLines( 10, 10, 320, 133, BLUE)
  46. DrawText("Free camera default controls:", 20, 20, 10, BLACK)
  47. DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY)
  48. DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY)
  49. DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY)
  50. DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY)
  51. DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY)
  52. EndDrawing()
  53. ---------------------------------------------------------------------------------------
  54. end
  55. -- De-Initialization
  56. -------------------------------------------------------------------------------------------
  57. CloseWindow() -- Close window and OpenGL context
  58. -------------------------------------------------------------------------------------------