3D Rigid body sphere collision response (C++)

  c++, collision, physics

I am currently programming a 3D physics engine in C++ and have two spheres in my scene. I can detect when said spheres are colliding and they have some basic collision as a response but the spheres go inside each other a lot and act minimally upon each other so I’m looking to change this to be a RigidBody collision. I’ve looked online and many tutorials are on 2D collisions and use Elastic collision which is already hard enough to translate into 2D. Any advice on where to look for Rigidbody sphere collision would be a huge help and I’ll put below the code I am currently using for my collision. Thanks in advance!

for (size_t i = 0; i < pool.size(); i++)
        {
            if (pool.at(i) == this)
            {
                continue;
            }
            DynamicObjects* other = pool.at(i);
            SScollision = PFG::SphereToSphereCollision(pos, other->GetPosition(), rad, other->GetRadious(), contactPoint);
            if (SScollision)
            {
                glm::vec3 relativeVel = this->GetVelocity() - other->GetVelocity();

                float eCof = -(1.0f + 1.0f) * glm::dot(relativeVel, contactPoint);

                float jLin = eCof / (1.0f / this->GetMass() + 1.0f / other->GetMass());

                glm::vec3 collision_impulse_force = jLin * contactPoint / deltaTs;

                //ClearForces();
                AddForce(1.0f / this->GetMass() * collision_impulse_force);

                //pool.at(otherI)->ClearForces();
                other->AddForce(-(1.0f / other->GetMass() * collision_impulse_force));
            }
        }

Source: Windows Questions C++

LEAVE A COMMENT