I don't think a linear force falloff would be realistic. (No idea how to do it better, but still, it's not realistic)
And for full realism you might want to count for the surface area directed to the blast (A small narrow box in the blast direction will catch less force then a small narrow box directly 90deg rotated on the blast)
Also, you try to get the length and normal of vectors with your own math, while the b2Vec2 class has functions for that, which are way faster then yours (cause pow() is slow, x*x is way faster then pow(x, 2) while it does the same)
This will be faster (but untested right now)
Code:
void PhysExplosion(b2Vec2 pos, float Radius, float Force)
{
b2AABB Sector;
Sector.lowerBound.Set(pos.x-Radius, pos.y-Radius);
Sector.upperBound.Set(pos.x+Radius, pos.y+Radius);
const int32 k_bufferSize = 512;
b2Shape *buffer[k_bufferSize];
int32 count = PhysWorld->Query(Sector, buffer, k_bufferSize);
b2Body* Body;
b2Vec2 HitVector;
b2Vec2 BodyPos;
float HitForce;
float Distance;
for (int32 i = 0; i < count; ++i)
{
Body = buffer[i]->GetBody();
BodyPos = Body->GetWorldCenter();
HitVector = (BodyPos-pos);
Distance = HitVector.Normalize(); //Makes a 1 unit length vector from HitVector, while getting the length.
if ((Body->IsDynamic()) & (Distance<=Radius))
{
HitForce=(Radius-Distance)*Force; //TODO: This is linear, but that's not realistic.
Body->ApplyImpulse(HitForce * HitVector, Body->GetWorldCenter());
};
}
};