Tutorial 10: Mesh Shapes Note: The instructions in this
tutorial refer to versions of OPAL after 0.3.0 (including the CVS version). Meshes in versions 0.3.0 and earlier had
problems that made them unusable. This
tutorial describes how to use mesh Shapes.
Although this process is more complex than using primitive Shapes like
boxes and spheres, it allows you to use your own triangle mesh for collision
detection. There are four pieces of
data that are necessary to create a mesh: the number of vertices, an array of
vertex data, the number of triangles, and an array of indexed triangle
data. No matter how you get your
geometry data (e.g. loading it from an OBJ file, generating it programmatically
at runtime, etc.), it must be represented in this
format. The
vertex and triangle arrays must be 1-dimensional arrays. The size of the vertex array is 3 times the
number of vertices since each vertex uses three elements (for its x, y, and z
components). Similarly, the triangle
array is 3 times the number of triangles since each triangle uses three
vertices. The following diagrams show
how these arrays must be organized: The
indexed triangle array stores the indices of vertices in the vertex
array. For example, in the diagram
above, “triangle 2” uses vertices 1, 2, and 4 in the vertex array. This storage method is fairly common; it allows
vertices to be reused by multiple triangles.
The
following example shows how to copy your geometry data into the MeshShapeData structure.
This example assumes that the geometry is initially stored in
2-dimensional arrays.
|
OPAL is Copyright © 2004-2005 Alan Fischer, Andres Reinot, and
Tyler Streeter