nPoly: 2D Polygonal Collision Library

Community Forums/Showcase/nPoly: 2D Polygonal Collision Library

gosse(Posted 2004) [#1]
nPoly is a 2D polygonal collision library for Blitz.

nPoly is a set of functions for Blitz to handle 2D polygonal collision. It is quite fast and is very useful for 2D games that need fast, accurate collision. It is not as precise as pixel-perfect, but is a lot faster! It can be used to check the collision between the character and the level, or between objects in a game, or various other things. Check the demos to see it in action!

Features:
You define your polygon’s vertices one by one
You can have up to any number of vertices (constant dependant, that you can change)
You can have unlimited number of polygons
Polygon versus polygon collision check
Polygon versus circle collision check
Circle versus circle collision check
Draw the collision primitives
Scale and rotate polygons freely
Bounding box check for even more speed

Website:
http://gosse.proboards19.com/index.cgi?board=npoly&action=display&num=1089359071
Download it (616KB):
http://www.nuloen.com/nPoly.zip


Rob(Posted 2004) [#2]
where were you when I needed you? :>
Thats very impressive work!


Binary_Moon(Posted 2004) [#3]
That;s nice. I would like some method for looping through collisions and recieving the normals. The reason for this is jumping. Basically I want to know if the player has landed on a surface or not. I could do jumping based on wether the player is colliding or not but then they would be able to jump no matter what they collide with (cieling, wall, other player etc)

It is incredibly cool though and I can think of a couple of uses for it that don't involve normals so I may use it in the future :)

Thanks for your contribution - much appreciated


aCiD2(Posted 2004) [#4]
The 2Din3D Master pops out again ey GoSsE? ;) Well done!!!


gosse(Posted 2004) [#5]
BloodLocust:
Hehe thanks a lot!

Binary_Moon:
Woah, hadn't thought of collision normals!!
This is a MUST have feature, I'll be implementing it for the next release! Thanks a lot for the idea!

aCiD2:
Hehe thanks buddy ;)


How should it return normals? How about a new 2DVector object with functions to get the x and y components? And should it return it normalized or not?

vect = nP_PolyOverlap(...)
if vect then ; its not 0, so there is a vector and it collided
nP_Normalize(vect) ; if its not normalized
x = nP_GetX(vect)
y = nP_GetY(vect)
nP_FreeVector(vect)
end if



Don't know when will the next release be tho ;)


jfk EO-11110(Posted 2004) [#6]
would this be useful for a game that is using sprites or quads to simulate 2D in 3D?


Binary_Moon(Posted 2004) [#7]
Gosse - cheers :)

I'd do...

vect = nP_PolyOverlap(...)
if vect then ; its not 0, so there is a vector and it collided
   x = nP_GetNX(vect)
   y = nP_GetNY(vect)
end if 


I ditched the normalize. That could be built into the np_GetNX and np_GetNY commands. I would also have a global temp vector (np_VectTemp?) that could be used for all commands like this. That way you don't have to keep creating and freeing types. The value returned from nP_PolyOverlap would then just be True/ False.

Of course you should do it how you think best... but I like to keep everything as clean and simple as possile so that's what I would do.


gosse(Posted 2004) [#8]
I was also thinking about doing it by simply returning the normal angle, since it's 2D, you'll have everything you need with it. And some commands to retrieve the normalized X and Y from the angle. This way though, I think I would have to make a different function, since if the collision normal is 0deg, it would return 0, which would be false :/
Unless I always add 360 degrees to the angle. And return 0 when something doesn't collide.


Binary_Moon(Posted 2004) [#9]
That would then work in the same way as I mentioned above. So as far as I'm concerned that's fine. As long as it's easy and clean (and fast) I don't care how it actually works :)


Perturbatio(Posted 2004) [#10]
This is looking good, much better than my attempt :)