Collision code
Monkey Forums/Monkey Code/Collision code
| ||
Here's some useful collision code ported from bmax: |
| ||
Nice! Any examples of use? |
| ||
Great thanks! Had started converting myself for some vector stuff but hadn't finished :) |
| ||
therevils, I don't have any examples, but I'm using a circle->polygon collision in my current project if that's any help. No problem dopeyrulz. I just converted this code, and I haven't extensively tested it(circle->poly works for sure), so if you find any problems, let me know! |
| ||
Yahfree, Have a long weekend at parents so will let you know tomorrow (Monday) how it looks. |
| ||
I've done some work around PointInTFormPoly: I read somewhere else the code is not fully processed unless you include some reference to it - ie. only compiles what it needs. I needed to 'box' up the Var references (as outlined here: http://www.monkeycoder.co.nz/Community/posts.php?topic=172 ) |
| ||
Some examples might be absolutely helpful! |
| ||
pinete, This code originally comes from Digesteroids - example game from BlitzMax. |
| ||
Thanks for the post. Same as pinete - if you can include an example that would be good. It'll help fast track the process. |
| ||
Yea a simple example code how to use this please, I don't have BlitzMax so I can't see how to use this. |
| ||
Class TCollision Field x1:Float Field y1:Float Field x2:Float Field y2:Float Field x3:Float Field y3:Float Field x4:Float Field y4:Float Field entity:TEntity Method Init:Void( entityRef:TEntity ) entity = entityRef UpdateBounds() End Method Method UpdateBounds:Void() x1 = -entity.image.handle_x * Pos( entity.scale.sx ) y1 = -entity.image.handle_y * Pos( entity.scale.sy ) x2 = (entity.image.width - entity.image.handle_x) * Pos( entity.scale.sx ) y2 = -entity.image.handle_y * Pos( entity.scale.sy ) x3 = (entity.image.width - entity.image.handle_x) * Pos( entity.scale.sx ) y3 = (entity.image.height - entity.image.handle_y) * Pos( entity.scale.sy ) x4 = -entity.image.handle_x * Pos( entity.scale.sx ) y4 = (entity.image.height - entity.image.handle_y) * Pos( entity.scale.sy ) 'Print x1 ; Print y1 'Print x2 ; Print y2 'Print x3 ; Print y3 'Print x4 ; Print y4 'Print "-------" End Method Method CollidesWithPoint:Bool( px:Float, py:Float ) px = px - entity.position.x py = py - entity.position.y Local tx:Float = px*Cos(-entity.rotation) - py*Sin(-entity.rotation) Local ty:Float = py*Cos(-entity.rotation) + px*Sin(-entity.rotation) If tx > x1 And ty >y1 And tx < x3 And ty < y3 Return True EndIf Return False End Method End As requested from GC-Martijn: The above checks for a point inside a rotated rectangle. I have converted it from BlitzMax and the entity thing should be obvious. Pos(value:Float) just ensures the value is positive. You can leave out entity.scale.sx/sy if your entities are never scaled. Example: Class TEntity Field image:Image Field collision:TCollision Method New() collision = New TCollision image = LoadImage("someimage.png") End End Local entity:TEntity = New TEntity If entity.collision.CollideWithPoint(MouseX(),MouseY()) Print "Collision" End |
| ||
Thanks for sharing ! :) Maybe I can use it inside a collision code I use that can't check Rects at the moment ! |
| ||
Thanks for this post. Came in very handy! |