core_vr_simulator.c 3.1 KB

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