Advertisement

AABB collusion not working :(

Started by April 26, 2006 06:35 PM
0 comments, last by lack the hack 18 years, 7 months ago

float Abs(float A)
{
	if(A <0)
	{
		A = -A;
	}
	return A;
}

int place_free(V3SectorPoints obj, V3SectorPoints obj2)
{
	Abs(obj.min.x);
	Abs(obj.min.y);
	Abs(obj.min.z);
	Abs(obj.max.x);
	Abs(obj.max.y);
	Abs(obj.max.z);
    Abs(obj2.min.x);
	Abs(obj2.min.y);
	Abs(obj2.min.z);
	Abs(obj2.max.x);
	Abs(obj2.max.y);
	Abs(obj2.max.z);
if((obj.min.z > obj2.min.z) && (obj.max.z < obj2.max.z) && (obj.min.x > obj2.min.x) && (obj.max.x < obj2.max.x) && (obj.min.y > obj2.min.y) && (obj.max.y < obj2.max.y))
{
return true;
}

return false;
}

Then for the program I :

if(place_free(player, warp))
{
...
}

I am using NeHe's lesson 10 movement (modified by me). Can someone tell me why I am not moving?
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
for reference, it's spelled collision ;]

i don't know what's wrong with your code, but i'll show you the function i use, it works good for me:
bool boxCollision(float object1Bottom,float object1Top,float object1Left,float object1Right,float object2Top,float object2Bottom,float object2Left,float object2Right){	//Y BOX CHECK	if(object1Left <= object2Right && object1Right >= object2Left)	{		if(object1Top >= object2Bottom && object1Top <= object2Bottom + 2)		{			return true;		}		if(object1Bottom <= object2Top && object1Bottom >= object2Top - 2)		{			return true;		}	}	//X BOX CHECK	if(object1Top >= object2Bottom && object1Bottom <= object2Top)	{		if(object1Left <= object2Right && object1Left >= object2Right - 2)		{			return true;		}		if(object1Right >= object2Left && object1Right <= object2Left + 2)		{			return true;		}	}	return false;}

maybe a little confusing, but good enough. (sorry that there's so many parameters and the codes messy, it was my first AABB function.)

hope that helps

--nathan

This topic is closed to new replies.

Advertisement