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...