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.

85 lines
3.4 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Oculus Rift CV1
  4. *
  5. * Compile example using:
  6. * gcc -o $(NAME_PART).exe $(FILE_NAME) -L. -L..\src\external\OculusSDK\LibOVR -lLibOVRRT32_1 -lraylib -lglfw3 -lopengl32 -lgdi32 -std=c99
  7. *
  8. * This example has been created using raylib 1.5 (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2016 Ramon Santamaria (@raysan5)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. int main()
  16. {
  17. // Initialization
  18. //--------------------------------------------------------------------------------------
  19. int screenWidth = 1080;
  20. int screenHeight = 600;
  21. // NOTE: screenWidth/screenHeight should match VR device aspect ratio
  22. InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift");
  23. // NOTE: If device is not available, it fallbacks to default device (simulator)
  24. InitVrDevice(HMD_OCULUS_RIFT_CV1); // Init VR device (Oculus Rift CV1)
  25. // Define the camera to look into our 3d world
  26. Camera camera;
  27. camera.position = (Vector3){ 5.0f, 2.0f, 5.0f }; // Camera position
  28. camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
  29. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  30. camera.fovy = 60.0f; // Camera field-of-view Y
  31. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  32. SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode
  33. SetTargetFPS(90); // Set our game to run at 90 frames-per-second
  34. //--------------------------------------------------------------------------------------
  35. // Main game loop
  36. while (!WindowShouldClose()) // Detect window close button or ESC key
  37. {
  38. // Update
  39. //----------------------------------------------------------------------------------
  40. if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode)
  41. else if (IsVrDeviceReady()) UpdateVrTracking(&camera); // Update camera with device tracking data
  42. if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
  43. //----------------------------------------------------------------------------------
  44. // Draw
  45. //----------------------------------------------------------------------------------
  46. BeginDrawing();
  47. ClearBackground(RAYWHITE);
  48. Begin3dMode(camera);
  49. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  50. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  51. DrawGrid(40, 1.0f);
  52. End3dMode();
  53. DrawFPS(10, 10);
  54. EndDrawing();
  55. //----------------------------------------------------------------------------------
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. CloseVrDevice(); // Close VR device
  60. CloseWindow(); // Close window and OpenGL context
  61. //--------------------------------------------------------------------------------------
  62. return 0;
  63. }