Archived

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

ColdFlame

Collision Detection

Recommended Posts

I am designing a 2D sprite based engine with particle effects ''n'' stuff. My current problem however is collision detection. I have a basic RECT based system, but I need something more accurate. I plan to define a seris of points arround each sprite and then draw a line between the sprites centers. Then, if the line crosses the sprite it started from, they do not intersect, if it crosses the other they intersect. Perhaps a diagram will help: __________ / /Edge of Sprite 1 | . / | \ / |_____\/ \Line between centers, not drawn very well ________\__ | \ |Edge of Sprite 2 | | | | ----------- Do you see what I mean with this? However, I have no idea how to draw the line and see which sprite it intersects first. Can anyone help? ColdFlame Oh well, Whatever, Nevermind

Share this post


Link to post
Share on other sites
Are you going for pixel-based collision detection without checking all the pixels? pixel-approximate collision detection, i guess?

one method may be to outline each sprite with x number of points to form a closed polygon. then test each segment for intersection with the other object''s segments. this is costly to do every time with many objects at once, but if you couple this by first using a quick bounding sphere/box check, you might get good results.

Share this post


Link to post
Share on other sites
Yeah, that''s what I was trying to describe. My plan to make it fast was to draw a line between the centers of the two polygons.
I then need some way of testing which polygon the line intersects.
Try drawing this on paper with intersecting and non-intersecting polygons and you''ll see what I mean.
However, i need the code for the line and polygon intersection.

Share this post


Link to post
Share on other sites
narfidoo asked a similar question in the Lounge Forum a week ago. I wrote him a reply which turned into a thesis of 9kB.
Anyway, my 2D engine uses polygons and circles and detects collisions and resolves them with the laws of physics. If you''d like the info what I sent to narfidoo or my shape class with all the algorithms with it (C++) you can email me (theloves@chariot.net.au)

Share this post


Link to post
Share on other sites