openfl / box2d

Haxe port of Box2D, a popular rigid-body 2D physics engine
Other
95 stars 28 forks source link

B2internal::m_p.set() what alternate ? #9

Closed justnajm closed 9 years ago

justnajm commented 9 years ago

Hi,

I was trying box2d buoyancy example as3 in openfl but unable to find any alternate method for this "circDef.b2internal::m_p.Set(30 / m_physScale, 0 / m_physScale);".

bodyDef.position.set(300/ m_physScale, 300 / m_physScale); body = m_world.createBody(bodyDef); circDef = new B2CircleShape(7 / m_physScale); fd = new B2FixtureDef(); fd.shape = circDef; fd.density =2; // circDef.computeMass(30 / m_physScale, 0 / m_physScale); // circDef.B2internal:m_p.set(30 / m_physScale, 0 / m_physScale); body.createFixture(fd); // circDef.B2internal::m_p.set(-30 / m_physScale, 0 / m_physScale); body.createFixture(fd); // circDef.B2internal::m_p.set(0 / m_physScale, 30 / m_physScale); body.createFixture(fd); // circDef.B2internal::m_p.set(0 / m_physScale, -30 / m_physScale); body.createFixture(fd);

By commenting the b2internal call I am able to run example but water is not interacting with bodies at all.

jgranick commented 9 years ago

Eventually I am going to probably hide all the internal stuff. It's bad for parallels between the C++ and porting over. I just took a look, you're supposed to use circDef.setLocalPosition () instead of accessing m_p directly. Give it a try and let me know if that works for you

justnajm commented 9 years ago

Great it works :)

Another problem within the same example, the last few line are:

for(body in m_bodies){
    m_controller.addBody(body);
}           
m_world.addController(m_controller);

last line hangs the example and do not show anything in flash player/browser(crashes). What I believe it may be due to the fix I did yesterday in haxe/lib/box2d/1,2,0/box2D/dynamics/controllers/B2BuoyancyController.hx

Without the fix it was throwing following error, "on line 95: Unexpected character ;"

/usr/lib/haxe/lib/box2d/1,2,0/box2D/dynamics/controllers/B2BuoyancyController.hx:95: characters 39-40 : Unexpected ;
/usr/lib/haxe/lib/box2d/1,2,0/box2D/dynamics/controllers/B2BuoyancyController.hx:95: characters 39-40 : Unexpected ;

I used, while on that line instead of "for loop":

while(i.nextBody)

Then the same error moved to line 109

I used, while on it:

while(fixture.getNext())

Then it moved to 137 and 146, there were semi-colons missing. So i added them... I think i didn't fix it the right way :(

jgranick commented 9 years ago

I just committed a round of fixes to fix Neko support, to improve the performance of the B2ShapeType enum as well as resolving the un-ported for() loops in B2BuoyancyController :smile:

justnajm commented 9 years ago

Thanks, it works like charm. Just had 2 semi-colon errors, fixed.