• Advertisement
Sign in to follow this  

Sphere Physics Simulation 3D (Impulse Based Reaction)

This topic is 1802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement this method.. i'm not asking for you post your code but if you could help me you'll help the others too!
The angular velocity it's giving me numbers such like: 4.86313e-11 (something like that). I've checked out many many sources... Chris Hecker's website etc. and i didn't see the wrong side of this. 
virtual void collide(Sphere& other)
        Vector d;
        float r;
        float s;
        d = (other.position - this->position); //collision normal (not normalized)
        r = (this->radius + other.radius);
        s = d.length() - r;
        if (s < 0)
            Vector cp, pt1, pt2, vel1, vel2, n, Vr;
            cp = (other.position + this->position) / 2.0f; //collision point (sphere with same radius)
            pt1 = cp - this->position; // collision point to center of mass vector 
            pt2 = cp - other.position;
            //velocity at the point of contact
            vel1 = this->velocity + this->ang_vel.cross(pt1);
            vel2 = other.velocity + other.ang_vel.cross(pt2);
            n = (other.position - this->position);
            Vr = (vel2 - vel1); //relative velocity
            //collision data
            collision.cn = n; // collision normal                    
            collision.cp = cp; //collision point
            collision.rv = Vr; //relative velocity
            float f1 = -(1.0f + 0.804f) * Vr.dot(collision.cn);
            float f2 = (1.0f / this->mass) + (1.0f / other.mass); 
            float f3 = ( (this->inverseInertia * pt1.cross(collision.cn).cross(pt1) ) +
                         (other.inverseInertia * pt2.cross(collision.cn).cross(pt2) ) ).dot(collision.cn);
            float j = f1 / (f2 + f3);
            velocity -= (j / mass) * collision.cn;
            other.velocity += (j / other.mass) * collision.cn ; 
            ang_vel -= j * inverseInertia * pt1.cross(collision.cn);
            other.ang_vel += j * other.inverseInertia * pt2.cross(collision.cn);

Share this post

Link to post
Share on other sites
Collisions between spheres without friction will not transfer any angular momentum, so I'd say that's as expected.

Your final cross products will be giving near zero because the vectors are parallel.

Share this post

Link to post
Share on other sites

hm i saw in another topic that angular momentum can be expressed by

dL = r x J (where J is the impulse vector) and r the position of the sphere...

thanks anyway... here is the topic if someone get interested 


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement