I am new to Box2d using with COcos2d IOS and started making different simple bodies and now I am having problem with getting the vertices of some shapes(i.e mySprite.png) like irregular shapes that are not convex. How can I convert those shapes to convex so that their body collision work accurately ??
Should I have to break those Concave Shapes into smaller Convex parts which is kind of hectic task is their any easy way or some Algorithm for this.
Please also provide helping material links
I shall be very thankfull for you help and concern.
Regards
Abi..
If you are working with flash this class is good solution: http://www.emanueleferonato.com/2011/09/12/create-non-convex-complex-shapes-with-box2d/
I'm working with box2dWeb and I couldn't find better solution than to break Concave shape into smaller Convex parts, and then to connect all them with "Weld joint".
The free tool which helped me a lot with this, is "box2d-editor" : http://code.google.com/p/box2d-editor/
Related
I'm using a game physics library (Box2D) which only supports convex polygon shapes. However, I'd like the level builder to be able to just specify concave polygons without having to worry about that.
So, how can I automatically break apart a concave polygon into convex ones (or even all triangles).
Speed would be cool, but ease of implementation is more important. The breaking apart will only be done on game initialization.
(My language is Flash/ActionScript 3, but that shouldn't matter)
Bernard Chazelle and David P. Dobkin presented an algorithm for that in 1985: Optimal Convex Decompositions.
Other approaches can be found on Wikipedia.
you probabaly need triangulation
This page explains how to convert polygons into non-complex shapes using ActionScript 3. The code is large so I wont copy paste here.
http://www.emanueleferonato.com/2011/09/12/create-non-convex-complex-shapes-with-box2d/
I'm still trying to density control (grade) meshes in CGAL. Specifically tet-meshing a polygon surface (or multiple surface manifolds) that I simply load as OFF files. I can also load lists of selected faces or face nodes too.
But I can't seem to get to first base on this with the polygon tet-mesher. All I want to do is assign and enforce a mesh density/size at selected faces in the OFF file.
I CAN get some kinds of mesh density working by inserting 1-D features with volumetric data meshing, but for CAD and 3D printing purposes it has to be computed from an STL-like triangular surface manifold, so volume-based meshing is not do-able.
Is what I'm trying to do even possible in CGAL? It feels to me like it must be, and I'm just missing something obvious.
I really hope someone can help here. FYI i'm mostly working with the Mesh3 example using v4.14.
Thanks very much.
Look at the Mesh_facet_criteria and in particular this constructor where SizingField is where you can control the size. For locating the point wrt a face, you can use the AABB-tree function closest_point_and_primitive().
Im trying to write a game in 2D with Sfml. For that game i need a Lightengine and some code that can give me the area of the world that is visible to the player. AS both problems fit very well together (are pratically the same) i would like to solve both problems at once.
My world will be loaded from files in which the hitboxes of objects will be represented as Polygons.
I now wrote some code that takes a list of Polygons and the Direction of a Ray that follows the mouse and finds the closest intersection with any of these polygons.
The next step now would be to cast rays from the players or lights Position towards the edges of the polygons, aswell rays offset by +-0.000001 radians to determine the visible area and give it back as a polygon.
The Problem though is that my algorithm (it calculates the inersection between two lines with vector mathematics) is too slow.
In my very good PC i get 100fps with 300 egdes and one Ray.
I now read many articles online but couldnt find one best solution. But as far as i read it should be much faster to calculate intersections with triangles.
My question now: would it be meaningly faster to triangulate the polygons once while loading the map and then use ray-triangle intersection or is there any better way that you know of to solve my problem?
I also heard of bounding Volumen hierachies but i dont know howmuch impact that would have.
Im a bit surprised of how much power my algorithm consumes, as it only has to calculate some 2 dimensional intersections...
For everyone looking for the solution I finally went with:
I discovered the Box2D Physics Engine and I am now using the b2World::RayCast(...) function to determine whether and where a ray hits an object in my scene.
For now everything works fine and smooth (did no exact benchmark yet) :)
http://www.iforce2d.net/b2dtut/world-querying
I got it to work with the help of this site
Have a nice Day! :)
I came across an application called PhysicsEditor and it traces images and results in vertices that make up the shape. I'm interested in implementing something that would do this but I'm not sure what type of algorithm can do this.
You get all of the points that make up the image (you might need to do this with edge detection or some kind of PCA if you're dealing with bitmaps)
Then you compute a convex hull : http://en.wikipedia.org/wiki/Convex_hull
Hey so i was told in a previous answer that to make concave shapes out of multiple convex ones i do the following:
If you don't have a convex hull, perform a package wrapping algorithm
to get a convex border that encompasses all your points (again quite
fast). en.wikipedia.org/wiki/Gift_wrapping_algorithm
Choose a point that is on the boarder as a starter point for the algorithm.
Now, itterate through the following points that are on your shape,
but aren't on the convex border.
When one is found, create a new shape with the vertices from
the starter point to the found non-border point.
Finally set the starter point to be the the found off-border point
Recursion is now your friend: do the exact same process on each new
sub-shape you make.
I'm confused on one thing though. What do you do when two vertices in a row are off-border? After reaching the first one you connect the starter point to it, but then you immediatly run into another off-border point after you start itterating again, leaving you with only 2 vertices to work with: the starter point and new off-border point. What am i missing?
To illustrate my problem, here's a shape pertaining to this issue: It would be great if someone could draw all over it and walk through the steps of the algorithm using this. And using point 1 as the starting point.
Thanks!
Assuming you really want to take a convex polygon (as you've illustrated) and decompose it into convex parts without introducing new vertices, the usual approach is called "ear clipping" and is described in this Wikipedia article, Polygon triangulation. In this approach the convex pieces are triangles, which are necessarily convex.
This problem has been discussed in connection with the CGAL computational geometry software here in Stackoverflow, C++ 2D tessellation library.