• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
RollerSimmer

Collisions: should I use triangles, cubes or spheres?

9 posts in this topic

I am involved in the development of an open source game featuring theme park construction and operation. For this game I want to make a quadtree map for collisions to prevent two solid objects from going in the same space. ( I have considered octrees, but they don't seem useful in relatively flat space. Quadtrees would be sufficient.) That part is mostly figured out, except for the core collision testing for each object in the tree. Triangles are very precise, and would correspond to the object's graphics almost exactly. The problem is that the algorithm is a little "involved" - both for me and the processor. For spheres I easily do a single-line function based off of distance-squared. Boxes, as long as they are axis-aligned, would be a simple case of comparing bounds. I've looked over a few texts explaining triangle intersection, and they involve multiple steps and a lot of linear algebra. I generally understand the math and geometry behind it, but it seems too complex for my needs.

I would like a certain degree of precision (perhaps within a third of a meter or so), but with small radii and more points in the "cloud", I could make collisions somewhat accurate with variable-radius spheres. Axis-aligned boxes would require more comparisons, but not as many as triangles would. Plus I would still need a lot of "grains" to make the map accurate. Should I go for simple computations and high memory usage, or multiple step matrix and vector processing with lower memory usage? I would like graphical collision to be close to physical collision, but not exact. The polygon counts for large roller coaster track go into the 100K+ range. The number of objects on a map will be huge. Think along the lines of RollerCoaster Tycoon or SimCity. This game aspires to something of that scale, if not bigger.

I am using Irrlicht game library for this game. I know there are some collision checks in that engine, but they seem tied to graphics scenes. I may want to make the collision geometry for certain objects (like ride track) simpler than their graphical mesh geometry. I figured a custom tree would be needed for this task. With STL dynamic structures, that should be a piece of cake. But if someone can point me to a better way, I would be glad. I don't like reinventing the wheel if I don't need to.

Any general advice on collisions in 3D would be appreciated.
0

Share this post


Link to post
Share on other sites
Personally I would go with whatever gave the tightest fit to the object. You don't want to use a sphere bounding radius when the object is cube shaped. Just have a couple predefined bouding shapes and pick or choose for each object. Your could use bounding meshes for complex objects, but this would be memory and cpu intensive.
0

Share this post


Link to post
Share on other sites
I was thinking about that. Each occupancy in the tree could have a tag giving it's shape type. I think vertical cylinders may be easy to include as well. Any shape with simple bound checking would work.
0

Share this post


Link to post
Share on other sites
Frankly, I don't understand why you'd need accurate clash checking for a theme park sim. What are the objects whose clashes you need to prevent?
0

Share this post


Link to post
Share on other sites
What are your performance requirements? Are you going to have LOTS of objects, or just a few? Do you need to test for collision frequently, in real-time?

That is, how many collision evaluations do you expect to do per second?

Are you sure the player will care about the difference between circle tests and triangle tests?

One approximation that can be uses is to represent every object with more than once circle. Maybe 3-4 of them if your objects are generally formed like triangles.
0

Share this post


Link to post
Share on other sites
You can have many bounding volumes and do different tests.

As someone pointed out, a sphere isn't a good fit with most objects. However, a Sphere can contain any object, and it's a cheap test to perform. If two object's bounding spheres do not intersect, then there is no need to proceed onto more expensive tests, because they can't possibly be colliding. If they do intersect, then you can loop through the objects hierarchy of other bounding volumes to get a more specific result.

eg:
You can have a character that has a bounding volume for every limb. And then a bounding sphere that surrounds the whole character. Then you can have a projectile, and test the projectile against that sphere.

-If it doesn't the sphere, it can't possibly intersect the other volumes, because they are in the sphere. So you save yourself the trouble of having to transform all the other volumes and do those extra tests.

-If it does intersect, it may still be a miss, but at least now you know that the more specific tests are worth running. Transform those volumes along with the character's current animation frame, and then do the tests.

The big spheres are a cheap first pass at collision. In a big scene it lets you quickly skip hundreds or thousands (or even more) of needless tests, and then focus only a small list of possible collisions.
0

Share this post


Link to post
Share on other sites
Spherical collision is great performance-wise, but some meshes may be hard to sum up as a mere sphere and produce silly collisions depending on the radius you apply to them. The key to maximizing performance is skipping the sqrt on your distance call, and instead squaring the other side of the comparison equation... So that

[source lang="cpp"]
typedef struct
{
float x, y, z;
} vec3_t;

typedef struct
{
vec3_t origin;
float radius;
// etc properties...
} object_t;

// returns 1 if colliding, returns 0 if not..
int ObjectsColliding(object_t *a, object_t *b)
{
vec3_t delta;
float dist_sqr, sizes_sqr;;

delta.x = a->origin.x - b->origin.x;
delta.y = a->origin.y - b->origin.y;
delta.z = a->origin.z - b->origin.z;

dist_sqr = delta.x * delta.x + delta.y * delta.y + delta.z * delta.z;
sizes_sqr = a->radius + b->radius;
sizes_sqr *= sizes_sqr; // this is faster than sqrt(dist_sqr)

if(dist_sqr < sizes_sqr)
return 1;

return 0;
}
[/source]

Alternatively you could use axis-aligned bounding boxes but then everything collides as rectangular prisms (ala Quake1/2).
Or a combination of a vertical axis-aligned bounding 'space' (eg: a height) combined with an XY pythag collision to produce cylindrical collisions, which is better suited for bipedal type character collisions.. Or you can even implement all three options to be used with specific objects that each is better suited for, requiring that you implement detection for each possible type of collision (sphere/sphere, sphere/bbox, sphere/cylinder, bbox/bbox, bbox/cylinder, cylinder/cylinder). Edited by radioteeth
0

Share this post


Link to post
Share on other sites
There's something definetely wrong with this thread, as with most threads involving physics and CD.
This threads lacks the notions of [i]broadphase [/i]and [i]narrowphase[/i].
No matter how fast a narrowphase is (in the case of hierarchical structures), it is not enough.
So, I'm sure I'll get bashed again for writing this, but everyone considering writing a CD library should[list=1]
[*]Reconsider their decision
[*]After consideration, they might want to look at Bullet for good practices (as I consider it an excellent library given it has been used in movie industry as well).
[/list]
That said,
[quote name='RollerSimmer' timestamp='1352775641' post='5000435'][list=1]
[*]I would like graphical collision to be close to physical collision, but not exact. The polygon counts for large roller coaster track go into the 100K+ range.
[*]The number of objects on a map will be huge.
[*]With STL dynamic structures, that should be a piece of cake.
[*]But if someone can point me to a better way...
[/list]
[/quote][list=1]
[*]As you note a few lines later, you totally must use special collision geometry. For models counting 100k+ polys, I'd be rather surprised if the corresponding collision geometry would take more than 5K. You might also consider building the geometry as an assembly of rigid bodies.
[*]Barely relevant if you use a broadphase. In most of my tests, doubling the amount of collidable objects incurs in a 5% performance penalty. Those are only my tests, on my dataset, yours could be different and likely will... but I think it's good scaling.
[*]Unfortunately not, as they lack the proper management for alignment requirements and such. Ok, I guess you could write your own [font=courier new,courier,monospace]std::allocator[/font] to make them work. Bullet does not use them, possibly because of portability issues. I don't know.
[*]Yes, consider using a CD library. You also get dynamics "for free" (in effort terms). Think about it.
[/list]
0

Share this post


Link to post
Share on other sites
I'm going to try Bullet. I didn't really want a full physics simulator, just something for space occupancy to prevent overlapping items. I'll see if Bullet has something to that effect.
0

Share this post


Link to post
Share on other sites
[quote name='Stroppy Katamari' timestamp='1352803366' post='5000515']
Frankly, I don't understand why you'd need accurate clash checking for a theme park sim. What are the objects whose clashes you need to prevent?
[/quote]

Maybe "collision" is the wrong word. I meant overlap avoidance of objects. Although there may be mini games involving free bodies that need physics and collisions. All I need is a simple boolean function that tells me if there is something where I want to place an object. Location of contact and force are irrelevant.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0