iPhone 3d Bullet Physics Explosion

Forum for Objective-C iPhone games and OpenGL related topics including programming doubts, books and other resources for iPhone game development

iPhone 3d Bullet Physics Explosion

Postby DevelopmentTeam » Tue Feb 07, 2012 12:05 pm

We are working on a 3D game engine with bullet physics. After trying out some tricks we finally ended up making explosion that affects all the nearby objects. The below function is called with the explosion location, power and radius. Remember to call this function from the tick method. Calling it from anywhere else might bring up crashes.

Code: Select all
- (void) Explode:(btVector3)location Power:(float)power Radius:(float)radius {
    for(int i = 0; i < _totalShapes; i++) {
        btVector3 shapeLocation = [_shapes[i] getPosition];
        float distance = btDistance(location, shapeLocation);
        if (distance < radius) {
            btVector3 dir = [_shapes[i] getDirectionFrom:location];
            [_shapes[i] ApplyForce:(dir*(-power/(distance*distance)))];
        }
    }
}
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Return to iPhone OpenGL ES 3D Game Development Forum

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron