core_3d_camera_free.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(10.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(camera, CameraMode.FREE) -- Set a free camera mode
  24. SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
  25. -------------------------------------------------------------------------------------------
  26. -- Main game loop
  27. while not WindowShouldClose() do -- Detect window close button or ESC key
  28. -- Update
  29. ---------------------------------------------------------------------------------------
  30. camera = UpdateCamera(camera) -- Update camera
  31. ---------------------------------------------------------------------------------------
  32. -- Draw
  33. ---------------------------------------------------------------------------------------
  34. BeginDrawing()
  35. ClearBackground(RAYWHITE)
  36. Begin3dMode(camera)
  37. DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
  38. DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
  39. DrawGrid(10, 1.0)
  40. End3dMode()
  41. DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5))
  42. DrawRectangleLines( 10, 10, 320, 133, BLUE)
  43. DrawText("Free camera default controls:", 20, 20, 10, BLACK)
  44. DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY)
  45. DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY)
  46. DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY)
  47. DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY)
  48. DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY)
  49. EndDrawing()
  50. ---------------------------------------------------------------------------------------
  51. end
  52. -- De-Initialization
  53. -------------------------------------------------------------------------------------------
  54. CloseWindow() -- Close window and OpenGL context
  55. -------------------------------------------------------------------------------------------