Iv'e attempted to add bounding box collision detection to my engine, and it compiles properly (which is farther than I got yesterday), but its not working. It calculates a bounding box for every object (3DS) loaded, and passes the min and max values to a struct array. The input functions then call a loop function when a key is pressed, that cycles through all the bounding boxes, and tests to see if the camera is inside them. If not, the camera can move, if so, don't move the camera. The problem: it dosn't recognize that the camera is in the bounding box for some reason.

Heres some code to aid the explination:

collision.cpp:
Code:
extern CCamera gCam;

boundingbox boxP[MAX_OBJECTS];
int num_boxes = 0;

collision::collision()
{
}

collision::~collision()
{
}

char collision::createBbox(float cx, float cy, float cz,
						   float minx, float miny, float minz,
						   float maxx, float maxy, float maxz)
{
	boxP[num_boxes].min.x = minx+cx;
	boxP[num_boxes].min.y = miny+cy;
	boxP[num_boxes].min.z = minz+cz;

	boxP[num_boxes].max.x = maxx+cx;
	boxP[num_boxes].max.y = maxy+cy;
	boxP[num_boxes].max.z = maxz+cz;

	num_boxes++;
	return (1);
}

bool collision::onBboxCollision(float x, float y, float z,
							    float minx, float miny, float minz,
							    float maxx, float maxy, float maxz)
{
	if (x > minx)
		return false;
	if (x < maxx)
		return false;

	if (y > miny)
		return false;
	if (y < maxy)
		return false;

	if (z> minz)
		return false;
	if (z < maxz)
		return false;

	return true;
}

int collision::loop(float x, float y, float z)
{
	for (int i = 0; i<num_boxes; i++)
	{
		if(onBboxCollision(x, y, z,
						   boxP[i].min.x, boxP[i].min.y, boxP[i].min.z,
						   boxP[i].max.x, boxP[i].max.y, boxP[i].max.z)==1)
		{
			return (i);
		}
	}
	return (-1);
}
input.cpp (snippet):
Code:
void Input::CheckForInput(float speed)
{
	if(GetKeyState('W') & 0x80){ 
		if(_peCollision->loop(gCam.m_vView.x, gCam.m_vView.y, gCam.m_vView.z)==!-1)exit(0);
	else if(_peCollision->loop(gCam.m_vView.x, gCam.m_vView.y, gCam.m_vView.z)==-1)gCam.MoveCamera(speed);}
	
	if(GetKeyState('S') & 0x80){ if(_peCollision->loop(gCam.m_vPosition.x, gCam.m_vPosition.y, gCam.m_vPosition.z)==-1)gCam.MoveCamera(-speed); }
	
	if(GetKeyState('A') & 0x80){ /*if(_peCollision->loop()==1)*/gCam.StrafeCamera(-speed); }
	
	if(GetKeyState('D') & 0x80){ /*if(_peCollision->loop()==1)*/gCam.StrafeCamera(speed); }
	
	
	
	if(GetKeyState('O') &0x80){ ShowCursor(false); }

	if(GetKeyState('P') &0x80){	ShowCursor(true); }
}
Please help if you can. Let me know if I didn't give enough information.

thanx,
-psychopath