Mesh object

A mesh is just a large collection of triangles:

Mesh object

For collision detection, a mesh should be treated as a linear list of triangles. Meshes can be constructed by hand, or loaded from a file. An OBJ loader sample is included with the code accompanying this chapter.

Getting ready

In this section, we are going to declare the Mesh structure that will be used to test for collisions against arbitrary 3D models.

How to do it…

Follow these steps to implement a mesh primitive:

  1. Declare the Mesh structure in Geometry3D.h:
    typedef struct Mesh {
  2. We need to know how many triangles the mesh will have:
        int numTriangles;
  3. With this anonymous union we can access the ...

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.