Welcome to my CPE 500 final project: Angry Birds Explosions!

All the code lives at my Github, here!

Use these keys to control the simulation:


1, 2, and 3: Change scenes. 1 is a 3-layer tower, 2 is a tall, skinny tower and 3 is a little dude standing next to a wall.



You can drag the mouse around to change where the "missiles" fly from. Once you press space to launch a missile, the mouse will start to control the camera instead!
Once a missile is flying, press E to cause an Explosion! All the block around any spawned missiles will get sent flying back!
You can spawn as many missiles and cause as many explosions as you want. Go crazy! Once you change scenes, everything will be reset.

Explosion Forces

There are a couple ways you could model explosions. You could simply set the velocity of nearby rigid bodies, but that might not be consistent if there are a lot of moving parts. I chose to apply an instant force to all objects caught in the explosion.
function explode() {
   Vector3d target_posn = bodies[i].curr_E.block<3, 1>(0, 3);
   Vector3d bomb_posn = bodies[bomb_ndx].curr_E.block<3, 1>(0, 3);
   Vector3d diff = bomb_posn - target_posn;
   double dist = diff.norm();
   
   double radius = 10.0;
   if (dist > radius) dist = radius;
   
   Vector4d world_exp_force;
   world_exp_force << -diff.normalized() * (radius - dist) * 1000, 0.0;
   
   bodies[j].explosion_force = (bodies[j].curr_E.inverse() * world_exp_force).head(3);
}

To do this, we take the vector FROM the bomb TO every rigid body in the scene. Then, we normalize it, and set its magnitude so that close-by bodies are affected more by the explosion.

Then, we tell each rigid body an instantaneous force to apply to the next frame! Notice that since the force needs to be in the local space of the rigid body, we multiply the inverse of its E matrix to go from world space to local space. Neat!