I just wrote a quick adaptation of the PhysExplosion Method (Box2D c++) in Box2D AS3.
This example works with Box2D and QuickBox2D.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /** * * @param locationPnt Application point of the explosion * @param nRadius Radius of the explosion in pixels * @param nForce Force of explosion */ private function physExplosion(locationPnt:Point, nRadius:Number, nForce:Number) : void { var aabb:b2AABB = new b2AABB(); aabb.lowerBound.Set((locationPnt.x - nRadius) / METER, (locationPnt.y - nRadius) / METER); aabb.upperBound.Set((locationPnt.x + nRadius) / METER,(locationPnt.y + nRadius) / METER); var k_bufferSize:Number = BODY_NUM; var buffer:Array = new Array(); var count:int = _pSim.w.Query(aabb, buffer, k_bufferSize); for (var i:Number = 0; i< count; ++i) { var pBody:b2Body = buffer[i].GetBody(); var pBodyPos:b2Vec2 = pBody.GetWorldCenter(); var pHitVector:b2Vec2 = new b2Vec2(pBodyPos.x - locationPnt.x/METER, pBodyPos.y - locationPnt.y/METER); var radDist:Number = pHitVector.Normalize(); radDist = (radDist * METER); if (!pBody.IsStatic() == (radDist<=nRadius)){ pBody.WakeUp(); var nHitForce:Number = ((nRadius-radDist) / nRadius) * nForce; var appForce:b2Vec2 = new b2Vec2(pHitVector.x*nHitForce,pHitVector.y*nHitForce); pBody.ApplyImpulse(appForce, pBody.GetWorldCenter()); } } } |
Source code soon… And other experiments to support the angular velocity caused by the explosion
Tags: Actionscript, Box2D, examples, Flash, Math, physics, quickbox2d
Hello,
Amazing! Not clear for me, how offen you updating your http://www.eventdispatcher.fr.
Socco
That’s very good, I was just about to start working on something very similar…
But, can you adapt it so that the force doesn’t pass through objects which have density = 0??
Following on from the previous message it’s possible to use b2Segment to do a “ray-trace” from the origin of the explosion.
From that it’s possible to determine the density of any shape in between the the explosion and the object being moved…
Tanks for your interesting comment !
Il will add notes and schema in this post to explain difficulties to render a good explosion (Point of application, center mass, density 0 bodies …)
Een van de interessantste plaatsen die ik heb ontmoet.
@charlie I found informations on RayCast
http://www.box2d.org/wiki/index.php?title=TestSegment
And AS3 application in : http://personal.boristhebrave.com/project/box2d-raycasts
ahhh, good find on the RayCast stuff…
My implementation works similarly, but is nowhere near as efficient…
I think it’s a slight shame that the box2d manual is so basic… (and doesn’t include some of the great additions.)
Salut Germain,
Ca fait un bail (je n’ai pas ouvert msn depuis 1 an à peu près…
Tu bosses où en ce moment ?
Moi, je suis chez Bouygues Tel (Applis sur SetTopBox)
Très intéressant ces travaux sur Box2D !
Passe le bonjour au collègue edocoien à l’occaz
++
Tony