Im trying to implement the collision of rigid spheres with spin. During research I stumbled upon a thread from here (https://www.gamedev.net/forums/topic/465248-calculating-impulse-due-to-rigid-body-collision-with-friction/?page=1) which shows a formula OP says to “have tested this and everything works correctly”. I tried to implement this in my code but it just doesnt work and I dont know why. The spheres just pass each other as if they wouldnt have a body, only mass.
This is the code I tried:
void Sphere::bounce(Sphere& b) {
const Vector3d Vr = (velocity() + angularMomentum()) - (b.velocity() + b.angularMomentum()); // Org from site?
const double e = 1;
const Vector3d n = math::normal(position(), b.position());
const Vector3d r1 = radius() * n;
const Vector3d r2 = -b.radius() * n;
const Tensor3d I1 = createInertiaTensor();
const Tensor3d I2 = b.createInertiaTensor();
const Vector3d J = (-Vr * (1 + e)) / (1 / mass() + 1 / b.mass() + n.dot((r1.cross(n) / I1).cross(r1)) + n.dot((r2.cross(n) / I2).cross(r2)));
_velocity = velocity() + (J * n) / mass();
b._velocity = b.velocity() + (-J * n) / b.mass();
_spin = spin() + (r1.cross(J * n)) / I1;
b._spin = b.spin() + (r2.cross(-J * n)) / I2;
}
Before adding spin my simple collision function was this, which works great:
void Sphere::collide_old(Sphere& b) {
const Vector3d normal = math::normal(position(), b.position());
const Vector3d relativeVelocity = velocity() - b.velocity();
const double dot = relativeVelocity.dot(normal);
const Vector3d velocityDelta = normal * dot;
_velocit = velocity() - velocityDelta;
b._velocity = b.velocity() + velocityDelta;
}
I know my way around code, not so much physics. So I basically try to implement what I can find online but the resources for collision with spin seem very rare. This is a piece of code Im trying to get working for a few weeks now and Im on the brink of just giving up.
Id be grateful for everyone who could spare some time to help me with this.