[ODE] dxTriangle class

Squint squint at squint.clara.co.uk
Sun Mar 30 19:19:02 2003


OK, since I have been asked, I thought I'd post this, in the hopes that
someone finds it useful.
It may be more use indirectly as a simple example of how to make your own
geometry classes.

http://www.squint.clara.co.uk/dxtriangle.tar.gz

It is the beginnings of a triangle geometry class for ODE.
One or two quirks:

Due to the use I have for it, this triangle must be static (ie, it has no
body, its position is 0,0,0 and its orientation is identity). This isn't
because it can't be done (quite easily infact), it is just because I have no
use for that, since all of my triangles are part of an immovable 'terrain'.
Making it mobile would simply require handling mass, and transforming the
vertices for collision detection and aabb generation. And that would be it.

Also, instead of storing the vertex information, it simply references it.
This is why it contains pointers to vertex coordinates, and not the
coordinates themselves. Since all my vertices already exist in a vertex
array for open GL, I have no need of storing them again in dxtriangle, and I
have rather a lot...

Lastly, it only supports collision with spheres. Some other shapes can be
added to this quite easily, however, and I intend to add ellipsoids at some
point.

files in that tar ball are:

dxTriangle.h
dxTriangle.cpp
Vec3.h
Geometry.h
test_boxstack.cpp
Makefile

The first 4 are the source for the triangle stuff (sorry about Vec3.h, but I
can't figure out ODEs vector maths stuff so I just made my own).
The last .cpp is a hacked version of test_boxstack, with a triangle in, more
as an example than as a test. All the changed bits are commented.
Makefile is exactly that, for linux. It really isn't a very complicated
makefile.

One more comment:

This is not (used directly) the most efficient way of colliding with an
entire mesh... I do have a dxMesh class too, but it is way too entangled in
my own libraries to try to distribute (even untangling dxTriangle was quite
a headache, which is possibly a bad sign). dxMesh is left as an excercise
for the reader. It is a fairly trivial extension.

I simply copied the ODE licence header stuff into my own files and changed
the name. Hope you don't mind. I've no real idea atall when it comes to all
that stuff and wanted to say 'use as you see fit' without getting stabbed in
the back by an enraged lawyer.