本文整理汇总了C#中AABB.Combine方法的典型用法代码示例。如果您正苦于以下问题:C# AABB.Combine方法的具体用法?C# AABB.Combine怎么用?C# AABB.Combine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AABB
的用法示例。
在下文中一共展示了AABB.Combine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateMetrics
private void ValidateMetrics(int index)
{
if (index == TreeNode.NULL_NODE)
{
return;
}
TreeNode node = m_nodes[index];
int child1 = node.Child1;
int child2 = node.Child2;
if (node.Leaf)
{
Debug.Assert(child1 == TreeNode.NULL_NODE);
Debug.Assert(child2 == TreeNode.NULL_NODE);
Debug.Assert(node.Height == 0);
return;
}
Debug.Assert(0 <= child1 && child1 < m_nodeCapacity);
Debug.Assert(0 <= child2 && child2 < m_nodeCapacity);
int height1 = m_nodes[child1].Height;
int height2 = m_nodes[child2].Height;
int height = 1 + MathUtils.Max(height1, height2);
Debug.Assert(node.Height == height);
var aabb = new AABB();
aabb.Combine(m_nodes[child1].AABB, m_nodes[child2].AABB);
Debug.Assert(aabb.LowerBound.Equals(node.AABB.LowerBound));
Debug.Assert(aabb.UpperBound.Equals(node.AABB.UpperBound));
ValidateMetrics(child1);
ValidateMetrics(child2);
}
示例2: RebuildBottomUp
/// <summary>
/// Build an optimal tree. Very expensive. For testing.
/// </summary>
public void RebuildBottomUp()
{
var nodes = new int[m_nodeCount];
int count = 0;
// Build array of leaves. Free the rest.
for (int i = 0; i < m_nodeCapacity; ++i)
{
if (m_nodes[i].Height < 0)
{
// free node in pool
continue;
}
if (m_nodes[i].Leaf)
{
m_nodes[i].Parent = TreeNode.NULL_NODE;
nodes[count] = i;
++count;
}
else
{
FreeNode(i);
}
}
var b = new AABB();
while (count > 1)
{
float minCost = Single.MaxValue;
int iMin = -1, jMin = -1;
for (int i = 0; i < count; ++i)
{
AABB aabbi = m_nodes[nodes[i]].AABB;
for (int j = i + 1; j < count; ++j)
{
AABB aabbj = m_nodes[nodes[j]].AABB;
b.Combine(aabbi, aabbj);
float cost = b.Perimeter;
if (cost < minCost)
{
iMin = i;
jMin = j;
minCost = cost;
}
}
}
int index1 = nodes[iMin];
int index2 = nodes[jMin];
TreeNode child1 = m_nodes[index1];
TreeNode child2 = m_nodes[index2];
int parentIndex = AllocateNode();
TreeNode parent = m_nodes[parentIndex];
parent.Child1 = index1;
parent.Child2 = index2;
parent.Height = 1 + MathUtils.Max(child1.Height, child2.Height);
parent.AABB.Combine(child1.AABB, child2.AABB);
parent.Parent = TreeNode.NULL_NODE;
child1.Parent = parentIndex;
child2.Parent = parentIndex;
nodes[jMin] = nodes[count - 1];
nodes[iMin] = parentIndex;
--count;
}
m_root = nodes[0];
Validate();
}