Collision Detection for Sliding Simulations in VR

Wednesday, March 28. 2007
Programming
Currently I have to develop a robust method for sliding simulation in a immersive VR environment. This means that the user in a CAVE should be able to move objects around, but these movements should be resitricted by collisions with a static environment. Unsurprisingly this task turns out to be non-trivial. We chose to integrate ODE as a physics simulation backend combined with our own collision engine originally developed by Gabriel Zachman.

There are two obvious problems:
  • The virtual body moved by the user eventually has to be moved by ODE. This means that I had to extract the forces needed to move the object as desired by the user and pass them to the physics engine. This has been rather easy once I understood what the words torque and intertia tensor mean (both are needed for rotational movements).

  • The more complex problem is the integration of the collision engine. The integration itself was straight forward, but the real problem is, that as soon as a collision is detected, the simulation gets out of control. The reason is that what we really would need is a penetration depth or we have to try to approximate the exct time of the first collision between two bodies. As our collision engine does not offer the penetration depth, I have to go down the second road and approximate the time of collision by progressively subdividing timesteps in case of a collision.


Interestingly I found out that commercial physics packages seem to employ much more advanced collision algorithms which can calculate the penetration depth or work in a continious mode and thus calculate the exact time of the first collision. Plus many games use simplified collision geometry and special bodies (spheres, cylinders, boxes) which make such calculations much more easy, while we have to cope with arbitrary high-resolution triangle meshes.

While looking for solutions on the net, I found two good PhD thesises on physics simulations:

Easy Bytecode

Wednesday, February 28. 2007
Programming
Writing a interpreter for a custom scripting language always seems to be more complex than writing a small bytecode compiler and bytecode interpreter. At a first glance, writing a direct interpreter might be easier, but if the scripting language contains flow control (like loops, if/else statements and similar constructs involving jumps), this turns out to be false. The primary problem lies in the fact that one needs to duplicate large parts of the parser - simply for skipping over the parts of a script that are not executed (like with a conditional if-block whose conditioon turns out to be false at runtime).

Because of this insight, I began to concentrate on writing an easy-to-implement bytecode compiler that would transform a text-based script into a more machine-friendly representation. A positive side-effect of bytecode is that simple fact that it is much faster to execute than the original textual representation. The downside of this approach is the fact that it involves writing a compiler - something that sounds to be a complex and difficult task.

But after analysing the process of parsing a script, I came to the conclusion that such a compiler and its corresponding bytecode interpreter ("virtual machine") would be rather straight-forward and easy to implement, if the underlying model of the virtual machine is chosen carefully. In my opinion the best machine model (in terms of simplicity to implement a compiler and interpreter) it a purely stack-based RPN (Reverse Polish notation) machine. And such a model not only is easy to implement, but it also easy to extract the original syntax tree from the bytecode, which in turn allows further optimisation techniques as a postprocessing step (it even wouldn't be to hard to turn bytecode into native assembler).

Continue reading "Easy Bytecode"

Reflection for C++

Monday, February 26. 2007
C++
One hot topic I am currently busy in, is reflection for C++. Reflection for a computer language means that you can access all types toegther with their methods and members at runtime using a simple string-based interface. Such a feature especially simplifies binding scripting-languages to a program by providing one wrapper that operates on the reflection information instead of binding each class, method or function by hand. Other possible usages are remote-method-invocations, serialisation, XML based configurations etc.

C++ offers only some very basic runtime type information (RTTI) out of the box and lacks full reflection. There are some projects on the net that try to close this gap (most notably the Reflex framework), but none of them really seem to be as powerful, flexible and easy-to-use as their native counterparts in Java or C#.

Dimajix's framework Magnum soon will contain some new modules that try to fill this gap, by offering the following tools:

  • A generic Meta-Compiler based upon gccxml together with a specialised XML-based transformation language.

  • Non-intrusive, full reflection for all public elements of any C++ program given in source.

  • A Java-like scripting language built on top of the reflection together with a custom bytecode compiler.


With these tools, one can easily add generic scripting capabilities to any C++ program with only some little one-time effort. Plus it is possible to use the Metacompiler for automatically transforming any type-information given in C++ headers in any kind of text-based files, by providing a set of transformation rules which will be applied to the C++ metainformation generated with gccxml.

The new package is not completely finished yet, there are some features still missing, but work is steadily progressing. For a preview, you can simply check out the latest version of Magnum using Subversion at svn://subversion.dimajix.de/magnum.

Promotional Video for Windows 386

Monday, January 29. 2007
Weird
While all people are talking about Windows Vista, lets look back in time:

The 80s really were a weird time, with a very strange taste for clothing. And a real laughable highlight is the Promotional Video for Windows 386 promoting the wodners of multitasking, with the best part coming at minute 7 after a boring start. Some people even wouldn't be surprised if it turned out to be sleazy porn scene.. It shouldn't be a surprise that you will not find many hits for the directory David Vik on google.

I am so glad that the 80s are over.

Status of Magnum

Saturday, January 13. 2007
C++
A short intermission with a status report of Magnum. Finally I put up a public SVN repository which can be reached under svn://dimajix.de/magnum. The repository has public read access for everyone and is synched with my private development repository every night, so it is always almost up-to-date.

The most important feature that will be included in the next release version is full reflection. This means that one can access the complete type information including classes, structs, unions, enums, methods, functions, fields and variables via a dynamic interface at runtime. You can even invoke any method or create new instances of arbitrary objects. This should make it rather easy to make up a small scripting language which can access all types defined in Magnum.

This is a really huge undertaking, but most of the really hard stuff is already working (you can download the newest version via Subversion, as indicated above.). Still missing is some intelligent automatic argument casting for method-invocation (so you do not have to care about the exact needed types), some fixes for non-public class members and - most importantly - the integration into the build system.

The really special about my implementation of the reflection is that you will not need to modify your source-code (at least I try really hard to avoid the need of changes to the source code for which reflection is to be generated.) to make your classes accessible via reflection. The meta-compiler, which reads in all headers and creates some cpp files containing the needed runtime information for reflection, is also outstanding in that it uses a generic XML-based language to transform the meta-information parsed from the original header files into a new text-based output file. The metacompiler is not tied to my implementation of reflection and can (and will) be used for many other automatic header-transformations. For example one could write an XML template that generates serialisation code for arbitrary classes (this actually shouldn't be too hard). Other possible uses include the generation of COM or .Net wrappers (or for any other scripting language), etc.

Why Windows Home Server will be a success

Tuesday, January 9. 2007
Workstations
According to ars technica, Bill Gates showed off his newest product, the Windows Home Server as part of his keynote last Sunday at the CES. The WHS is a small device intended to be the central server for home users for storing their photos, music etc. Paul Thurrot has a small preview of this server and a hardware implementation done by HP (Microsoft only delviers the operating system). On OSNews there has been a debate for the need of such a product.

I predict that the Windows Home Server will be a big success for Microsoft, and I will try to elaborate on the reasons: Nowadays we live in the so called "information age", that is after industrialisation, information is the new driving force in out culture. More and more people have have multiple computers at home (you do not want to know how many I own) and other electronic devices like digital cameras, media players, digital video recorders etc are already standard equipment in many households.

This means that digital content and properties replace traditional values in our life. This also means there is a new need for protection of your personal investments - ten years ago, you could mainly lose your possesions in terms of a physical loss. Nowadays more and more important and valuable data is stored on various computers at each home. This imposes two problems: First you want a centralized storage for all your digital data (photos, movies, music, documents etc), and second you want a secure backup of all your data. Many people become increasingly aware of the first problem, but the second is the really important one. In former times, you only lost part of your values if - for example - a CD got scratches or was stolen.

But nowadays if your harddisc crashes, you probably will lose a lot of irretrievable data like your private email etc. So you wish that you had a backup of all your data, or even better a centralized storage that is protected against hardware faults by some redundancy.

These are just the reasons why a home server makes sense for a lot of people today. One can argue that there are already a lot of good and affordable NAS boxes out there, but most of them are not more than simple NAS boxes (one exception would be Infrants product reportoire) that don't offer comfortable backup utilities or are too complicated for the average user. This is why I see espceially Windows Home Server to be a success - if done right and with the help of Microsofts massive marketing forces.

For me, I probably won't buy a Windows Home Server, because I want something more professional - I want to have a blindingly fast RAID server with tons of storage, support for different file protocols (NFS comes to my mind), although the hardware specs of HPs machien are promising: 1.8 GHz AMD Sempron paired with 512MB of RAM. This should offer twice the performance of Thecus N5200 NAS solution, which is already by far the fastest affordable home NAS out there (although with many firmware limitations and problems).

If Life Ran on a Solaris Cluster

Monday, January 8. 2007
Weird
You might wonder what the girls at Sun expect from a boy friend. You can find the answer in a small spot at YouTube:

  • availability

  • reliability

  • redundancy

Why you want ZFS for Linux

Saturday, January 6. 2007
Workstations
Currently I am thinking of replacing my (rather new) ReadyNAS NAS server by a more powerful self-built server. Although the ReadyNAS is a very nice device with very good support from Infrant, it is still too slow for storing all remotely mounted user directories for my Linux and Mac box. Plus I am thinking of using a iSCSI volume for all user directories on my Windows box.

My ideal server would contain an Areca SATA controller with 16 channels and 15 disks in hot-swap carriers running in a RAID-6 plus one or two fast gigabit controllers. So much for the hardware.

But another important aspect is the software of course. Currently I would opt for OpenFiler as operating system for the server. OpenFiler is based on Linux and supports all features I want, except for efficient snapshots. Snapshots are a wonderful thing, they allow to keep an old state of a file-system without the need to do an explicit backup (although one still should backup ones data because of the risk of hardware faults). OpenFiler implements these snapshots using LVM (Logical Volume Manager), which in turn implements snapshots on a Copy-on-Write base. This snapshot implementation has two main drawbacks:
  • You have to allocate space for the snapshot on your disks.

  • The more snapshots you have, the slower gets your system .

And this is exactly the point where Suns filesystem ZFS comes in. ZFS also supports snapshots, but as it seems in a much more efficient way. You do not need to preallocate space for the snapshot and it seems that there is no performance penality by using them. So I'd love to use ZFS together with OpenFiler - but ZFS currently is only available in Solaris with a Linux port under the way. But I guess it will take more time for the Linux port to finish and to be integrated into OpenFiler than I want to wait with my new NAS server.

Snapshots really are the reasons why everyone wants ZFS on Linux. Okay, at least this is my personal top reasons why I want to see it soon. Or a port of OpenFiler to Solaris ;-)