Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 A quick way to detect polygon collision...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masterbooda
Swordmaster

277 Posts

Posted - May 15 2004 :  01:09:03 AM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Ok......... real simple.........can anybody help me with this...
I have two 4 sided polygons, all I need to know is of a method or the math needed to detect if they are overlapping...

I was using gdi32 calls for this, and even after fixing the memory leak issues........it was still to slow........I have looked high and low for articles on this and everyone is using the gdi calls and the math tutorials where well above this uneducated man's head........

Could somebody point me to something........or explain the math in layman(i'm a blithering idiot) language....... The closest article I found was on line intersection......and it doesn't work in all instances.....

Any help would be appreciated..... and I will remain calm and civil....

DaBooda out.....

DaBooda Team is back: http://dabooda.789mb.com/

VBBR
Moderator

Brazil
617 Posts

Posted - May 15 2004 :  06:01:25 AM  Show Profile  Reply with Quote
Try this article from DirectX4VB, it's for collisions in 3D but I think it can be adapter to 2D easily.


Whatever. Who knows...
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - May 15 2004 :  2:55:32 PM  Show Profile  Reply with Quote
The math isn't difficult at all, it's just a compound If statement -

  
If rect1.top >= rect2.bottom And rect1.bottom <= rect2.top And _  
rect1.left <= rect2.right And rect1.right >= rect2.left Then
  
'Code
  
End If
  


I think that works... And it is pretty fast as well (faster than gdi calls, anyway)

Edited by - Sr. Guapo on May 15 2004 3:06:51 PM
Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - May 15 2004 :  11:03:13 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Yeah that works for rectangles, but I have irregular polygons....... I was needing an actual algorithm to detect the intersection of these two.... I have been using line intersection, but it is slow and even if all I detect is just whether or not the lines intersect..... still slow......

I then switched over to using very simple circle collision... which is just one line of code..... still pretty slow..... but of course my processer is slower than my grandmother on a rainy day...

And circular collision isn't very accurate...... I was hoping to find a better algorithm... I could take this and write it in c++ and use it that way... but I'm pulling my hair out finding something...

I need something that covers all bases, that way there is no error...... Its for my dabooda2dturbo engine.....

DaBooda out...

DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - May 15 2004 :  11:11:29 PM  Show Profile  Reply with Quote
There are all sorts of different shortcut collision detection methods. Circles are the easy, but don't usually fit well. Same with rectangles. There ae even ways to use ellipses (rather than circles), if those fit better, though I don't know how. It probably involves some complex math, however.
Go to Top of Page

Brykovian
Bryk the Cheese Slayer!

USA
58 Posts

Posted - May 16 2004 :  12:18:54 AM  Show Profile  Visit Brykovian's Homepage  Click to see Brykovian's MSN Messenger address  Reply with Quote
Are you aware of these: http://voodoovb.talosstudios.com/tutorialscollision.html

The Circles method actually allows for multiple circles per object ... and the "irregularly shaped" method is using line intersection (which you're already trying) ... but maybe these will give you other ideas to try.

-Bryk

www.mwgames.com
Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - May 16 2004 :  06:59:04 AM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Thanks, those really helped....... I figured out how to cut the math in half, by not squaring the result...... thanks again..

DaBooda out...


DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

Chris
Neophyte

Australia
1 Posts

Posted - Jul 01 2004 :  03:17:59 AM  Show Profile  Reply with Quote
Hi, DaBooda.
I'm not too sure what you intend to do, but if you're looking for Pixel Perfect Collision Detect in DirectDraw, VB, then here's a tutorial i'd like to refer you to: http://rookscape.com/vbgaming/tutAS.php.
This only works for 8-Bit, but in the message board there is a way of fixing it for 16-bit. For any more help, email me on: drewboy_notyou@hotmail.com. Good luck!
Chris
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jul 02 2004 :  4:43:08 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
Hi

hmmmmm ,, divide on polygon into 2 traingles

then find if any point of the other polygon is lies on any of the 2 traingles

this means you have to test point in traingle 16 times

and here is a code of point in traingle

Download Attachment: triangle.zip
3.89 KB

regards

Edited by - game_maker on Jul 03 2004 03:36:54 AM
Go to Top of Page

Sion
Warrior

Denmark
138 Posts

Posted - Jul 03 2004 :  06:33:36 AM  Show Profile  Visit Sion's Homepage  Click to see Sion's MSN Messenger address  Reply with Quote
There is a very informative tutorial on how to calculate polygon collisions. The code is in C++ but ideas should be relatively clear, however it may be a bit too advanced for what you're asking for, but try and take a look. It's found here http://www.gamedev.net/community/forums/topic.asp?topic_id=251638

Visit my personal blog at www.AndersNissen.com!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.