UnderwareDesign
May 20, 2013, 11:56:21 AM *
News: Happy Diver 2 WIP by Sigtrygg (11th,Jan,2013)
   Home    
Pages: [1]
 
Author Topic: Partition (inter object) Shape Collision  (Read 3618 times)
Member
Development Team


WWW
« on: April 02, 2006, 08:00:29 PM »


This example is basically an asteroids frame work.   While it doesn't play a full game of asteroids, it's set up to demonstrate a method of partitioning the games world space to help eliminate unnecessary collision checks.  In this case shape intersections.

 The partitioning in the example is achieved by cutting up the screen is vertical rectangular regions. Each region is 1 partition.  The partition will hold a list of the objects that share this space.   The partition map is just a 2D array.  Where the X coordinate represents the vertical region and the Y coordinate represents the index of the asteroid in this partition list.  To assign an Asteroid into a partition it's index is simply dropped at the end of the list.   element zero is used as each partitions item counter.

  Each update the partition is cleared.  Then the asteroids are remapped into the partition buffer.  To map them,  all were doing is running through the asteroids, calcing it absolute width, then translating that region to the partition buffer.    When collisions require testing, rather than scan all the objects each time, we poll the partition map for a list of objects that are known to be within our test objects region.  This will give us a short  list of asteroids to check against.  

  There's potentially a logic errors (as objects are moving and checking), but all in all it's good enough... Smiley

Recursive_Collision.zip (9.32 KB - downloaded 227 times.)
Logged

Member


« Reply #1 on: April 03, 2006, 05:56:36 AM »

Great Job...

I am very happy that I find something of mine in your sourcecode...  Smiley

I get over 280 FPS...

In the case of nearer analysis of the source code I must state that I must learn still a lot  Sad  (or translate to understand...  Wink )

Big C.
Logged
Member


« Reply #2 on: April 03, 2006, 07:24:09 AM »

You’re a fast worker Kevin Smiley  

I’ll have a good look through this

Thanks  Smiley
Logged
Member


WWW
« Reply #3 on: April 03, 2006, 02:58:39 PM »

I get around 130 FPS.
I think I will modify the code a bit to add yellow and green flashies to the red flashies and then I can finally stop consuming alcohol and other drugs and just watch the demo  Cheesy

The partitioning code is pretty smart. It even covers asteroids spanning more than two partitions.
I think the only "flaw" if I dare to say so is when you check for collisions. Then you only look at asteroids that are less than 50 pixels away. There you could also calculate the interesting asteroids by using the radius of the checked asteroid (YTop = y - radius, YBottom = y + radius) and use those values to find possible collision asteroids.

I read about this partitioning several times in other forums but never understood how such code could work for moving objects and never found an example (some of those game gurus have a bad habit of only "mentioning" their knowledge and forget about explaining) - but now I know  Cheesy

Thanks for this eye and brain opener!

Cheers,
Tommy
Logged

Member
Development Team


WWW
« Reply #4 on: April 06, 2006, 04:02:52 AM »

Quote
I think the only "flaw" if I dare to say so is when you check for collisions. Then you only look at asteroids that are less than 50 pixels away. There you could also calculate the interesting asteroids by using the radius of the checked asteroid (YTop = y - radius, YBottom = y + radius) and use those values to find possible collision asteroids.

  True, but it does that, as it doesn't pass the collision object in, just the shape index.  As there not all asteroids

  Generally, you'd have a 2D partition rather than columns as seen here.  Given that situation i'd probably still use a trivial reject max radius, before falling to the second level of tests.

  However, one thing that is missing from the demo is a way to stop duplicated tests occurring.  Since objects allocated as they move and prior to moving. it's more than likely you'll end up checking the same object more than once.  

  The remarkable trivial solution is use a unique stamp.   If an object is within range to check, and it's stamp is invalid (<> to current stamp) you check. Once checked, you stamp it with the current stamp.   This way even if it's in the partition 10 times, it only ever gets checked once..
Logged

Member


WWW
« Reply #5 on: April 06, 2006, 04:54:17 AM »

Quote
True, but it does that, as it doesn't pass the collision object in, just the shape index.  As there not all asteroids
Yes, I missed that. You're right.
Quote
  The remarkable trivial solution is use a unique stamp.   If an object is within range to check, and it's stamp is invalid (<> to current stamp) you check. Once checked, you stamp it with the current stamp.   This way even if it's in the partition 10 times, it only ever gets checked once..
And if you toggle the stamp between 0 and 1 everytime you reset the partitions you don't even need to reset the stamps inside the objects.
We used that once in our Smalltalk system for the "mark and sweep" Garbage collector code. Works fine  Cheesy

Cheers,
Tommy
Logged

Member

« Reply #6 on: August 27, 2006, 02:54:21 PM »

Hi!
Where can I find this code?

stef
Logged
Member
Development Team


WWW
« Reply #7 on: August 27, 2006, 03:02:26 PM »


 attached to the first post
Logged

Member

« Reply #8 on: August 27, 2006, 03:07:42 PM »

thx Cheesy
Logged
Pages: [1]
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2009, Simple Machines LLC | Privacy Policy Valid XHTML 1.0! Valid CSS!