[gameprogrammer] Re: About 2D collision detection
- From: David Olofson <david@xxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 27 Oct 2006 17:22:26 +0200
On Friday 27 October 2006 16:44, Facundo Dominguez - Inco wrote:
> Thanks!
> You got me a few tips I didn't think of!
>
> I wonder, yet, whether polygon intersection can be considered cpu
> intensive ...
That depends entirely upon how much of it you're doing. If you use
bounding boxes or bounging circles together with some suitable
structure to avoid testing everything against everything all the
time, you can improve scalability a great deal. The cost of
the "exact" detection method impacts only groups of objects that are
close together - and if your game design doesn't generates lots of
situations like that, the cost of "exact" detection can be next to
irrelevant, as you'll be doing very little of it per frame.
If your game is instead designed so that practically everything can
collide with everything, and objects tend to work in tight
formations, higher level logic can only help to some extent. There
will still be lots of "exact" tests every frame, so they'll need to
be - relatively speaking - fast.
Another thing that matters a great deal in games where the map is a
lot larger than the visible playfield window, is how your game logic
deals with off-screen objects. In the 8 and 16 bit days, off-screen
objects usually didn't really exist. Objects were spawned just before
they went on screen, and were destroyed as they went off screen or
were shot down or something. Thus, the game loop only actually had to
deal with the objects that were currently visible, even if there was
a thousand enemies total in the level.
All that said, remember that we're talking about at hundreds of
objects that need to be checked some 30 through 100 times per second.
Unless you're working on a low end handheld device or similar, you
can do a lot of calculations per object before that sums up to a
significant part of the total CPU load.
Solve the problem first, and then benchmark and see if you even need
to think about optimizing (that is, complicating, obfuscating, ...)
anything at all.
//David Olofson - Programmer, Composer, Open Source Advocate
.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
'-- http://www.reologica.se - Rheology instrumentation --'
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: About 2D collision detection
- From: Facundo Dominguez - Inco
- References:
- [gameprogrammer] About 2D collision detection
- From: Facundo Dominguez - Inco
- [gameprogrammer] Re: About 2D collision detection
- From: Alan Wolfe
- [gameprogrammer] Re: About 2D collision detection
- From: Facundo Dominguez - Inco
Other related posts:
- » [gameprogrammer] About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- » [gameprogrammer] Re: About 2D collision detection
- [gameprogrammer] Re: About 2D collision detection
- From: Facundo Dominguez - Inco
- [gameprogrammer] About 2D collision detection
- From: Facundo Dominguez - Inco
- [gameprogrammer] Re: About 2D collision detection
- From: Alan Wolfe
- [gameprogrammer] Re: About 2D collision detection
- From: Facundo Dominguez - Inco