2

I am searching for a 2D physics engine to simulate gravity using images, preferably PNG images with transparency. So the engine will know how to calculate the collision base on the opaque parts of the image. I have only found Javascript engines that works with primitive shapes and basic HTML elements, but not with images.

5
  • Isn't <img> a basic html element? Commented Jul 30, 2012 at 17:01
  • 3
    I think he means that transparent sections of an image shouldn't collide. Commented Jul 30, 2012 at 17:02
  • Yes. I will use PNG images with transparency Commented Jul 30, 2012 at 17:03
  • 2
    Use the HTML5 Canvas tag. It's better and faster Commented Jul 30, 2012 at 17:04
  • found this: lib.ivank.net/?p=demos&d=box2D, but I don't think it recognizes the empty areas of the PNG image Commented Jul 30, 2012 at 17:14

2 Answers 2

2

I don't know any way to do what you desire, but you can try drawing your shapes in HTML5 Canvas and use Box2D.js for working with shape collision.

Sign up to request clarification or add additional context in comments.

Comments

1

One think you could do is compute the convex hull of your image (you can have a look here) and then use those hulls to compute collisions and so on (using GJK for example, you can find some great explanations here or here)

As noted by micnic, I guess you can indeed use Box2D.js and feed a b2PolygonShape why the non transparent pixels of your images (or you can compute their contours and use contours as input for the b2PolygonShape)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.