Is nPoly any good?

Blitz3D Forums/Blitz3D Programming/Is nPoly any good?

HappyCat(Posted 2005) [#1]
Just wondering if anyone knows if GoSsE Korupted's nPoly routines (http://www.blitzbasic.com/Community/posts.php?topic=36003) are sound.

I've started using them for collision detection in my 2D (in 3D) shooter and most of the time it's okay, but occasionally shots will pass right through enemies.

The first thing I thought was that the shots were passing over the enemies (moving so far in a frame that they never actually touched the enemy) but debugging has proved this not to be the case (when it happens shots are moving no more than 16 pixels in a frame and the enemy is 45 pixels wide, plus shots can pass within 10 pixels on the sprite's handle and nPoly doesn't trigger a collision).

I can't get my head around the maths in the nPoly routines (I'm not a maths person at all) so I'm wondering if anyone else has used them or understands them and could let me know if they're sound or not.


Sweenie(Posted 2005) [#2]
Don't know if it's the cause to your problems, but I spotted a little typo in the poly2poly test...

This line...
ty4 = Y2 + nPoly2\iMaxX

should be
ty4 = Y2 + nPoly2\iMaxY (Note the Y at the end)


HappyCat(Posted 2005) [#3]
Actually I've tried poly to poly (nP_PolyOverlap) and poly 2 circle (nP_PolyOverlapsCircle) as well as having bCheckBounding (which is where that line is) on and off. All exhibit the same thing, so I think it's probably something quite fundamental.

Edit: but I'll try that fix at lunchtime anyway :-)


HappyCat(Posted 2005) [#4]
A bit more testing (using circular shots and nP_PolyOverlapsCircle) shows that the bounding check reckons that the circle and bounds are overlapping.

At that point the two are 14.1 pixels apart, well within the enemy (which is basically a rotating 45x45 square with some extrusions, and yes I'm rotating the polygon and it lines up quite nicely with the quad sprite if I draw the polygon using nP_DrawPoly).

But the next check (the actually poly check and the bit I don't understand) doesn't trigger.


HappyCat(Posted 2005) [#5]
Damn, just had a thought when playing with the nPoly demo. It checks if the circle is touching the polygon outline. My shot must be going from outside the polygon, to fully inside, to fully outside in three frames. Dang!

Anyone know how I could implement a "is this circle touching or inside this poly" function using the nPoly Types? Or is that just too much work and I should stick to just checking radius' of sprites?