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


C++ OBB::localToParent方法代码示例

本文整理汇总了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;
}
开发者ID:Ariemeth,项目名称:MechCommander2HD,代码行数:98,代码来源:Line.cpp


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