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.

72 lines
2.7 KiB

  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [core] example - Oculus Rift CV1
  4. --
  5. -- NOTE: Example requires linkage with LibOVR
  6. --
  7. -- This example has been created using raylib 1.6 (www.raylib.com)
  8. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. --
  10. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  11. --
  12. -------------------------------------------------------------------------------------------
  13. -- Initialization
  14. -------------------------------------------------------------------------------------------
  15. local screenWidth = 1080
  16. local screenHeight = 600
  17. -- NOTE: screenWidth/screenHeight should match VR device aspect ratio
  18. InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift")
  19. -- NOTE: If device is not available, it fallbacks to default device (simulator)
  20. InitVrDevice(VrDevice.OCULUS_RIFT_CV1) -- Init VR device (Oculus Rift CV1)
  21. -- Define the camera to look into our 3d world
  22. local camera = {}
  23. camera.position = Vector3(5.0, 5.0, 5.0) -- Camera position
  24. camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
  25. camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
  26. camera.fovy = 60.0 -- Camera field-of-view Y
  27. local cubePosition = Vector3(0.0, 0.0, 0.0)
  28. SetTargetFPS(90) -- Set our game to run at 90 frames-per-second
  29. ----------------------------------------------------------------------------------------
  30. -- Main game loop
  31. while not WindowShouldClose() do -- Detect window close button or ESC key
  32. -- Update
  33. ------------------------------------------------------------------------------------
  34. UpdateVrTracking()
  35. if (IsKeyPressed(KEY.SPACE)) then ToggleVrMode() end
  36. ------------------------------------------------------------------------------------
  37. -- Draw
  38. ------------------------------------------------------------------------------------
  39. BeginDrawing()
  40. ClearBackground(RAYWHITE)
  41. Begin3dMode(camera)
  42. DrawCube(cubePosition, 2.0, 2.0, 2.0, RED)
  43. DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON)
  44. DrawGrid(10, 1.0)
  45. End3dMode()
  46. DrawFPS(10, 10)
  47. EndDrawing()
  48. ------------------------------------------------------------------------------------
  49. end
  50. -- De-Initialization
  51. ----------------------------------------------------------------------------------------
  52. CloseVrDevice() -- Close VR device
  53. CloseWindow() -- Close window and OpenGL context
  54. ----------------------------------------------------------------------------------------