Jump to content
  • Advertisement
Sign in to follow this  

Plane - Sphere Collision

This topic is 3993 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 writing a simple plane-sphere (triangles and vertices etc. come later) collision test: obj is the sphere: its radius: obj->r its position: obj->x its speed: obj->v (There are also values for force, rotation etc) tri is a triangle with 3 corner vectors a,b,c (a being origin) and normal n. bool PoolPhysics::planeCollision(ball *obj, triangle *tri){ // The signed distance from the plane. Tri->n is assumed to be normalized double nx = tri->n.dotProduct(obj->x) - tri->n.dotProduct(tri->a); // Check if there already is some penetration. if(nx < THRESH + obj->r) return true; // The relative speed to the plane double nv = tri->n.dotProduct(obj->v /*+ obj->force* this->timeSinceLastFrame / obj->m*/); // If the ball has not already collided we check if its moving away or parallell to the plane. if(nv >= 0) return false; // The estimated time for collision (does not consider acceleration) double t0 = (obj->r - nx)/(nv); // The program uses the timesincelastframe to do its calculations // If the estimated collision time is smaller than the frame time // the collision will occur within one frame, we do an extra calculation at t0. if(t0 < this->timeSinceLastFrame) this->timeSinceLastFrame = t0; return false; } And it works quite well i suppose but its far from perfect. Anyone got any ideas on how to make this a bit better. Any help would be much appreciated =)

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!