Sign in to follow this  

My collision detection code flaws : (

This topic is 4714 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

Hi all, after a very long break I'm coming back to gamedev stuff... One of my major problems at the time is collision detection. Currently I'm using a very primitive code I created to detect whether 2 bodies collide through OBB. It basicaly consists of detecting if any vertex of one object's bounding box is within the 6 planes of the other object's BB. This code has some flaws as there are some possibilities of objects colliding without any BB vertex go inside the other BB, like this: <edited> I had put a nice ascii drawing here but it got all messed up :/, just use your imagination <edited> Another flaw is that I can't detect the point of collision, what is important for collision response... So, before rewriting all my collision code, I ask for some advices on how to solve this issue... I thought of implementing some Line - Plane col detection to check for intersections between one BB's edge and the other's face Some info that might be usefull:
class CCollBox
{
public:
	CCollBox();
	~CCollBox();

	bool CheckIntersect(CVector Pos, CVector Point);

	CVector Center;
	CVector X;
	CVector Y;
	CVector Z;
};



Please don't say things like "you should put <some var> in private:" it's just a draft
bool CCollBox::CheckIntersect(CVector Pos, CVector Point)
{
	bool Collide = true;

	if(GetVecsAngleCos(Pos + Center - Point + X, X) <= 0 || GetVecsAngleCos(Point - (Pos + Center) + X, X) <= 0)
		Collide = false;

	if(GetVecsAngleCos(Pos + Center - Point + Y, Y) <= 0 || GetVecsAngleCos(Point - (Pos + Center) + Y, Y) <= 0)
		Collide = false;

	if(GetVecsAngleCos(Pos + Center - Point + Z, Z) <= 0 || GetVecsAngleCos(Point - (Pos + Center) + Z, Z) <= 0)
		Collide = false;

	if(Collide)
		return true;
	else
		return false;
}



- GetVecsAngleCos returns the cossine of the angle between 2 vectors - (Pos + Center) is the absolute position of the BB You will probably not use that stuff but I'll post it anyway... Any tutorials (simple please) about other good collision detection methods are also welcome Thanks a lot for reading till here and cya...

Share this post


Link to post
Share on other sites
Hi Raptor,

Fortunately, the answer to your problem is fairly simple, and comes up over and over here. Since 'search' is down, though, let me give you some references.

For OBBs, the 'separating axis theorem' gives you pretty much all the tools you need for both static and dynamic intersection, along with contact points or depth of penetration. Here are some places you can look for info:

1. The 'collision detection' portion of the articles section here. I can't remember which, but one of the articles includes a description of this algorithm with OBBs, and another describes the swept test with AABBs.

2. Any of Dave Eberly's materials: '3D Game Engine Design', 'Game Physics', his various .pdfs on the subject, the code on his Magic Software site, etc.

3. oliii, a member at this site, has some tutorials I believe that cover OBB intersection using the SAT theorem.

Anyway, that should get you started. If the search function were working, a search for 'separating axis' or 'OBB intersection' would turn up all the info you'd ever need.

Good luck...

Share this post


Link to post
Share on other sites
Hey jyk, thanks a lot, that should be just perfect for now

Sorry if this is a very common question ask a milion times a day (I've alreay seen some people asking the same here) but, as you said, the search engine is down (it's been some time it's been down) and searching this forum topic by topic isn't very easy

I'll be seeking for those references right away, thanks again :)

Share this post


Link to post
Share on other sites

This topic is 4714 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this