This page has been translated automatically.
Unigine Basics
1. Introduction
2. Managing Virtual Worlds
3. Preparing 3D Models
4. Materials
5. Cameras and Lighting
6. Implementing Application Logic
7. Making Cutscenes and Recording Videos
8. Preparing Your Project for Release
9. Physics
10. Optimization Basics
11. PROJECT2: First-Person Shooter
12. PROJECT3: Third-Person Cross-Country Arcade Racing Game

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:

ObjMovableThis component type can be used for all objects, that can be grabbed, held and thrown (it can be a ball, a pistol, whatever you can take, carry and drop).
ObjHandleThis component type can be used for all objects, that can be turned or moved while being held (various handles, levers, valves, etc.).
ObjSwitchThis component type can be used for all objects, that can be switched by grabbing (all sorts of buttons and on-off switches, including rotary ones).
ObjLaserPointerThis component enables casting a laser ray by the object.
Notice
The laser pointer object in the VR Sample world has ObjMovable and ObjLaserPointer components attached.

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:

VRPlayerPCThis component implements a player with standard PC input devices (keyboard + mouse or Xbox360 controller) for VR emulation and contains all related settings and methods.
VRPlayerVR This is a base class implementing common functionality for supported VR devices and contains their common parameters.

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:

Notice
These components can be attached to GUI objects only.
HandSampleMenuGui This component implements initialization of widgets for the menu that is attached to a controller.
WorldMenuSampleGui This component implements initialization of widgets for the world menu.

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).

Notice
Obstacles are not available for VRPlayerPC.

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.

Notice
Primitives used to mark obstacles must have their first surface (the one with the 0 index) named as "box", "sphere", "capsule" or "cylinder" in order to be properly converted into corresponding trigger volumes.

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.

Last update: 2024-12-13
Build: ()