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


C++ Vector2::GetLengthSquared方法代码示例

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


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

示例1: SweptCircleEdgeVertexIntersect

// Checks intersection between a polygon an moving circle at inBegin + t * inDelta with radius^2 = inA * t^2 + inB * t + inC, t in [0, 1]
// Returns true when it does and returns the intersection position in outPoint and the intersection fraction (value for t) in outFraction
bool SweptCircleEdgeVertexIntersect(const Vector2 *inVertices, int inNumVertices, const Vector2 &inBegin, const Vector2 &inDelta, float inA, float inB, float inC, Vector2 &outPoint, float &outFraction)
{
    // Loop through edges
    float upper_bound = 1.0f;
    bool collision = false;
    for (const Vector2 *v1 = inVertices, *v2 = inVertices + inNumVertices - 1; v1 < inVertices + inNumVertices; v2 = v1, ++v1)
    {
        float t;

        // Check if circle hits the vertex
        Vector2 bv1 = *v1 - inBegin;
        float a1 = inA - inDelta.GetLengthSquared();
        float b1 = inB + 2.0f * inDelta.Dot(bv1);
        float c1 = inC - bv1.GetLengthSquared();
        if (FindLowestRootInInterval(a1, b1, c1, upper_bound, t))
        {
            // We have a collision
            collision = true;
            upper_bound = t;
            outPoint = *v1;
        }

        // Check if circle hits the edge
        Vector2 v1v2 = *v2 - *v1;
        float v1v2_dot_delta = v1v2.Dot(inDelta);
        float v1v2_dot_bv1 = v1v2.Dot(bv1);
        float v1v2_len_sq = v1v2.GetLengthSquared();
        float a2 = v1v2_len_sq * a1 + v1v2_dot_delta * v1v2_dot_delta;
        float b2 = v1v2_len_sq * b1 - 2.0f * v1v2_dot_bv1 * v1v2_dot_delta;
        float c2 = v1v2_len_sq * c1 + v1v2_dot_bv1 * v1v2_dot_bv1;
        if (FindLowestRootInInterval(a2, b2, c2, upper_bound, t))
        {
            // Check if the intersection point is on the edge
            float f = t * v1v2_dot_delta - v1v2_dot_bv1;
            if (f >= 0.0f && f <= v1v2_len_sq)
            {
                // We have a collision
                collision = true;
                upper_bound = t;
                outPoint = *v1 + v1v2 * (f / v1v2_len_sq);
            }
        }
    }

    // Check if we had a collision
    if (!collision)
        return false;
    outFraction = upper_bound;
    return true;
}
开发者ID:jrouwe,项目名称:SweptEllipsoid,代码行数:52,代码来源:SweptEllipsoid.cpp


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