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


C++ AABB::downright方法代码示例

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


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

示例1: AABB_vs_AABB

bool Collision::AABB_vs_AABB(const AABB& a, const AABB& b, Vector *v)
{
    const Vector a_upleft = a.upleft();
    const Vector a_downright = a.downright();
    const Vector b_upleft = b.upleft();
    const Vector b_downright = b.downright();

    bool c =  !(a_downright.y < b_upleft.y
             || a_upleft.y    > b_downright.y
             || a_downright.x < b_upleft.x
             || a_upleft.x    > b_downright.x);

    if(c && v)
    {
        AABB ov = a.getOverlap(b);
        *v = ov.getCenter();
    }

    return c;
}
开发者ID:lv3proj,项目名称:lv3proj_ng,代码行数:20,代码来源:Collision.cpp

示例2: AABB_vs_Circle

bool Collision::AABB_vs_Circle(const AABB& a, const Circle& c, Vector *v)
{
    const Vector cpos = c.getPosition();
    const Vector upleft = a.upleft();
    const Vector downright = a.downright();

    const bool leftside = cpos.x >= upleft.x;
    const bool rightside  = cpos.x <= downright.x;

    const bool topside = cpos.y >= upleft.y;
    const bool bottomside = cpos.y <= downright.y;

    const bool inx = leftside && rightside;
    const bool iny = topside && bottomside;
    /*
      |       |    
      |  (x)  |    
  ----+-------+----
      |#######|    
   (y)|#######|(y) 
      |#######|    
  ----+-------+----
      |  (x)  |    
      |       |    
    */
    // First check: Center completely in AABB? [(#) region ]
    if(inx && iny)
    {
        if(v)
            *v = cpos;
        return true;
    }

    // Quick check: If AABBs are not intersecting, the circle is definitely out of reach.
    const AABB caabb = c.getAABB();
    if(!AABB_vs_AABB(a, caabb, NULL))
        return false;

    // AABBs intersecting. Now, if the circle center is contained in at least one axis,
    // they are intersecting. [ (x) or (y) region ]
    if(inx || iny)
    {
        if(v)
        {
            if(inx)
            {
                     if(bottomside) *v = Vector(cpos.x, upleft.y);
                else if(topside)    *v = Vector(cpos.x, downright.y);
            }
            else
            {
                     if(leftside)   *v = Vector(downright.x, cpos.y);
                else if(rightside)  *v = Vector(upleft.x,    cpos.y);
            }
        }
        return true;
    }

    // If we are here, the circle center must be in one of the corner regions.
    // Now we need to check if the circle contains the corresponding corner point of the AABB.
    Vector corner;
    // Above AABB?
    if(cpos.y <= upleft.y)
    {
        // Left of AABB?
        if(cpos.x <= upleft.x)
        {
            // Upper left
            corner = upleft;
        }
        else
        {
            // Upper right
            corner = Vector(downright.x, upleft.y);
        }
    }
    else if(cpos.y >= downright.y)
    {
        if(cpos.x <= upleft.x)
        {
            // Lower left
            corner = Vector(upleft.x, downright.y);
        }
        else
        {
            // Lower right.
            corner = downright;
        }
    }
    else
    {
        // Circle is too far away, done here.
        return false;
    }

    if(c.isPointInside(corner))
    {
        if(v)
            *v = corner;
        return true;
//.........这里部分代码省略.........
开发者ID:lv3proj,项目名称:lv3proj_ng,代码行数:101,代码来源:Collision.cpp


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