本文整理汇总了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;
}
示例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;
//.........这里部分代码省略.........