当前位置: 首页>>代码示例>>C++>>正文


C++ AxisAlignedBoundingBox::getGreaterCorner方法代码示例

本文整理汇总了C++中AxisAlignedBoundingBox::getGreaterCorner方法的典型用法代码示例。如果您正苦于以下问题:C++ AxisAlignedBoundingBox::getGreaterCorner方法的具体用法?C++ AxisAlignedBoundingBox::getGreaterCorner怎么用?C++ AxisAlignedBoundingBox::getGreaterCorner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AxisAlignedBoundingBox的用法示例。


在下文中一共展示了AxisAlignedBoundingBox::getGreaterCorner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: build

//------------------------------------------------------------------------
void KdTreeNode::build(KdTree* tree, const AxisAlignedBoundingBox& aabb, unsigned int depth)
{
	if (hasToStopBuilding(depth))
	{
		return;
	}

	float subcost  = std::numeric_limits<float>::max();
	float distance = std::numeric_limits<float>::max();

	Vector3::AXIS axis = aabb.getDirection();
	float lowerDistance = aabb.getLowerCorner().get(axis);
	float greaterDistance = aabb.getGreaterCorner().get(axis);

	// m_Spheres are sorted along axis to simplify the splitplane research
	std::sort(m_Spheres->begin(), m_Spheres->end(), [&](const Sphere* s1, const Sphere* s2) {
		return s1->getCenter().get(axis) < s2->getCenter().get(axis);
	});

	unsigned int greaterCount = unsigned int(m_Spheres->size());
	unsigned int lowerCount = 0;

	///////////////////////////
	// Find best split plane //
	///////////////////////////

	for (auto it = m_Spheres->begin(); it != m_Spheres->end(); it++)
	{
		const Sphere* pSphere = *it;
		const AxisAlignedBoundingBox& sphereAABB = pSphere->getAABB();
		float newDistance;
		float newSubcost;

		newDistance = sphereAABB.getLowerCorner().get(axis);

		if (lowerDistance < newDistance && newDistance < greaterDistance)
		{
			newSubcost = cost(aabb, lowerCount, greaterCount, newDistance, axis);

			if (newSubcost < subcost)
			{
				distance = newDistance;
				subcost = newSubcost;
			}
		}

		greaterCount--;
		lowerCount++;

		newDistance = sphereAABB.getGreaterCorner().get(axis);

		if (lowerDistance < newDistance && newDistance < greaterDistance)
		{
			newSubcost = cost(aabb, lowerCount, greaterCount, newDistance, axis);

			if (newSubcost < subcost)
			{
				distance = newDistance;
				subcost = newSubcost;
			}
		}
	}

	// if there is no interesting split
	if (distance <= lowerDistance || greaterDistance <= distance)
	{
		return;
	}

	////////////////////
	// Split the Node //
	////////////////////

	m_Axis = axis;
	m_SplitDistance = distance;

	AxisAlignedBoundingBox boxA = aabb.getLowerSubAABB(distance, axis);
	AxisAlignedBoundingBox boxB = aabb.getGreaterSubAABB(distance, axis);

	m_Nodes = tree->getNextNode();
	tree->getNextNode(); // we allocate a pair, they are next to each other in memory

	for (auto it = m_Spheres->begin(); it != m_Spheres->end(); it++)
	{
		const Sphere* pSphere = *it;

		if (boxA.intersect(*pSphere))
		{
			getA()->add(pSphere);
		}
		if (boxB.intersect(*pSphere))
		{
			getB()->add(pSphere);
		}
	}

	getA()->build(tree, boxA, depth + 1);
	getB()->build(tree, boxB, depth + 1);

//.........这里部分代码省略.........
开发者ID:Dragnalith,项目名称:Raycaster,代码行数:101,代码来源:KdTree.cpp


注:本文中的AxisAlignedBoundingBox::getGreaterCorner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。