[Solved] Polygon shapes not colliding?

Topics: Developer Forum, User Forum
Jul 22, 2012 at 12:09 PM
Edited Jul 22, 2012 at 12:10 PM

Hiya,

I've been fiddling around with FPE for a few days now, and I've got it working with OpenTK / Mono. The only problem here is, the polygon shapes do not report collisions. I've tested with two circle-shaped bodies and they collide nicely as they are supposed to, but if I have a poly-circle-collision or poly-poly-collision, it won't happen - they just fly through each other. I have already crawled through the source code and tried to tinker with the debugger, but so far I haven't found anything that could relate to this problem... I think I've just missed something basic here. :p

What could cause this? I'm using the latest stable build. 

EDIT:

Forgot to mention, the debugview draws the circle shapes, but not the polygon shapes, which is a bit odd. Maybe this is related to the origin of the problem..?

Jul 22, 2012 at 1:07 PM

Are you talking about DebugViewXNA or you implemented it in OpenTK (btw if you implemented it there please do share :)

Check your polygons for correct winding order (counter-clockwise vertices). Also try a Factory polygon like BodyFactory.CreateRectangle(), CreateEllipse(), CreateCapsule() to see if those work.

If you want to debug/test further, the TestBed project has a lot of tests for various aspects. It would be nice to see them working on Mono. I believe some people are using/trying MonoGame already (seen posts on the forum).

Jul 22, 2012 at 1:48 PM
Edited Jul 22, 2012 at 2:55 PM

About DebugView, I followed the DebugViewXNA loosely and used immediate drawing functions without the primitivebatch class. It's hacky-tacky, but does the trick for now. :p

I've tried the CreateRectangle() and CreateEllipse() factory methods, but they do not work (no collisions, no debug drawing). I've also tried subscribing the OnCollision to see if it's raised, but it's not. With a circle fixture, it is raised, so something funky must be going on here.

EDIT: Made a little proceeding, found out that the vertices delivered for the polygon drawer function are all zero vectors! Now to hunt the reason for this anomaly...

EDIT2: Okay, there was a small bug in the drawer function, now it draws the polygon shapes properly. The collisions are still nowhere to be found.

EDIT3: The capsule collider works too, which (if I assume correctly) is a compound collider. So, there has to be something wrong with the actual polygon stuff.

EDIT4: Oo-okay... Something weird is definitely going on. I created a circle collider with a radius of 10f, and then a rectangle with 2f width and 4f height. When I "fly" around with the rectangle, it sometimes passes the circle, sometimes it collides with it, and sometimes it lets the rectangle to penetrate the circle, then immediately rubberbands the rectangle back. Wtf?

Jul 22, 2012 at 7:51 PM
Edited Jul 22, 2012 at 7:52 PM

At high speeds some interpenetration can be seen because of tunnelling. CCD (continuous collision detection) should be enabled by default for static bodies. For dynamic bodies you should set IsBullet=true manually. You can test to exclude that (make one poly static and see what happens, set IsBullet etc.).

Also I've seen the issues you are describing when I had a wrong transform of the vertices passed to the graphics and the physics. As in the conversion matrices were wrong so the graphics was getting one thing and the physics another. So I rectangle would look and behave like a rectangle but collisions would be weird. I have very little experience with OpenTK but I remember OpenGL had some differences to DirectX with regards to the matrices.

Jul 23, 2012 at 5:26 AM
Edited Jul 23, 2012 at 5:29 AM

Hmm, it might be that there's something wrong with the matrices. I changed FPE to use OpenTK's matrices and vectors instead of XNA's, so maybe there's either a small bug I've presented myself or the matrices are handled differently. I don't think this is caused by tunneling, since the speeds are really small and the objects are "moderately sized". I tried using IsBullet = True on the moving rectangle, but it didn't have any effect whatsoever.

It's a bit weird though that the graphics representation looks correct (2x4 rectangle at origin, 10-radius circle at 0,-15 => rectangle appears over the circle), and if I print out the coordinates of the moving rectangle, the seem to be changing like they should. If I apply for to right, then the X coordinate is incrementing as supposed to.

Jul 24, 2012 at 8:02 AM

Ooookay, I solved the problem! Indeed, the problem was in the way the matrices are handled. OpenGL uses column-ordered matrices while XNA uses row-ordered. The simplest way was to use the Mono.XNA.Matrix for all the FPE-related matrix stuff. Now all the collisions work like a charm :)

By the way, if someone needs help implementing FPE with OpenTK, I will be more than glad to share my knowledge collected in the last few days. :p