vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
402 stars 48 forks source link

Change shape size (polygon points) #15

Closed benui-dev closed 12 years ago

benui-dev commented 12 years ago

My game requires that I change the size of objects, and thus their collision shapes. I could remove the shape and re-add, but that seems like kind of an inefficient way to do it. Could you add a function to allow the modification the position of polygon points of an existing Shape, and for the HC spatial hash to be updated accordingly?

dannyfritz commented 12 years ago

Have you tried this on the shape yet? https://github.com/vrld/HardonCollider/blob/master/polygon.lua#L124

Oh never mind, I see the next line makes them immutable.

benui-dev commented 12 years ago

I'm never sure whether I should be messing around with stuff within Lua objects. But I guess because it's vertices and not _vertices that should be ok.

But as you said it's immutable.

vrld commented 12 years ago

shape:scale() would indeed be very convenient. I'll add in in the next days.

As for polygon.vertices: It is possible to modify the existing vertices, only adding new ones is prohibited. You have to be careful with that though: The winding should not be changed.

vrld commented 12 years ago

Not yet documented, but shape:scale(s) scales your shape. s must be a number greater than 0. You can also scale polygons using polygon:scale(s, cx,cy) that scales s wrt the point cx,cy, where s can be any number and cx,cy are optional.