Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Box2D: How does b2setbodyimage work?

Author
Message
DrT
18
Years of Service
User Offline
Joined: 10th May 2008
Location: 26.78 degrees North, -70.49 degrees West
Posted: 21st Jul 2010 23:59
I understand the coordinate systems for b2createbody and b2createshape. b2createbody creates a point mass at specified coordinates relative to the screen. b2createcircleshape creates a circle at specified coordinates relative to the coordinates used for b2createbody.

How does b2setbodyimage work? Take the pinball tutorial that comes with Box2D and look at the creation of the flipper. In paint, the pivot point for the flipper is at 89.5, 14.5. How does b2setbodyimage know to put this point at the location of the point mass for the body?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Jul 2010 01:30 Edited at: 22nd Jul 2010 01:32
The image is always centred on the body it is attached to (ie. the centre of the image is always at position 0,0 in body coordinates). If you open the flipper image you will see that one half is transparent, making the centre of the image the same as the pivot point.

This is not necessary, I could have simply altered the positions of the vertices so that they fit the image, but for a tutorial it seemed like the simplest way.

Btw, I'm just being pedantic, but b2CreateBody doesn't create a point mass as such, it just creates an empty body with no mass. Mass is added when you attach shapes to the body using fixtures.

However, if the body is used in the simulation when its total mass is zero, it is given a mass of one (better than breaking the simulation IMO).

[b]
DrT
18
Years of Service
User Offline
Joined: 10th May 2008
Location: 26.78 degrees North, -70.49 degrees West
Posted: 22nd Jul 2010 01:49
Thanks for responding so quickly to my question. I see it now.

Login to post a reply

Server time is: 2026-07-25 05:32:38
Your offset time is: 2026-07-25 05:32:38