models_billboard.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [models] example - Drawing billboards
  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 [models] example - drawing billboards")
  16. -- Define the camera to look into our 3d world
  17. local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
  18. local bill = LoadTexture("resources/billboard.png") -- Our texture billboard
  19. local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard
  20. SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
  21. SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
  22. -------------------------------------------------------------------------------------------
  23. -- Main game loop
  24. while not WindowShouldClose() do -- Detect window close button or ESC key
  25. -- Update
  26. ---------------------------------------------------------------------------------------
  27. camera = UpdateCamera(camera) -- Update camera
  28. ---------------------------------------------------------------------------------------
  29. -- Draw
  30. ---------------------------------------------------------------------------------------
  31. BeginDrawing()
  32. ClearBackground(RAYWHITE)
  33. Begin3dMode(camera)
  34. DrawBillboard(camera, bill, billPosition, 2.0, WHITE)
  35. DrawGrid(10, 1.0) -- Draw a grid
  36. End3dMode()
  37. DrawFPS(10, 10)
  38. EndDrawing()
  39. ---------------------------------------------------------------------------------------
  40. end
  41. -- De-Initialization
  42. -------------------------------------------------------------------------------------------
  43. UnloadTexture(bill) -- Unload texture
  44. CloseWindow() -- Close window and OpenGL context
  45. -------------------------------------------------------------------------------------------