SAT for Monkey
Monkey Forums/User Modules/SAT for Monkey
| ||
Hello everyone, I want to share with you this module I just released which is based on SAT.js, a library I've been using for a while. I wanted to have a cross-platform solution for this and I didn't want to depend on a engine to handle my collisions. It's still a work in progress but I think this version is pretty stable. Here is the link for the repo: https://github.com/ilovepixel/sat-monkey Here are some examples of how to use it: Circle to Circle test Result Circle to Polygon test Result Polygon to Polygon test Result Cheers, Felipe |
| ||
Nice! |
| ||
Yes, this looks very nice! |
| ||
Thanks! I've added a new demo It can be viewed here: http://dev.shin.cl/sat-monkey/demo/ I am also working on building a quadtree module that could be used with this module. |
| ||
nice job. even though monkey box2d is excellent, i think this community needs a good collision module when you don't need all the extras. i'll be interested in seeing the benchmarks. |
| ||
Hmmm...? All your demos just appear to me as a black screen in Firefox :( Ran it on Chrome... whoa! Very nice!! Downloading it now :) |
| ||
@SLotman In what version of firefox did you test the demos? |
| ||
Crumbs, that's impressive stuff! |
| ||
@ilovepixel: Firefox 27.0.1 |
| ||
@ilovepixel: Firefox 27.0.1 27.0.1 is what i have and worked ok here. |
| ||
FF worked OK for me too? Nice work Felipe, well done! |
| ||
Thanks! As I mentioned before I started working on a quadtree module that could go along with the SAT module. Here is what I got so far. Sadly is not performant enough to be released but it's working as expected. Now comes the optimization! http://dev.shin.cl/sat-monkey/quadtree/ Cheers |
| ||
Again, very nice work, this should make much larger amounts of bodies to co-exist in the play-field without it killing the frame-rate. A feature that SAT.js does not provide IIRC? |
| ||
@Sammy Yes this would help a lot. The current SAT.js implementation doesn't have this and I've also added getting the bounding box of polygons and circles which helps a bit with the quad tree implementation. I don't want to force the use of this so it will be kept inside the module directory but it will be up to the developer to use it or not. Here is a more evident comparison of the use of quadtrees with the sat module: http://dev.shin.cl/sat-monkey/quadtree/compare/ Just press space to turn on and off the quadtree. I think I am almost done with it, so I could be able tu push it to the repo very soon. |
| ||
Update! I've added the QuadTree implementation to the SAT module. You can compare performance between using it and not in this link: http://dev.shin.cl/sat-monkey/quadtree/compare/ The source for this example can be found on the example folder. Cheers, Felipe |
| ||
The QuadTree is making a big difference to the processing speed, 30-40% quicker with the QuadTree on on my setup. Well done again, Felipe! :) |
| ||
That's really chuffin cool :) |
| ||
ilovepixel: If you don't mind, I'm wondering what you would suggest as the most elegant way is to manage interactions between objects. I've got a class TActiveObject which all in game items extend. These items have a Polygon field and I'd like to use a Quadtree to check for overlaps and then have the objects response based on the object types using a method ReactToObject(ob:TActiveObject) (e.g. Bullet is overlapping Enemy, destroy Bullet, reduce enemy health by 1) Quadtree code I'd like to use Local t:Polygon For Local i:Int = 0 To pool.Length() - 1 t = pool.Get(i) quadTree.Insert(t) returnObjects = quadTree.Retrieve(t) For Local j:Int = 0 To returnObjects.Length() - 1 p = Polygon(returnObjects.Get(j)) If (t <> p And SAT.TestPolygonPolygon(t, p, response)) If (p <> poly1) p.position.Add(response.overlapV) If (t <> poly1) t.position.Sub(response.overlapV) Endif response.Clear() Next t.DebugDraw() response.Clear() Next I hope that makes some sense! :) Ta -Chris Example of TActiveObject class Class TActiveObject Method ReactToObject:Void(ob:TActiveObject) Select ob.type Case OB_COIN ReactToCoin(Coin(ob)) Case OB_BULLET ReactToBullet(Bullet(ob)) End End End |
| ||
What you could do is implementing iSAT into TActiveObject That would make it look like: Then what you can do in pseudo - code is something like this: I hope this helps :) Cheers, Felipe |
| ||
That more than helps, thank you very much :) |