Using image in Box2D

I just started trying out Box2D and it seems very interesting. I haven't been able to find a lot about it though, at least regarding images. How can I create a shape/object using an image and have the colors match together?. I think I need to create a polygon. I was also wondering if I could change the pivot point to a specific location on the image/shape for it. I am using box2D on processing and I have already downloaded the library for it. Any help would be greatly appreciated!

Tagged:

Answers

  • Hello ! I already told you how to do :

    • find the points located on the border of your shape using this kind of algo http://forum.processing.org/two/discussion/10297/contour-detection#latest

    • simplify it to reduce the amount of points (you want to get a shape with less than 100 points )

    • triangulate your simplifyed-shape

    • inside box 2d, create a group and draw every generated triangles inside it

    • draw your image like usual and use the position / rotation of the box2d body

    There is no easy solution to do what you want.

  • Hi, I'm sorry for bothering you with this. But I read on some places that you could import json files into Box2D. I created an outline using the Physics Body Editor, but I couldn't find any documentation on how to import the JSON file into Box2D to use. Or is that not supported in Processing in box2D?

  • I didn't know about that, but I think it's not available in processing

  • edited May 2015 Answer ✓

    but it's not so hard actually :)

    1) Use the algo I told you.

    2) count the amount of point, divide that number by 100 and you will get a value "myVal"

    3) loop on all the point and increment using "myVal" to be able to get 100 points.

    4) look for the "ear cutting algorithm" , find it or translate it from another language

    5) apply the ear cutting on your points, you will get some triangles used in the same way than an indexBuffer in openGL (with some indexs relative to the vertex)

    6) rebuild your triangle in box2D inside a "group"

    7) that's all

    The true complex thing, to be honnest, is to know what to do. But now you know ! :)

    Since you will not create you own version of a "border-finder" and you will not create the ear cutting by yourself, you have almost nothing to do.

    Just do what I told and it will work.

    I'm sure about that because my version works :D

    http://forum.processing.org/two/discussion/8565/does-box2dprocessing-supports-complex-shape#latest

  • Thank you so much! I'm glad I found the Box2D and I can definately see myself playing with it further down in the future. I do feel ...... annoyed that I spent so long trying to get pixel collision and all, but it was a good experience I guess. Thanks for the help

  • collision detection & collision response is one of the most complex topic you can find, it's complex to use/learn how to use and it needs some time. But the solution with box2D + complex shape is the better / easiest to use if you have not too much objects (hundreds, not thousands) .

    So, don't give up ! :)

  • I've been testing out the joint and revolution, mainly be trying to read and understand the windmill example that was given. Is there a way to change the angle of a box manually. For example, have the box angle change according to an inputed angle/radian as opposed to using the motor. I also can't seem to find any sort of documentation where I can find the specific functions and objects inside Box2D. I don't know if I'm just looking in all the wrong places or something. =X Right now I'm just trying to create a box where I can control the rotation, but stays in place.

  • look at this : http://www.box2dflash.org/docs/

    it's for the flash version but it's approximatly the same thing

  • Thanks! This'll help a lot. Trying to figure out what function I could use with just the examples was difficult.

Sign In or Register to comment.