CollisionMesh shape without a Model object

Apr 4, 2010 at 12:29 AM

Hey there,

First, thanks for Oops!  It's very easy to use and definitely a huge help.  I don't normally use game components as actual components in my XNA projects, so I've just been using the Oops physics system by itself and calling initialize/endUpdate/beginUpdate when necessary.  It's been working very well.

My problem (and "solution"): I wanted to create a CollisionMesh shape by simply providing a list (or array) of Vector3 vertices and int indices, but I couldn't find a way to do it.  I ended up adding an extra constructor to the ModelCollisionMeshProxy class that took two lists (vertices and indices) instead of a model.

public ModelCollisionMeshProxy(List<Vector3> verts, List<int> indices)
{
	// Save the positions
	this.positions = verts;

	// Create collision triangles from the indices.
	for (int i = 0; i < indices.Count; i += 3)
		this.triangles.Add(new CollisionMeshTriangle(this, indices[i], indices[i + 1], indices[i + 2]));

	// Create the bounding volume hierarchy.
	this.Initialize();
}

It works pretty well, as far as I can tell.  I'm hoping that I didn't miss something important in the process.  I always feel weird about altering a library, but I needed it for the way our game is set up.  I thought I'd bring this up and suggest adding something similar (maybe a TriangleCollisionMeshProxy class) for future versions, as it could be a big help for dynamically created geometry. 

Thanks again! I'm sure I'll have some questions in the near future :)

 

-Chris

Coordinator
Apr 4, 2010 at 2:52 AM

Good idea - I'll add this functionality to the framework.  Good luck with your game!