pixels per meter defaults to 30. <edit>is 30 in test bed examples, no default is set in core code</edit>
concept of change
firstly an idea that can be applied as is.
multiplying is faster than dividing.
so storing var inversePxMeter:Number = 1/30; and multiplying by that when ever you would divide would speed things up, i think someone reported multiplying as 130% faster than dividing.
secondly an idea of changing the default.
if pixels per meter were 32, we could use "bit-shifting" to multiply and divide;
32 = 2(to the power of)5
so shape.width = image.width>>5; (350% faster than dividing)
or avatar.x = body.x<<5; (300% faster than multiplying)
*these last two speed estimates are based on this link*
http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/
Impact of change
I'm not sure how much that value is used internally in box2d<edit> none other than debug draw</edit>, i assume it may only be used heavily in debug-draw since everything else doesn't worry about pixels.
I'm sure most users use that value quite often in their body / shape creation scripts.
but most importantly pixels per meter is used for every body in every time step to update the position of the displayed UserData
32 is not far off from 30 so I don't suspect there would be a noticeable change in stability. I've read several people have tried to change it to 1 to avoid the need to convert back and forth and it makes box2d act funny.
thoughts?
concept of change
firstly an idea that can be applied as is.
multiplying is faster than dividing.
so storing var inversePxMeter:Number = 1/30; and multiplying by that when ever you would divide would speed things up, i think someone reported multiplying as 130% faster than dividing.
secondly an idea of changing the default.
if pixels per meter were 32, we could use "bit-shifting" to multiply and divide;
32 = 2(to the power of)5
so shape.width = image.width>>5; (350% faster than dividing)
or avatar.x = body.x<<5; (300% faster than multiplying)
*these last two speed estimates are based on this link*
http://lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math/
Impact of change
I'm not sure how much that value is used internally in box2d<edit> none other than debug draw</edit>, i assume it may only be used heavily in debug-draw since everything else doesn't worry about pixels.
I'm sure most users use that value quite often in their body / shape creation scripts.
but most importantly pixels per meter is used for every body in every time step to update the position of the displayed UserData
32 is not far off from 30 so I don't suspect there would be a noticeable change in stability. I've read several people have tried to change it to 1 to avoid the need to convert back and forth and it makes box2d act funny.
thoughts?