• 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.

Archived

This topic is now archived and is closed to further replies.

Shadow Mint

Bouncing Balls

4 posts in this topic

We''ve all seen the silly demo which has a bunch of balls bouncing around in 3D space...I hope so anyway. It''s a fairly simple/common demo. What I want is a good algorithm to do collision detection between the balls that are bouncing. Since all the balls are well...balls, I''m saying each one is a particle defined by a sphere of radius R. When the number of balls is small, it''s fairly simple to check if any of the spheres overlap; For each x, y, z, get a minimum (coordinate - radius) and a maximum (coordinate + radius). For every other ball, check if the spheres overlap. The order of this is shocking however. N*N*(Number of operations to see if a ball is overlapping another ball). So I want a more efficient algorithm to achieve this. I''ve had quite a look around and the only real collision detection I can find is based on trying to do collision detection on a polymesh, using cubes or sphere (elipsoids) to approximate the polygons. Can anyone suggest some reading on this matter? So far the very best I''ve come up with sorting the balls into a series of trees by x, y, z and then using the binary tree to throw away any balls which are outside the target area. This can reduce the calculations in the best case situation, but on the worst case it''s more calculations and the average case is only something like 2% more efficient. When I actually implement it and use random starting positions and velocities on the balls, I get a comparable time taken for collision detection (1000 balls). Any thoughts on the matter most welcome. I''m getting quite frustrated by things which say: "Particle Collision Detection Algorithm!" and then spent 30 pages on generating BSPTrees from polymeshs and collision caching and about 1/2 a page on actually doing collision detection. Thanks!
0

Share this post


Link to post
Share on other sites
An idea that comes to mind is to discretize the containing volume and test for collisions within the elements. What I mean is that you divide your volume - the cube within which the balls are bouncing - into a 3D matrix of smaller volumes. You then index through them searching for which balls have their centers encompassed by a cube element, and test those against each other. This has bizarre results for balls that should collide but are in adjacent cubes, so it''s far from perfect but should yield fair results.

If your application is object-oriented, you could even have the individual balls query the cube elements - the one they are in as well as the adjacent cubes - for the coordinates of any occupying balls, and then do collision detection against them.

You call also simplify your detection by checking the distance between the centers of your spheres rather than for overlap of their volumes. If the vector distance between two balls (centers) is less than twice the radius, there''s been a collision.

I hope this helps somewhat.
0

Share this post


Link to post
Share on other sites
Initialize the system by calculating, for each ball, the first time it will hit any other ball. Keep these times in sorted order.

Then, advance the simulation to the time of the next collision (i.e. the first thing on your list). After the collision, recalculate the new collision time for every other ball, update your list accordingly.

With this method you only have to do n comparisons every collision instead of n^2 comparisons every frame. You also get around the problem of fast balls missing collisions because your simulation time was to high and the ball "warped through" the one it was supposed to collide with.

-Mike
0

Share this post


Link to post
Share on other sites
Another method is ''sweep and prune'':

To do this project all the balls onto each axis in turn. E.g. on the x axis this means taking the x coordinate of each ball, adding and subtracting it''s radius and noting the values obtained. Do this for every ball and sort the results. Repeat on the y ans z axes.

As the balls move keep track of these values and keep them sorted. Assuming they are not moving far each frame the sorting may not often change or at most it will require a few exchanges, done by a couple of passes of a bubble sort.

A collision can only occur between two balls when they overlap on all three axes. This greatly reduces the number of pairs that need to be considered, and it''s easy to detect new candidate pairs during sorting, e.g. when the upper bound of one object is swapped with the lower bound of another during sorting.

In general the calculations are quick and scale with the number of particles, e.g. O(n). You do not need to know anything about how the objects move (needed for the time prediction technique) or how they are distributed (needed to fix a grid size). And this works well for other shapes: just use bounding spheres or axiz-aligned bounding boxes for more general objects.
0

Share this post


Link to post
Share on other sites
A thing i thought of whilst reading the above "sweet and prune" reply:

Firstly, check only the x-axis for all the balls, and save all overlapping balls found (radius distance checking). Next, move on to the y-axis, and check only the collisions for those balls having collided in the x-axis. Save only the ones that have 'collided' in both x-axis _and_ y-axis. Finally, check the z-axis collision for those balls that still are left. :D

Is this efficiant - or what?.

//parklife



Edited by - parklife on July 6, 2001 4:01:45 AM
0

Share this post


Link to post
Share on other sites