Advertisement

Collision detection in octrees

Started by July 20, 2003 03:22 PM
0 comments, last by uber_n00b 21 years, 7 months ago
I load in a file filled with points and form an octree right and theres about 60,000 polygons formed. It isn''t feasible to calculate collision detection for each polygon each time the camera moves so i made a function that checks collision detection for each polygon only in the node of the octree the camera is in. Is there a faster way to do it? Thats still checking like up to 32 polygons per render My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
I had this problem, this is how I solved it (warning: probably not the best way but here goes):

COctree* COctree::getNearestFaces(CVector3 position){	if (!isSubdivided)	{		return this;	}	else	{		for (int i = 0; i < 8; i++)		{				if ((position.x <= (child[i]->center.x + (child[i]->width / 2))) &&					(position.y <= (child[i]->center.y + (child[i]->width / 2))) &&					(position.z <= (child[i]->center.z + (child[i]->width / 2))) &&					(position.x >=(child[i]->center.x - (child[i]->width / 2))) &&					(position.y >=(child[i]->center.y - (child[i]->width / 2))) &&					(position.z >=(child[i]->center.z - (child[i]->width / 2))))				{						if (child[i]->numFaces <= 0)						return this;					return child[i]->getNearestFaces(position);				}					}	}	return NULL;}vector<COctree*> getNearestNodes(COctree* octree, CVector3 position, CVector3 radius){	vector<COctree*> result;		CVector3 nextPos = CVector3(position.x - radius.x, position.y + radius.y, position.z + radius.z);	result.push_back(octree->getNearestFaces(nextPos));	nextPos = CVector3(position.x - radius.x, position.y + radius.y, position.z - radius.z);	result.push_back(octree->getNearestFaces(nextPos));	nextPos = CVector3(position.x + radius.x, position.y + radius.y, position.z - radius.z);	result.push_back(octree->getNearestFaces(nextPos));	nextPos = CVector3(position.x + radius.x, position.y + radius.y, position.z + radius.z);	result.push_back(octree->getNearestFaces(nextPos));		nextPos = CVector3(position.x - radius.x, position.y - radius.y, position.z + radius.z);	result.push_back(octree->getNearestFaces(nextPos));	nextPos = CVector3(position.x - radius.x, position.y - radius.y, position.z - radius.z);	result.push_back(octree->getNearestFaces(nextPos));	nextPos = CVector3(position.x + radius.x, position.y - radius.y, position.z - radius.z);	result.push_back(octree->getNearestFaces(nextPos));	nextPos = CVector3(position.x + radius.x, position.y - radius.y, position.z + radius.z);	result.push_back(octree->getNearestFaces(nextPos));	return result;} 


GetNearestFaces just recursively loops through the octree returning the node that the position passed is in. At first I tried using just the faces in this node, the problem is that if you are crossing to a different node, you kinda fall through floors. So the second method passes a position, and a radius (for a bounding box) and should return all the nodes that the box intersects. Its probably got some bugs but it seems to work ok. Anyway you get the idea.

Kazade.

Hyperdev

"To err is human, to really mess up requires a computer"


[edited by - Lukerd on July 20, 2003 5:32:41 PM]
"To err is human, to really mess up requires a computer"

This topic is closed to new replies.

Advertisement