Skip to main content
GameDev.net gamedev.net
🔒 Locked

Collision

Started by Wyrframe Jun 29, 2000 at 3:02 AM 5 replies 350+ views
Original Post
Wyrframe
Wyrframe
Collision in 2D, 3D, or what? I can''t even try to help without knowing what you want...
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
bintangku
bintangku
i mean both..but the primary one is 2D if you can
Julio
Julio
There are many methods. for 2d.
bounding box-pretty easy
pixel perfect-not as easy more time consuming

3d:
bounding sphere - not too tough
bounding box with rotation -waste of time

JoeMont001@aol.com
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
bintangku
bintangku
ok...now I want to know the 2D method first....can you give me the URL that I can refered with....??

thanks
Jrz
Jrz
First you check the if the bounding boxes collide, this is pretty easy
if one collides, then you''ll need to:
check the collided section for collided pixels

+------+
/ /
/ +----+
+----/ /
/ /
+----+



2 boxen, there''s only a small part that collides
now just loop for every pixel until it''s a hit
win32mfc
win32mfc
Hiya.. For 2D collision detection, you might want to try what was previously suggested by Jrz. Here''s how I might go about it, though.

First, Images you draw to the screen have a bounding rectangle. Like Jrz said, you first check to see if the rectangle overlaps any other rectangles. This is a very simple test. If they don''t overlap, then you''re done-- no collision. If it does overlap with another image, then you do a pixel-level test.

Secondly, to speed things up and give a little more flexability, I would create new "mask" images that are monochrome. They take up little space since each pixel is represented by a single bit. If a bit is 0 then nothing is there, if it''s 1 then something is there. Sort of like a silhouette. When you do the secondary "pixel-level" collision detection, use these images instead of your actual display images. You''ll have to create a special routine [which can be highly optimized] to quickly determine if any bits collide/overlap. Using a BMP structure for a mono bitmap [an array of scanlines, each scanline an integral number of DWORDS] you can create an optimized routine that can scan a lot faster [up to 32 pixels at a time on the interior of an image.]

That''s how I would go about it. If involves an extra step to create the mask/silhouette images, but they can be generated relatively easily.

Perhaps there are some game libraries which already have these routines implemented; I don''t know. As I understand, it''s a fairly common & well-known trick for pixel-perfect collision detection that''s faster than directly checking collisions on 8-, 16-, or 32-bit game images.

Cheers!
// CHRIS

// CHRIS [win32mfc]
Jrz
Jrz
When your map gets really large, you might want to use a quadtree like thing before the other 2

you split up you map in sectors:

+-----+-----+-----+-----+-----+-----+-----+
/ / / / / / / /
/ / / / / / / /
+-----+-----+-----+-----+-----+-----+-----+
/ / / / / / C / /
/ B / / / / / D / /
+-----+-----+-----+-----+-----+-----+-----+
/ / / / / / / /
/ / / / A / / / /
+-----+-----+-----+-----+-----+-----+-----+
/ / / / / / / /
/ / / / / / / /
+-----+-----+-----+-----+-----+-----+-----+


Now, if you want to test collision, and there are ALOT of objects, you could first check if 2 objects are in the same sector(s)

B and A could never collide, but C and D could.
so you''ll only have to test bounding boxes for CD, and if those collide, do a perpixel comparison

have fun

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.