Creating an Application Using the Template
Getting Started#
UNIGINE has a ready-to-use template for making VR projects in C++. It supports Oculus Rift and HTC Vive / Vive Pro (OpenXR) out of the box. It also provides a sample project (VR Sample). Here, you will find a set of 3D models of all popular VR controllers and the implementation of basic mechanics such as grabbing and throwing objects, pressing buttons, opening/closing drawers, and a lot more.
The world in this sample project has its settings optimized for best performance in VR.
Both the template and the sample project are created using the Component System — components attached to objects determine their functionality.
You can extend an object's functionality simply by assigning it more components. For example, the laser pointer object in the VR Sample has the following components attached:
- ObjMovable — enables grabbing and throwing an object
- ObjLaserPointer — enables casting a ray of light by the object
You can also implement custom components to extend functionality.
The main features of the VR Sample:
- VR support (OpenXR-compatible devices including Oculus Rift, HTC Vive, and others)
- A set of physical objects that can be manipulated via controllers (physical objects, buttons, drawers)
- An interactive laser pointer object
- Teleportation around the scene
- GUI
- Interaction with GUI objects via controllers
Open SDK Browser, go to the Samples tab, and select Demos.
Find the VR Sample in the Available section and click Install. After installation, the demo will appear in the Installed section, and you can click Copy as Project to create a project based on this sample.
In the Create New Project window that opens, enter the name for your new VR project in the corresponding field and click Create New Project.
To open our new VR project in an IDE, select it on the Projects tab of the UNIGINE SDK Browser and click Open Code IDE.
Structure Overview#
As the IDE opens, you can see, that the project contains a lot of different classes. The brief overview below will give you a hint on what are they all about.
VRInteractable Class#
This is a base class for all objects that you can interact with. It defines a basic set of interactions, in other words: here you define what can a user do with your object. You can add your own type of interaction here.
The following component classes are inherited from the VRInteractable:
VRPlayer Class#
This is a base class for all players. It contains declaration of baseline controls, common basic player operations, event management etc.
The following component classes are inherited from the VRPlayer:
VRPlayerSpawner Class#
This class registers all VRPlayer components in the Component System. It checks that VR is initialized and spawns the VRPlayerVR. In case if VR was not initialized, a VRPlayerPC is spawned.
MenuBaseGUI Class#
This is a base class for all graphic user interfaces (GUI).
The following component classes are inherited from the MenuBaseGUI:
Framework#
Framework includes the Component System which implements the core functionality of components and a set of utility classes and functions used for playing sounds, auxiliary math functions, event system implementation.
Triggers Class#
Triggers is a framework class used to mark room obstacles for the VR Player (e.g. room walls, objects, etc.) and give a warning if there is an obstacle on the way (as the player gets closer to an obstacle, controllers' vibration becomes more intense).
You can simply create primitives for walls and objects in your room and add them as children to the node dummy named Obstacles, which is a child of the VR dummy node (see the hierarchy in the Editor below).
All children of the Obstacles node will be automatically switched to invisible mode and will be used only to inform the player and prevent collisions with objects in the real room.
Setting Up a Device and Running#
Suppose you have successfully installed your Head-Mounted Display (HMD) of choice (please visit Oculus Rift Setup or HTC Vive Setup if you did not). If you are having difficulties getting your HTC Vive to work, this Troubleshooting guide might be helpful.
Major VR devices (OpenXR-compatible) are supported out of the box.
So, we're ready to see the template in action, let's build our application for the first time.
Don't forget to set the appropriate platform and configuration settings for the project before compiling your code in Visual Studio.
Build your application in Visual Studio (Build -> Build Solution) or otherwise, and launch it by selecting the project on the Projects tab of the UNIGINE SDK Browser and clicking Run.
Before running your application via the UNIGINE SDK Browser make sure, that appropriate Customize Run Options (Debug version in our case) are selected, by clicking an ellipsis under the Run button.
As the application starts, learn about basic mechanics, grab and throw objects, try to teleport and interact with objects in the scene.