core_vr_simulator.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. camera.type = CAMERA_PERSPECTIVE; // Camera type
  29. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  30. SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode
  31. SetTargetFPS(90); // Set our game to run at 90 frames-per-second
  32. //--------------------------------------------------------------------------------------
  33. // Main game loop
  34. while (!WindowShouldClose()) // Detect window close button or ESC key
  35. {
  36. // Update
  37. //----------------------------------------------------------------------------------
  38. UpdateCamera(&camera); // Update camera (simulator mode)
  39. if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
  40. //----------------------------------------------------------------------------------
  41. // Draw
  42. //----------------------------------------------------------------------------------
  43. BeginDrawing();
  44. ClearBackground(RAYWHITE);
  45. BeginVrDrawing();
  46. BeginMode3D(camera);
  47. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  48. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  49. DrawGrid(40, 1.0f);
  50. EndMode3D();
  51. EndVrDrawing();
  52. DrawFPS(10, 10);
  53. EndDrawing();
  54. //----------------------------------------------------------------------------------
  55. }
  56. // De-Initialization
  57. //--------------------------------------------------------------------------------------
  58. CloseVrSimulator(); // Close VR simulator
  59. CloseWindow(); // Close window and OpenGL context
  60. //--------------------------------------------------------------------------------------
  61. return 0;
  62. }