<?xml version="1.0" encoding="ISO-8859-15"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta name="dc:creator" content="J&ouml;rn Nettingsmeier &lt;nettings@folkwang-hochschule.de&gt;"/>
<meta name="dc:publisher" content="University of Duisburg-Essen, Dept. of Computer Science"/>
<meta name="dc:subject" content="Input devices for 3d virtual environments - the Spaceball under Linux"/>
<meta name="dc:description" content="Course presentation on VR concepts, spaceball hardware, installation and Linux software"/>
<meta name="dc:date" content="2003-09-24"/>
<meta name="dc:format" content="text/xml"/>
<meta name="dc:identifier" content="http://spunk.dnsalias.org/Model3D/term_paper.xml"/>
<meta name="dc:language" content="en"/>
<meta name="dc:rights" content="(c) 2003 J&ouml;rn Nettingsmeier - may be freely redistributed and modified. Credit is welcome :)"/>

<link rel="stylesheet" type="text/css" href="term_paper.css" />

<title>Input devices for 3d virtual environments - the Spaceball under Linux</title>

</head>

<body>

<div class="nav">
<a href="term_paper-1.xml">Previous</a> |
<a href="term_paper.xml">Table of Contents</a> |
<a href="term_paper-3.xml">Next</a>
</div>

<h1>2 Using the spaceball with Linux</h1>

<h2>2.1 Why bother with Linux at all ?</h2>

<p>
The problem with Linux in the context of VR applications is the complete and
utter lack of corporate support from hard- and software vendors. Thus you will
find VR under Linux a rather immersive and hands-on experience. But isn't that
what it's all about anyway ?
</p>
<p>
On the (commercial) Windows side, there used to be a number of capable solutions
that auto-installed in a few mouse clicks.<br />
However, most companies in the business that started
out alive and kicking way back when VR was a buzzword have shown an alarming
tendency to go belly-up at moment's notice, taking all their closed-source
drivers and middleware with them and leaving their customers with expensive
paperweights, no-longer installable browser plugins and virtual worlds that nobody
can view anymore.
</p>
<p>
This was the situation I found when Prof. Luther assigned me the spaceball
they had lying around in the faculty as a presentation project. There was one
known combination of browser, Windows version and driver that would run their
meticulously crafted VR project with spaceball control, yet alas - nobody had it
anymore.
</p>
<p>
All Linux software described below is open-source, and distributed under free
licenses such as the GNU Public License (GPL), which allows for modification
and free re-distribution of any derived works. Thus if the maintainer of a
program drops out, you can be sure the work you created with that program
remains accessible and is easily ported to new environments, and you are free
to improve the software and squash any bugs you find.<br />
Using Linux makes a lot of sense in academic projects, even though there are
no turn-key, end-user-ready applications (yet - some projects are very close).
</p>

<h2>2.2 Getting the hardware to run</h2>

<h3>2.1.1 Hardware issues</h3>

<p>
The spaceball's built-in electronics generate a continuos stream of
events while the ball is displaced from zero  - you might say the integration
mentioned above is performed in hardware. So it looks quite similar to a mouse
from a driver's point of view, which simplifies the driver code a lot.
</p>

<h3>2.1.2 Existing drivers and libraries</h3>

<p>
The spaceball version discussed here is the <span class="keyword">serial</span>
(RS-323) variant, which is readily supported by the standard serial driver in
current Linux kernels (2.4.20 as of this writing).
Since there is no standard serial interface for the spaceball events (the X mouse
protocol is not sufficient), each application must deal with the raw input from
the serial port.<br />
Fortunately, this tedious job is done by <span class="keyword">libsball</span>,
a GPL'd C library that you can link into your own programs (described below).
</p>

<div class="note">
<p>
The newer <span class="keyword">gameport</span> variant is supported by the
joystick driver in the current development kernels (2.6.0-testX), which also
takes care of mapping the events to userspace. The mapping is
configurable, so any program that supports the Linux joystick interface should
be able to make use of the spaceball.
</p>
<p>
The status of the current <span class="keyword">USB</span>-driven models is
 unknown - I would like to hear from you if you can get your hands on one.
</p>
</div>

<h3>2.1.3 Installation</h3>

<p>
Simply hook the spaceball up to a free 9-pin serial connector or get an adaptor
if your machine only provides 25-pin D-SUB ports. I've been hot-plugging serial
devices happily for years, but I guess recommended practice is to do it only
when the box is off, so power down first.
</p>
<p>
After booting, become root and test whether the spaceball is alive by opening the
serial port and dumping all incoming data to the console:
</p>
<div class="input">
root@yourbox:~&gt; cat /dev/ttyS0
</div>
<div class="note">
<p>
The <span class="input">/dev/ttyS0</span> stands for the first serial port or
COM1: in DOSspeak. Change to <span class="input">/dev/ttyS1..n</span> if you
are using another port.
</p>
</div>
<p>
You should see something like
</p>
<div class="output">
@1 Spaceball alive and well after a poweron reset.

@2 Firmware version 2.63 created on 28-Sep-1998.

EE

...
</div>
<p>
and a continuous stream of garbage characters. Press
<span class="input">Ctrl-C</span> to interrupt the
process.
</p>

<div class="note">
<p>
If some of the garbage characters have messed up your console, blind-type
<span class="input">reset</span> to get the terminal back in a usable state.
</p>
</div>

<p>
Now you can be sure your serial ports are working and the spaceball is ok.
If the above test fails, try plugging in a known-good modem or serial mouse.
If none of those yield any output, check whether your serial ports are enabled
in the BIOS and consult the
<a href="http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Serial-HOWTO.html">
Serial-HOWTO</a> at the <a href="http://tldp.org">Linux Documentation Project</a>.
</p>


<h2>2.3 Open-Source VR Applications for Linux</h2>

<div class="note">
<p>
The following packages depend on one another and should be installed and tested in the
order in which they are presented here.
</p>
</div>

<h3>2.3.1 libsball</h3>

<p>
libsball is a GPL-licensed C library that provides user-space support for a number of
Spaceball models. See the project homepage at
<a href="http://jedi.ks.uiuc.edu/~johns/projects/libsball/">
http://jedi.ks.uiuc.edu/~johns/projects/libsball/</a> for more information and a
comprehensive list of UNIX applications with Spaceball support.
</p>

<p>
Grab the latest source tarball, unpack it, read the README, compile it and run the test programs:
</p>
<div class="input">
user@yourbox:~&gt; tar xvzf libsball-1.0.tar.gz<br />
user@yourbox:~&gt; cd libsball<br />
user@yourbox:libsball&gt; make<br />
user@yourbox:libsball&gt; less README<br />
user@yourbox:libsball&gt; ./testsball /dev/ttyS0<br />
</div>
<p>
Optionally run the Open-GL demo application:
</p>
<div class="input">
user@yourbox:libsball&gt; cd sballfly<br />
user@yourbox:libsball/sballfly&gt; make<br />
user@yourbox:libsball/sballfly&gt; ./sballfly /dev/ttyS0<br />
</div>

<p>
Now you must install the library as root. There is no "make install" target, so you
have to do it by hand:
</p>
<div class="input">
user@yourbox:libsball/sballfly&gt; cd ..<br />
user@yourbox:libsball&gt; su<br />
root@yourbox:libsball&gt; cp libsball.* /usr/local/lib<br />
root@yourbox:libsball&gt; cp *.h /usr/local/include<br />
root@yourbox:libsball&gt; exit<br />
</div>
<p>
Congratulations. You have a running userspace support library for your spaceball. We will
use it with the FreeWRL VRML browser and the White_dune VRML IDE below.
</p>


<h3>2.3.2 FreeWRL, a VRML97/X3D browser</h3>

<p>
To quote the project page at <a href="http://freewrl.sourceforge.net/">
http://freewrl.sourceforge.net</a>,
<span class="quote">"FreeWRL is an open-source(R) VRML and X3D browser
written by a merry band of developers, who wish to produce a high quality,
up to date, browser that is in the public domain."</span>
</p>
<p>
It has reached version 1.0 in August 2003, and has quite an impressive list of
features, notably the ability to plug itself into Mozilla, Netscape or Konqueror,
turning them into VRML-capable browsers. It also makes use of hardware-accelerated
rendering if a 3D graphics card is found.
</p>
<p>
The project is actively developed in a funny mixure of Perl, Java and C and has seen a
number of releases recently. VRML97 support is almost complete, although I stumbled
across some PROTO problems. I have not tested X3D capabilities, but since it is
equivalent to VRML97, it should work
</p>
<p>
To install, grab the latest source tarball from sourceforge and unpack it:
</p>
<div class="input">
user@yourbox:~&gt; tar xvzf tar xvzf FreeWRL-1.01.tar.gz<br />
user@yourbox:~&gt; cd FreeWRL-1.01
</div>
<p>
Carefully read the <span class="input">INSTALL</span> file.
You will need to tweak the <span class="input">vrml.conf</span> file and
probably install a bunch of Perl modules from either your distribution media or
from <a href="http://cpan.org">CPAN</a>, plus a current Java SDK.<br />
Once you have checked all dependencies are there, do
</p>
<div class="input">
user@yourbox:FreeWRL-1.01&gt; perl Makefile.PL<br />
user@yourbox:FreeWRL-1.01&gt; make<br />
user@yourbox:FreeWRL-1.01&gt; su<br />
root@yourbox:FreeWRL-1.01&gt; make install<br />
root@yourbox:FreeWRL-1.01&gt; exit<br />
</div>
<p>
If all goes well, test your freshly compiled FreeWRL by issuing
</p>
<div class="input">
user@yourbox:FreeWRL-1.01&gt; freewrl tests/1.wrl<br />
</div>
<p>
Check out all files in test/ to see what FreeWRL can do, and read the manpage
(<span class="input">man freewrl</span>) to grok the command-line options.
</p>

<h3>2.3.3 FreeWRLduneInputDevice, a spaceball backend for FreeWRL</h3>

<p>
Now you are ready to add Spaceball support to the browser. There is a little module
called
<span class="keyword">FreeWRLduneInputDevice</span>, which is a spin-off from the
White_dune IDE discussed below and can be used to hook the spaceball up to
FreeWRL. Grab it from
<a href="http://www.csv.ica.uni-stuttgart.de/vrml/dune/FreeWRLduneInputDevice.html">
http://www.csv.ica.uni-stuttgart.de/vrml/dune/FreeWRLduneInputDevice.html</a>, and
again, unpack and install it:
</p>
<div class="input">
user@yourbox:&gt; tar xvzf FreeWRLduneInputDevice-1.4.tar.gz<br />
user@yourbox:&gt; cd FreeWRLduneInputDevice-1.4<br />
user@yourbox:FreeWRLduneInputDevice-1.4&gt; ./configure<br />
</div>
<p>
Read through the output of <span class="input">configure</span> to make sure it has found
your libsball.<br />
If all is well, build and install the binary and the manpage (it has bogus permissions, so
we correct them before):
</p>
<div class="input">
user@yourbox:FreeWRLduneInputDevice-1.4&gt; make<br />
user@yourbox:FreeWRLduneInputDevice-1.4&gt; su<br />
root@yourbox:FreeWRLduneInputDevice-1.4&gt; cp FreeWRLduneInputDevice /usr/local/bin<br />
root@yourbox:FreeWRLduneInputDevice-1.4&gt; chmod 644 FreeWRLduneInputDevice.1 <br />
root@yourbox:FreeWRLduneInputDevice-1.4&gt; cp FreeWRLduneInputDevice.1 /usr/local/man/man1<br />
root@yourbox:FreeWRLduneInputDevice-1.4&gt; exit<br />
</div>
<p>
What this little program does is continuously poll the spaceball and write its current state
to <span class="input">/tmp/inpdev</span>, which in turn is read by FreeWRL. Unfortunately,
this method hogs 100% CPU, but then it seems to work ok, so what!<br />
Let's test it:
</p>
<div class="input">
user@yourbox:~&gt; FreeWRLduneInputDevice -spaceball /dev/ttyS0 &amp;<br />
user@yourbox:~&gt; freewrl /some/vrml/world.wrl
</div>
<p>
Move the mouse over the freewrl window and type <span class="input">f</span> to enter
externally controlled fly mode. Wiggle the spaceball, and lo and behold: you can fly :).<br />
Check the manpage for ways to tweak the sensibility and orientation of the spaceball
axes. I found a global scaling factor of 2 the most convenient (<span class="input">-all 2.0</span>).
</p>
<p>
To get rid of the process in the background, either move it into the foreground
with the <span class="input">fg</span> command and then kill it with 
<span class="input"> Ctrl-C</span> or take the brute approach and issue 
<span class="input">killall -KILL FreeWRLduneInputDevice</span>.
</p>

<h3>2.3.4 White_dune, an immersive VRML IDE</h3>

<p>
White_dune is a visual VRML scene editor licensed under the GPL.
It supports immersive editing via shutter glasses or polaroid-filtered stereoscopic
projection. It is an active project hosted at the Universit&auml;t Stuttgart (Germany), and
there has been a round of new features lately.<br />
Visit the excellent <a href="http://www.csv.ica.uni-stuttgart.de/vrml/dune/">
project page</a> for details and a good entry page into VR on Linux and UNIX in general.
</p>
<p>
As before, download the latest beta tarball and unpack it. Follow the instructions in
the INSTALL file to build White_dune. They have a weird compile mechanism that is supposed
to generate a package suitable for the package manager of your distribution (rpm, deb, etc.).
Here is an example for rpm-based distributions:
</p>
<div class="input">
user@yourbox:~&gt; tar xvzf white_dune-0.25beta94.tar.gz<br />
user@yourbox:~&gt; cd white_dune-0.25beta94<br />
user@yourbox:white_dune-0.25beta94&gt; less INSTALL<br />
user@yourbox:white_dune-0.25beta94&gt; cd packager/rpm<br />
user@yourbox:white_dune-0.25beta94/packager/rpm&gt; su<br />
root@yourbox:white_dune-0.25beta94/packager/rpm&gt; sh mkrpm.sh<br />
</div>
<p>
It worked for me, although  the compiler spewed out a metric shitload of deprecation warnings
and other frightening things. Your mileage may vary.<br />
After the build, you can find the package in the standard place (e.g. /usr/src/packages/RPMS
for RedHat, SuSE or other rpm-based distros). Install it (example for rpm on Intel hardware):
</p>
<div class="input">
root@yourbox:white_dune-0.25beta94/packager/rpm&gt; cd /usr/src/packages/RPMS/i386<br />
root@yourbox:/usr/src/packages/RPMS&gt; rpm -Uvh white_dune-0.25beta94-1.i386.rpm<br />
root@yourbox:/usr/src/packages/RPMS&gt; exit<br />
</div>
<p>
For historic reasons, the binary will be called dune. Have a look at the manpage to find out about useful command
line options (<span class="input">man dune</span>). Let's start it with the spaceball as input
device (it has libsball built-in, so you don't need a helper program as with FreeWRL).
</p>
<div class="input">
user@yourbox:~&gt; dune -spaceball /dev/ttyS0<br />
</div>
<p>
Presto: here is a nice little VRML IDE for you to play with. If you are feeling adventurous,
you can even build it with support for immersive 3D displays (shutter glasses etc.).
</p>


<div class="nav">
<a href="term_paper-1.xml">Previous</a> |
<a href="term_paper.xml">Table of Contents</a> |
<a href="term_paper-3.xml">Next</a>
</div>


</body>

</html>

