FreeVR Library Programming Tutorial (w/ OpenGL)
The FreeVR Library will be used to exemplify many VR interface and
programming techniques.
FreeVR will work in most local VR facilities (eg. CAVE™ or Head-Based-Display),
as well as on the available desktop machines in a simulated-VR mode.
It can be used on PC's with Linux and OpenGL installed, or
in a (currently very) limited way on PC's with Cygwin installed.
The FreeVR webpage is www.freevr.org.
This tutorial takes the approach of starting with an extremely simple initial
example and then advancing in very small increments (baby steps) until we can
perform some interesting tasks in virtual reality.
Another point to make about this tutorial is that it is not intended as a
means to learn advanced OpenGL programing.
The computer graphics in these examples are all very simple.
The goal of the tutorial is to highlight programming tasks that are unique
to programming for a virtual reality system.
On the other hand, some basic OpenGL techniques can be learned by following
this tutorial, as it will show how to handle texture maps, billboards,
cutting planes, and moveable lights.
Other tutorials are under development for interfacing FreeVR to additional
rendering and world simulation systems.
Presently there is a tutorial available for the SGI Performer scene-graph
library, but as Performer has greatly decreased in usage new tutorials
will cover similar, but more popular libraries.
This tutorial has been most recently tested with FreeVR version 0.6a.
Part 3: Examples 12 - 14
Now that we know the basics about creating simple VR experiences, and
have done a couple of interesting things, such as grabbing and moving
objects, we will continue the tutorial of OpenGL FreeVR programs by
introducing how to let participants travel through the virtual world,
give objects (simple) behaviors, and add user interface objects
to the world.
Each example links to a copy of the source code
(and the difference from the previous example)
.
The examples can be compiled with one or more of the following additional
files:
Example 12: Traveling through the world (ex12)
Another common way to "interact" with a virtual world is to move through it.

- The FreeVR Library provides a collection of utilities to accomplish this:
- vrGetValuatorValue — user inputs from the "joystick"
on the wand.
- vrVectorGetRWFrom6sensorDir() — a direction from
one of the tracked objects.
- vrPointGetVWFromUser6sensor() — get a sensor's
position in the virtual worlds coordinates with
respect to a particular user.
- vrUserTravelTranslate3d(),
vrUserTravelRotateId(),
vrUserTravelReset() — functions to specify the
relationship between the real and virtual worlds.
- vrRenderTransformUserTravel() — a matrix that moves
from the real world position to a virtual world position.
- Notice that some objects (perhaps the user interface) can be
left in real-world coordinates, and other objects can be in
the coordinates of one of the tracked sensors (such as the
wand avatar).
- Note that we again must be concerned with how much time has
passed between simulation frames.
Otherwise, speed of travel will be relative to
the speed of the computation hardware.
- Another note: interaction with objects in the virtual world
now requires that we perform calculations with
respect to the virtual world coordinate system.
- Example 12 (ex12_travel.c)
lets the user fly through the virtual world.
- There are minor
differences between ex11 and ex12.
- There are many ways to fly:
- There is also a C++ version of example 12 (ex12_travel.cpp)
that demonstrates the small number of changes needed to compile FreeVR with a C++
application.
Example 13: Agent-style interaction with the world (ex13)
- There are many possible interface techniques.
- Some techniques can be seen in the CAVE demos (CRUMBS, Boiler, Crayoland).
- Many of the currently common methods are still very
reminiscent of the desktop metaphor interfaces.
- Text is also a possible interface. One that allows other
possible interfaces to specify functions to the world simulation.
- Pressing keys on the keyboard is the simplest example of this.
- The ubiquitous 'ESC' key is one example
- Some applications also read keyboard presses to change modes, etc.
(although to be useful this generally requires someone sitting by
the keyboard).
- Text commands can also be sent via a socket connection.
- Example 13 (ex13_socket.c) is
an example of this.
- There are some significant
differences between ex12 and ex13.
- The socket connection can take any message, and use a simple parser,
or something more complex.
- By setting up a listen-socket, the application is behaving
as the server half of a client/server relationship.
- The client can take many forms:
- keystrokes in a telnet session
- simple send-a-message unix program
- scripting language (eg. perl)
- and (building on the first method) voice
- A simple socket API is provided by the FreeVR library.
Example 14: User Interface: Virtual Controls (ex14a-14f)
The following six examples show how different forms of virtual controls
can be implemented and used to control actions within the virtual world.
These examples are implemented in a very rudimentary fashion, with
limits on how they can be positioned in the virtual world.
These examples now require some additional shapes not included in the
simpler version of the shape source code.
The new shapes code is in
(wrs_shapes.c).
Example 14a: Virtual Controls: Toggle Button (ex14a)
- Introducing the first virtual control: a toggle button.
- Interaction with the different types of objects (artifacts
in the world vs. user interface objects) must each be done
in the proper coordinate systems.
- When the virtual button is pressed, its state toggles between
on and off.
- Virtual controls affect the interaction with the world, just
like other type of controls.
Here, travel control is only enabled when the button is "on".
- Example 14a (ex14a_button.c)
lets the user toggle a virtual button to enable/disabled travel.
- There are a few
differences between ex13 and ex14a.
Example 14b: Virtual Controls: Slider (ex14b)
- When the virtual slider is moved, a control values can be
moved through the range from [-1, 1].
- The slider can be grabbed by the plate, or in the rod.
- The slider controls the speed of rotation (negative values reverse
the direction).
- Example 14b (ex14b_slider.c)
lets the user adjust the speed of travel with a slider-bar widget.
- There are a few
differences between ex14a and ex14b.
Example 14c: Virtual Controls: Lever (ex14c)
- The lever is also a single valued valuator (like the slider).
- The lever rotates about the base when grabbed by the ball-handle.
- Implementing the lever is a little more complicated than the slider-bar.
- In this example, the lever is used to control the travel rotation
of the virtual world.
- Example 14c (ex14c_lever.c)
lets the user control the direction of travel with a lever widget.
- There are a few
differences between ex14b and ex14c.
Example 14d: Virtual Controls: Radio Buttons (ex14d)
- Like the buttons on a car radio, the virtual radio button widget
allows the user to select one option from among many choices.
- This widgets uses text strings to indicate the available choices,
but icons or 3D models could also be used.
- This example does not make use of the radio button selection.
- Example 14d (ex14d_radio.c)
lets the user make a radio button choice.
- There are a few
differences between ex14c and ex14d.
Example 14e: Virtual Controls: Joystick (ex14e)
- Like the real-world counterpart, a virtual joystick control is a
two-valuator input device.
- We can implement virtual controls such as the joystick to operate
as though they have springs that will return them to center, or
the control can remain where it was released.
The same is true for the lever.
A "spring-loaded" SNAPBACK feature can be enabled in this example
by setting a #define prior to compilation.
- In this example, the virtual joystick now operates the travel
controls instead of the physical joystick on the wand.
- Example 14e (ex14e_joyst.c)
lets the user control direction and speed of travel with a
virtual joystick widget.
- There are a few
differences between ex14d and ex14e.
Example 14f: Virtual Controls: Push Button (ex14f)
- The virtual push-button control operates like a typical spring-loaded
contact switch.
The button is on when the user touches it, but once the user
ceases to touch the button, it turns off.
- Here, the push-button resets travel back to the initial coordinates.
- Example 14f (ex14f_pushbut.c)
lets the user reset travel with the touch of a button.
- There are a few
differences between ex14e and ex14f.
Example 15: The four methods of manipulation (ex15)
This example is not yet fully implemented.
Last modified 10 January 2010.
Bill Sherman, shermanw@indiana.edu
© Copyright William R. Sherman, 2010.
All rights reserved.
In particular, republishing any files associated with this tutorial
in whole or in part, in any form (included electronic forms)
is prohibited without written consent of the copyright holder.
Porting to other rendering systems is also prohibited without
written consent of the copyright holder.