Game Development Reference
In-Depth Information
Five btVector3 objects contiguous in memory.
The btConvexHullShape constructor expects us to provide three things: the
memory address of start of a list of vertex points, the number of vertices, and the
stride, or how many bytes in memory it should jump to reach the next vertex.
Since the memory address must be provided in the form of btScalar , we will call
getX() on the first point to get the memory address that we need. The number of
vertices is required so that it knows when to stop counting (computers are stupid like
that), and the stride is necessary to determine how to count. The default value for the
stride is 16 bytes, which is (not by coincidence) the size of a btVector3 object; so
there's actually no need to provide this argument, but it is worth mentioning because
this concept appears all the time when working with vertex and index buffers.
Hopefully things become clear once we explore the code for this procedure:
// create a vertex cloud defining a
square-based pyramidbtVector3 points[5] =
{btVector3(-0.5,1,1),
btVector3(-0.5,1,-1),
btVector3(-0.5,-1,1),
btVector3(-0.5,-1,-1),
btVector3(1,0,0)};
// create our convex hull
btConvexHullShape* pShape = new
btConvexHullShape(&points[0].getX(),5);
// initialize the object as a polyhedron
pShape->initializePolyhedralFeatures();
// create the game object using our convex hull
shape
CreateGameObject(pShape, 1.0, btVector3(1,1,1),
btVector3(5, 15, 0));
Search WWH ::




Custom Search