Beispiel #1
0
void octreeSolid::constructTreeRecur(octreeSNode * node, int depth)
{
	// Stop at leaf
	if (node->nodeDepth == depth)
	{
		node->bEnd = true;
		leaves.push_back(node);
		return;
	}

	Vec3f mid = (node->leftDownf + node->rightUpf)/2;
	std::vector<Box> boxes = get8ChildrenBox(node->leftDownf, node->rightUpf);

	GeometricFunc geoFunc;
	for (int i = 0; i < 8; i++)
	{
		if (isSurfIntersectWithBox(sufObj, boxes[i])
			|| geoFunc.isPointInSurf(sufObj->point(), sufObj->face(), sufObj->getBVH()->root(), boxes[i].center))
		{
			octreeSNode* newN = new octreeSNode;
			newN->leftDownf = boxes[i].leftDown;
			newN->rightUpf = boxes[i].rightUp;
			newN->nodeDepth = node->nodeDepth+1;
			newN->parent = node;

			node->children[i] = newN;
			constructTreeRecur(newN, depth);
		}
		else
		{
			node->children[i] = nullptr;
		}
	}
}
Beispiel #2
0
bool octreeSolid::isSurfIntersectWithBox(SurfaceObj * sufObj, Box boxf)
{
	CollisionManager colMngr;
	if (colMngr.isSurfaceWithAABBIntersectBox(sufObj->getBVH()->root(), boxf, sufObj->point(), sufObj->face()))
	{
		return true;
	}
	else
	{
		GeometricFunc geoFunc;
		if (geoFunc.isPointInSurf(sufObj->point(), sufObj->face(), sufObj->getBVH()->root(), (boxf.leftDown+boxf.rightUp)/2))
		{
			return true;
			// For optimization, all of it children should automatically set as inside
		}

		return false;
	}
}