I want use complex shapes with the 2D physics engina that love2d has, right now I onlu can use simple shapes like a circle or a square. I want to draw something like a hand in an image and when it loads the engine has to detect the shape of the object.
Is this easely achiavable?
How to detect from an image the shape for an physic object?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- ellipticaldoor
- Prole
- Posts: 6
- Joined: Sun May 05, 2013 2:56 pm
Re: How to detect from an image the shape for an physic obje
1. the 2d physics engine that love2d has is called Box2D, it supports polygons so complicated shapes are possible if you find that it isn't enough use love.math.triangulateellipticaldoor wrote:I want use complex shapes with the 2D physics engina that love2d has, right now I onlu can use simple shapes like a circle or a square. I want to draw something like a hand in an image and when it loads the engine has to detect the shape of the object.
Is this easely achiavable?
2. Translating image to a physics shape is quite complicated and the results aren't perfect either, so unless you have 50+ images it is not recommended.
How to go about it:
- get image data from the image.
- make a bit mask of data(iterate through each pixel), matrix with 1 as transparent and 0 as colored:
[1,1,1]
[1,0,1]
[1,1,1]
- produce shapes out of this(most likely polygons and hence use triangulation) and attach it to a body.
- circles are a whole different story.
Note:
If you are planing to use this for the main character or NPC's please consider making shapes manually as it is way easier and produces better results.
Re: How to detect from an image the shape for an physic obje
This is the complicated step, by the way. You can use the Marching Squares Algorithm for that. Note that you should simplify (remove points that area (nearly) on a line between two other points) your shape before triangulating it with love.math.triangulate.- produce shapes out of this(most likely polygons and hence use triangulation) and attach it to a body.
In any case, it is probably faster to draw the shapes manually (for example with Inkscape) than to write the code that extracts them from the image.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: How to detect from an image the shape for an physic obje
This is what I have used in the past if you are on windows than it will have an executable for you if you are on linux i think it runs in wine. All you will have to do is make a export template for love. https://www.codeandweb.com/physicseditor
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests