How to use Wiiheadtrack

Daniel Wunderlich (
Christian Rohrbeck (

In this section, the usage of Wiiheadtrack is demonstrated. You should also take a look at the two OpenGL example programs -- one using the object-mode, the other one using the room-mode. You can find the whole codes at

Remark: The examples tend to demonstrate the usage of the class in a minimalistic way. They don't consider code conventions.

Getting started

Before you can use Wiiheadtrack, you need to compile the wiiuse library. After you downloaded and extracted Wiiheadtrack, you can run


at the command-line (while you are in the downloaded Wiiheadtrack-folder). If you need to compile wiiuse again (e. g. if you want to use your program at another computer/operating system), you can use

 ./ clean 

to delete the compiled files and compile wiiuse again.

Include Wiiheadtrack and link wiiuse

To use Wiiheadtrack in your program, you have to include its header:

 #include "wiiheadtrack.h"

Because Wiiheadtrack uses wiiuse, you have to include the path of wiiuse.h (wiiuse/src) and the wiiuse library (wiiuse/lib) and link wiiuse (-lwiiuse) when you compile your program. As an example, this is the makefile of our demo-object-mode.cpp:

 CC          = g++
 CCFLAGS     = -c -Wall
 LIBS        = -L /usr/X11/lib -L wiiuse/lib
 INCLUDES    = -I wiiuse/src
 LDFLAGS     = -lglut -lGL -lGLU -lm -lwiiuse

 MYOBJECTS   = demo-object-mode.o wiiheadtrack.o
 BIN         = demo-object-mode
 $(BIN): $(MYOBJECTS) Makefile
        $(CC) $(LIBS) $(LDFLAGS) $(MYOBJECTS) -o $(BIN)
        $(CC) $(INCLUDES) $(CCFLAGS) $<
        rm -f *.o $(BIN)

Create a Wiiheadtrack-object

As a next step, a Wiiheadtrack-object needs to be created:

 Wiiheadtrack wiiht(WIIHT_MODE_OBJECT, 1);

The constructor needs to know the mode you want to operate it with (WIIHT_MODE_OBJECT or WIIHT_MODE_ROOM) and the number of Wiimotes, you want to connect to the program.

See also:
The two modes

Remark: The current version of Wiiheadtrack only supports one Wiimote.

Connect to the Wiimote(s)

Before connecting the Wiimote(s), you may decide, how long the program tries to connect to the Wiimote(s). By default, the duration is 5 seconds. Expected that the user is too slow, you can set this time, e. g. to 7 seconds:


Now you can connect to the Wiimote(s):


Configuring Wiiheadtrack

You can configure some properties of the Wiiheadtrack: The most important property is the sensitivity. (Please read the related page for detailed information before.) For example, you can set the sensitivity of moving left/right and up/down


For setting the sensitivity of moving forward/backward, you can call

 wiiht.setEyeDist(730.0, 550.0);
 wiiht.setPosDist(10.0, 5.0); 

for instance. Because some systems invert the y-Value of the current position, you can invert the y-axis:


These configurations need to be done only once.s

See also:

Getting the position of the user

Finally, the current position of the user in front of the camera needs to be detected, mapped (depending on the choosen mode) and read out. These steps need to be done before every call of the virtual camera in some kind of idle-function.

Detecting and mapping the users position is done by


After this call, the mapped position is saved in the 3-dimensional array Wiiheadtrack::pos (the relative change of the position is also saved -- in Wiiheadtrack::posRel) inside the Wiiheadtrack-object. You can access this array with the help of

 float* posPointer = wiiht.getPos();

which returns a pointer to the first element of the array. Now can use the pointer to read out the position and place your camera, for example:

 float pos[3];
 pos[0] = *posPointer;
 pos[1] = *(++posPointer);
 pos[2] = *(++posPointer);
 gluLookAt(pos[0], pos[1], pos[2], 0,0,0, 0,1,0);

If you want to use Wiiheadtrack for detecting the relative change of the user, you can use

 float* posPointer = wiiht.getPosRel();


See also:
Computation of the position


You can also enable/disable Wiiheadtrack. It is enabled by default; disabling Wiiheadtrack means computePos() won't change the position anymore.


Sometimes it is helpful to read out the current status of Wiiheadtrack. For this purpose you can call

 All Data Structures Files Functions Variables Enumerations Enumerator