core_vr_simulator.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. InitVrSimulator(HMD_OCULUS_RIFT_CV1); // Init VR simulator (Oculus Rift CV1 parameters)
  21. // Define the camera to look into our 3d world
  22. Camera camera;
  23. camera.position = (Vector3){ 5.0f, 2.0f, 5.0f }; // Camera position
  24. camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
  25. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  26. camera.fovy = 60.0f; // Camera field-of-view Y
  27. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  28. SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode
  29. SetTargetFPS(90); // Set our game to run at 90 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. UpdateCamera(&camera); // Update camera (simulator mode)
  37. if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. BeginVrDrawing();
  44. Begin3dMode(camera);
  45. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  46. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  47. DrawGrid(40, 1.0f);
  48. End3dMode();
  49. EndVrDrawing();
  50. DrawFPS(10, 10);
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. CloseVrSimulator(); // Close VR simulator
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }