本文整理汇总了C++中OBB::localToParent方法的典型用法代码示例。如果您正苦于以下问题:C++ OBB::localToParent方法的具体用法?C++ OBB::localToParent怎么用?C++ OBB::localToParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBB
的用法示例。
在下文中一共展示了OBB::localToParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: normal
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Scalar
Line3D::GetDistanceTo(
const OBB& box,
int *first_axis
)
{
Check_Object(this);
Check_Object(&box);
Check_Pointer(first_axis);
//
//------------------------------------------------------------------------
// Get the vector from the line to the centerpoint of the OBB. All planes
// will be generated relative to this
//------------------------------------------------------------------------
//
Point3D center;
center = box.localToParent;
Vector3D delta;
delta.Subtract(center, origin);
//
//--------------------------------------------------
// Set up the loop to examine each of the three axes
//--------------------------------------------------
//
Scalar enters = -100.0f - length;
Scalar leaves = length + 100.0f;
for (int axis=X_Axis; axis <= Z_Axis; ++axis)
{
UnitVector3D
normal(
box.localToParent(axis, X_Axis),
box.localToParent(axis, Y_Axis),
box.localToParent(axis, Z_Axis)
);
//
//----------------------------------------------------------------------
// Now, we have to calculate how far the line moves along the normal per
// unit traveled down the line. If it is perpendicular to the normal,
// then it will hit or miss based solely upon the origin location
//----------------------------------------------------------------------
//
Scalar drift = direction * normal;
Scalar distance;
if (Small_Enough(drift))
{
distance = delta * normal;
if (Fabs(distance) > box.axisExtents[axis])
return -1.0f;
else
continue;
}
//
//--------------------------------------------------------------------
// We know the line is not parallel, so we will now calculate how long
// the line will stay inside the box. We also will calculate how far
// from the origin to the centerplane of the OBB
//--------------------------------------------------------------------
//
drift = 1.0f / drift;
Scalar span = box.axisExtents[axis] * Fabs(drift);
distance = (delta * normal) * drift;
//
//--------------------------------------------------------------------
// Now adjust where the line can enter and leave the OBB, and if it is
// no longer possible to hit, stop checking
//--------------------------------------------------------------------
//
Scalar enter = distance - span;
Scalar leave = distance + span;
if (enter > enters)
{
*first_axis = axis;
enters = enter;
}
if (leave < leaves)
leaves = leave;
if (enters > leaves)
return -1.0f;
}
//
//-------------------------------------------------------------------------
// If we got here, then the line in theory can hit the OBB, so now we check
// to make sure it hits it within the allowed span of the line
//-------------------------------------------------------------------------
//
if (leaves < 0.0f || enters > length)
return -1.0f;
Min_Clamp(enters, 0.0f);
return enters;
}