本文整理汇总了C++中vec3::DistanceSqr方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3::DistanceSqr方法的具体用法?C++ vec3::DistanceSqr怎么用?C++ vec3::DistanceSqr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec3
的用法示例。
在下文中一共展示了vec3::DistanceSqr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DistanceToAABBSqr
float DistanceToAABBSqr(const vec3& p, const AABB& aabb)
{
if (p.x < aabb.m_mins.x)
{
if (p.y < aabb.m_mins.y)
{
if (p.z < aabb.m_mins.z)
return p.DistanceSqr(aabb.m_mins);
else if (p.z > aabb.m_maxs.z)
return p.DistanceSqr(vec3(aabb.m_mins.x, aabb.m_mins.y, aabb.m_maxs.z));
else
return DistanceToLineSqr(p, aabb.m_mins, vec3(aabb.m_mins.x, aabb.m_mins.y, aabb.m_maxs.z));
}
else if (p.y > aabb.m_maxs.y)
{
if (p.z < aabb.m_mins.z)
return p.DistanceSqr(vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return p.DistanceSqr(vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_maxs.z));
else
return DistanceToLineSqr(p, vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_mins.z), vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_maxs.z));
}
else
{
if (p.z < aabb.m_mins.z)
return DistanceToLineSqr(p, aabb.m_mins, vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return DistanceToLineSqr(p, vec3(aabb.m_mins.x, aabb.m_mins.y, aabb.m_maxs.z), vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_maxs.z));
else
return DistanceToPlaneSqr(p, aabb.m_mins, vec3(-1, 0, 0));
}
}
else if (p.x > aabb.m_maxs.x)
{
if (p.y < aabb.m_mins.y)
{
if (p.z < aabb.m_mins.z)
return p.DistanceSqr(vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return p.DistanceSqr(vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_maxs.z));
else
return DistanceToLineSqr(p, vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_mins.z), vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_maxs.z));
}
else if (p.y > aabb.m_maxs.y)
{
if (p.z < aabb.m_mins.z)
return p.DistanceSqr(vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return p.DistanceSqr(vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_maxs.z));
else
return DistanceToLineSqr(p, vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_mins.z), vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_maxs.z));
}
else
{
if (p.z < aabb.m_mins.z)
return DistanceToLineSqr(p, vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_mins.z), vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return DistanceToLineSqr(p, vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_maxs.z), vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_maxs.z));
else
return DistanceToPlaneSqr(p, aabb.m_maxs, vec3(1, 0, 0));
}
}
else
{
if (p.y < aabb.m_mins.y)
{
if (p.z < aabb.m_mins.z)
return DistanceToLineSqr(p, aabb.m_mins, vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return DistanceToLineSqr(p, vec3(aabb.m_mins.x, aabb.m_mins.y, aabb.m_maxs.z), vec3(aabb.m_maxs.x, aabb.m_mins.y, aabb.m_maxs.z));
else
return DistanceToPlaneSqr(p, aabb.m_mins, vec3(0, -1, 0));
}
else if (p.y > aabb.m_maxs.y)
{
if (p.z < aabb.m_mins.z)
return DistanceToLineSqr(p, vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_mins.z), vec3(aabb.m_maxs.x, aabb.m_maxs.y, aabb.m_mins.z));
else if (p.z > aabb.m_maxs.z)
return DistanceToLineSqr(p, vec3(aabb.m_mins.x, aabb.m_maxs.y, aabb.m_maxs.z), aabb.m_maxs);
else
return DistanceToPlaneSqr(p, aabb.m_maxs, vec3(0, 1, 0));
}
else
{
if (p.z < aabb.m_mins.z)
return DistanceToPlaneSqr(p, aabb.m_mins, vec3(0, 0, -1));
else if (p.z > aabb.m_maxs.z)
return DistanceToPlaneSqr(p, aabb.m_maxs, vec3(0, 0, 1));
else
return 0;
}
}
}