Physics Engine and Terrain

Started by
5 comments, last by oggialli 18 years, 1 month ago
Hi All, I am implementing a basic physics engine into my game, and I can understand how objects work with collision detection by having one or more bounding volumes, but I am at a bit of a loss as to how to check collision with the terrain. Having a bounding volume for each tile would obviously be nowhere near accurate enough, and in fact thinking about it the only true accuracy would be to do polygon level checking. This seems very expensive though, not to mention the duplication of data between the physics engine and the render engine which from what I have heard should be modular in design. How do other physics engines do this? Do they use some kind of hack or do they just bit the bullet and do polygon checking? Thanks!
Advertisement
Some third-party physics engines have a function where they "compile" a polygon soup and even allowed you to save the "program". I suspect that the major one in particular generates a 3D-tree from the set. Other major third-party engine I've used forces you to provide a collection detection function. At that point you can optimize the function for your particular terrain say a triangle-tree, quad-tree of some type, or just an index lookup if you're using a regular grid for your terrain data set.

I personally didn't like the one that "compiled" the polygons. It definitely wouldn't work if your terrain was dynamic, and seemed shady. It was pretty fast however. I also don't think you can realistically expect to do a brute-force linear test of the polygons and have acceptible speed if you've got a moderately sized dataset... you've got to have some kind of subdivision.

:-D

If your terrain is tiled, you can find the X-Z coordinates of the tiles you are potentially in collision with. Then you just have to do a 'proper' collision on those tiles, which is likely to only be four tiles max for most game types.
Quote:Original post by krum
Other major third-party engine I've used forces you to provide a collection detection function. At that point you can optimize the function for your particular terrain say a triangle-tree, quad-tree of some type, or just an index lookup if you're using a regular grid for your terrain data set.

Interesting. So, you provide some kind of callback function reference for the object? Can you elaborate a bit more on how this works?

Thanks

If it's C++ it might very well just be pure virtual functions to implement for your object.
Olli Salli
Quote:Original post by oggialli
If it's C++ it might very well just be pure virtual functions to implement for your object.


Oh, so the physics engine would define an object interface which you could inherit from for your objects and then override some kind of IntersectBox() or IntersectSphere() type virtual function?
Well my engine-in-the-works-for-my-game-in-the-works does just that (or actually it's more like object_in_scene_graph->intersects(whatever_overloaded_for_all_collision_baseclasses)).
Olli Salli

This topic is closed to new replies.

Advertisement