So I'm jumping into a physics engine. The colliders for now are spheres and planes. I've found the depth of the collision and the normal at point of contact easy enough, but for the life of me I can not wrap my head around the distribution of energy.
The Bodies contain a Collider, a Mass, a Force vector (velocity * mass), an Elasticity value (0 no bounce, 1 complete bounce) and a Friction value (0 slippery sausage, 1 momentum vampire) I've googled to hell and back and everything comes up with 1D and 2D simplifications, but I've been simply unable to adapt these to 3D.
Edit: I tried following this page: http://www.plasmaphysics.org.uk/collision3d.htm. It seemed so simple but for some reason I still have no bounce with an elasticity of 1.
My implementation is below:
var v = new vec3(
(body.force.x + other.force.x) / totalMass,
(body.force.y + other.force.y) / totalMass,
(body.force.z + other.force.z) / totalMass
);
body.force.set(
((velA.x - v.x) * elasticity + v.x) * body.mass,
((velA.y - v.y) * elasticity + v.y) * body.mass,
((velA.z - v.z) * elasticity + v.z) * body.mass
);
other.force.set(
((velB.x - v.x) * elasticity + v.x) * other.mass,
((velB.y - v.y) * elasticity + v.y) * other.mass,
((velB.z - v.z) * elasticity + v.z) * other.mass
);
For elasticity I have tried both multiplying the elasticity of both bodies and getting the average of them; no change.
So a nights sleep, a bit of thinking and great help taken from the N+ physics explanation page I've hashed something together which works, though not necessarily physically accurate, for the sake of debugging it is split between many variables, but I have commented to the best of my ability.