2d Polygon collision Module

Community Forums/Showcase/2d Polygon collision Module

TartanTangerine (was Indiepath)(Posted 2005) [#1]
This is a Polygon Collision module that uses code written by Gosse Corrupted (ported from Blitz to BlitzMax)

Unzip the attached files to your "BlitzMax Directory\mod\"

There is a demo in the zip file.

http://www.indiepath.com/tim/indiepath.mod.zip


flying willy(Posted 2005) [#2]
you know, I really need line collision as I am doing a platform game, so this will be a great help I think.

However I placed the mod in blitzmax\mods and tried the demo but it wouldn't work


TartanTangerine (was Indiepath)(Posted 2005) [#3]
Skunk, What error is BMAx giving you?


Spot-Nothing(Posted 2005) [#4]
i have an error, too:

[ERROR]: Compile Error:Can't find interface for module 'indiepath.poly'

(using protean for blitzmax)


TartanTangerine (was Indiepath)(Posted 2005) [#5]
Does your path look something like this?

Blitzmax\mod\indiepath.mod\poly.mod


TartanTangerine (was Indiepath)(Posted 2005) [#6]
I've uploaded a new file which might work :)


Spot-Nothing(Posted 2005) [#7]
sniff, still the same error. i double checked the paths etc. but it didn't help...


TartanTangerine (was Indiepath)(Posted 2005) [#8]
I am now confused. I can only replecate your error if I move the files elsewhere.

Have you had any problems with other Modules?


Extron(Posted 2005) [#9]
Simply put the directory "indiepath.mod" in the mod folder of Bmax.

Nice work! ;)


TartanTangerine (was Indiepath)(Posted 2005) [#10]
Yeah, someone got it working.. and they did exactly what I originally said ?!?!


fredborg(Posted 2005) [#11]
I get this error:
[ERROR]: Unhandled Exception: Unhandled Memory Exception Error
[ERROR]: Poly_AddVertex [C:\BlitzMaxBeta101\mod\indiepath.mod\poly.mod/poly.bmx;56;19]
[ERROR]: testpoly [e:\programmer\blitzmax\mod\indiepath.mod/testpoly.bmx;11;1]
It compiles fine, but the example crashes.


TartanTangerine (was Indiepath)(Posted 2005) [#12]
Ouch, that looks to me like a problem with types. But why does it run okay for me, Extron and others that have tested it for me.???

Source is now posted in the zip file, perhaps someone can work out the problem and let me know.


Extron(Posted 2005) [#13]
Well, i clarify my previous post. :)

Simply put the directory "indiepath.mod" in the mod folder of Bmax and compile run "testpoly.bmx" in this folder ("indiepath.mod").

Is this work?


fredborg(Posted 2005) [#14]
Rebuilding the module did the trick. Don't know why it didn't work before.


Extron(Posted 2005) [#15]
Yes, i've don't mention this. :)


TartanTangerine (was Indiepath)(Posted 2005) [#16]
Very odd, perhaps that is why we are still in Beta. :)


Extron(Posted 2005) [#17]
Also. :)


Hotcakes(Posted 2005) [#18]
Rebuilding the module did the trick. Don't know why it didn't work before.

Perhaps you compiled the module in debug mode but the example code in release mode or vice versa?


Diordna(Posted 2005) [#19]
Here is the error I get:

Compiling:testpoly.bmx
Linking:testpoly.debug
ld: archive: /Users/stephen/Applications/Development/Languages/BlitzMax/BlitzMax024/mod/indiepath.mod/poly.mod/poly.d.a has no table of contents, add one with ranlib(1) (can't load from it)
Build Error: Failed to link /Users/stephen/Applications/Development/Languages/BlitzMax/BlitzMax024/testpoly.debug.app/Contents/MacOS/testpoly.debug

Will try "build modules."


Diordna(Posted 2005) [#20]
Building modules fixed it. Duh. Works wonderfully. Actually, I had already implemented most of that code myself but never released it :) Or, more accurately, I implemented a point-line distance algorithm that makes collision detection dead easy. Will post in the future, but I don't want to spend my time writing mods, I want to spend my time writing games.


Tibit(Posted 2005) [#21]
I improved the code a little (atleast to my liking) I made methods out of the functions. Which made the implentation much more trival (easier).
Ex instead of :

ship:dPoly = dPoly.Create()
dPoly.Poly_AddVertex(ship,0,-5)
dPoly.Poly_Resize(ship,10,10)
ship1:dPoly = dPoly.Poly_Copy(ship)

You would Do:
Ship:Polygon = Polygon.Create()
Ship.AddVertex(0,-5)
Ship.Resize(10,10)
Ship2:Polygon = Ship.Copy()

It helps me to speed up the coding =)

I also added a example line infront of each function

And I made a new example to test the Polygon-Type. Even thou I do not use it as a module here below just un-comment the import part and make sure you name everything correctly and it should still work as a stand alone module.



There isn't someone who would know how to implend collision for points/rects/ovals versus Polygons?


TartanTangerine (was Indiepath)(Posted 2005) [#22]
Hi wave,

I've done some improvements at this end also. I've implemented a point in poly detection mode as well as included polygon Collision hulls for detection. And to make it easier I've also coded a polygon editor tool to make your own polys and design the collision hull.

I will post as soon after I release the game I am using it for. aHem, When Win32 Bmax is in release more to the point.

Oh and nice use of the Methods, the code I posted was my first use of BMAX, thanks for the tips :)


Tibit(Posted 2005) [#23]
Cool! I'm going to use poly-collision for the maps in my game. The plan so far is to use a nice background image of a arena/map and then I'm to use polygons to plot the impasseble terrain and walls from that image. It that way I hope to mix speed with color. A polygon editor would be super!

I just have to ask, What is Collision Hulls? It seems really cool but I have no real idea of what it is or what it does. =) (polygons which are joined?)

Perhaps we should meld our versions, it's public domain anyway =) , What do you think?


TartanTangerine (was Indiepath)(Posted 2005) [#24]
Hi Wave,

In the game I am developing the polygons are very complex and the collision algo in the code above would be erroneous. A collision hull is a simple polygonal representation of the complex poly. I use the Hull to check for collisions which is much faster as it has fewer points to check and is a true convex polygon.

Here is a screenie of an early version of the editor to demonstrate. The Blue Lines are the collision hull.




smilertoo(Posted 2005) [#25]
does this only work if the user can compile it?


TartanTangerine (was Indiepath)(Posted 2005) [#26]
@John, I don't understand the question. This is blitzmax and it's already compiled into a module


Haramanai(Posted 2005) [#27]
As I see this up...
Looks like the Overlap function don't work as it suposed to work couse if one of the polies it's biger and fits the other without any of their sides intersect nothing happen. After all looks good.


TartanTangerine (was Indiepath)(Posted 2005) [#28]
It's an old library now and does not do point inside poly checks, the new version does but that's not for public consumption - sorry.


smilertoo(Posted 2005) [#29]
doesnt work for me, i get the same error as the first post


TartanTangerine (was Indiepath)(Posted 2005) [#30]
The source is in the .exe just use it as an include.