本文整理匯總了C++中Box2D::Area方法的典型用法代碼示例。如果您正苦於以下問題:C++ Box2D::Area方法的具體用法?C++ Box2D::Area怎麽用?C++ Box2D::Area使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Box2D
的用法示例。
在下文中一共展示了Box2D::Area方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Occluded
bool Occluded( const Box2D &bound, float depth, const HOM *hom, int scnWidth, int scnHeight, bool autoFind )
{
// initiating case
if ( autoFind )
{
// find best starting level
float area = bound.Area() * 100.f;
float bestDif = (float)INFINITE;
HOM *curLevel = const_cast<HOM *>( hom );
while ( curLevel != NULL )
{
int pixArea = ( ( scnWidth / curLevel->width ) * ( scnHeight / curLevel->height ) );
float curDif = abs( (float)pixArea - area );
if ( curDif < bestDif )
{
hom = curLevel;
bestDif = curDif;
}
curLevel = curLevel->prev;
}
}
Box2D box;
float denW = (float)( scnWidth / hom->width );
float denH = (float)( scnHeight / hom->height );
box.origin[0] = (float)bound.origin[0] / denW;
box.extent[0] = (float)bound.extent[0] / denW;
box.origin[1] = (float)bound.origin[1] / denH;
box.extent[1] = (float)bound.extent[1] / denH;
// test each pixel
int nOpaques = 0;
int yMin = std::max( (int)( box.origin[1] + .5f ), 0 );
int yMax = std::min( (int)( box.extent[1] + .5f ), hom->height - 1 );
int xMin = std::max( (int)( box.origin[0] + .5f ), 0 );
int xMax = std::min( (int)( box.extent[0] + .5f ), hom->width - 1 );
for ( int y = yMin; y < yMax; ++y )
{
for ( int x = xMin; x < xMax; ++x )
{
float test = const_cast<HOM *>( hom )->Depth( x, y );
if ( ( const_cast<HOM *>( hom )->Map( x, y ) < TRANSPARENCY_THRESHOLD ) ||
( depth < const_cast<HOM *>( hom )->Depth( x, y ) ) )
{
return false;
}
if ( const_cast<HOM *>( hom )->Map( x, y ) > OPACITY_THRESHOLD )
{
nOpaques++;
}
}
}
int iArea = ( ( xMax - xMin ) * ( yMax - yMin ) );
if ( nOpaques < iArea )
{
if ( hom->prev != NULL )
return Occluded( bound, depth, hom->prev, scnWidth, scnHeight, false );
return false;
}
return true;
}