//----------------------------------------------------------------// USBox MOAIGfxQuadListDeck2D::GetBounds ( u32 idx ) { USBox bounds; u32 size = this->mSprites.Size (); if ( size ) { idx = ( idx - 1 ) % size; USRect rect; USSprite& sprite = this->mSprites [ idx ]; if ( sprite.mTotalPairs ) { USSpritePair prim = this->mPairs [ sprite.mBasePair ]; USQuad& baseQuad = this->mQuads [ prim.mQuadID ]; rect = baseQuad.GetBounds (); for ( u32 i = 1; i < sprite.mTotalPairs; ++i ) { prim = this->mPairs [ sprite.mBasePair + i ]; rect.Grow ( this->mQuads [ prim.mQuadID ].GetBounds ()); } bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; } } bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// USBox MOAIDeck::GetBounds ( u32 idx, MOAIDeckRemapper* remapper ) { idx = remapper ? remapper->Remap ( idx ) : idx; USBox bounds; if ( this->mBoundsDeck ) { bounds = this->mBoundsDeck->GetBounds ( idx & MOAITileFlags::CODE_MASK ); } else { bounds = this->GetBounds ( idx & MOAITileFlags::CODE_MASK ); } if ( idx & MOAITileFlags::FLIP_MASK ) { USVec3D scale; scale.mX = ( idx & MOAITileFlags::XFLIP ) ? -1.0f : 1.0f; scale.mY = ( idx & MOAITileFlags::YFLIP ) ? -1.0f : 1.0f; scale.mZ = 1.0f; bounds.Scale ( scale ); bounds.Bless (); } return bounds; }
//----------------------------------------------------------------// USBox MOAIStretchPatch2D::GetItemBounds ( u32 idx ) { UNUSED ( idx ); USBox bounds; bounds.Init ( this->mRect.mXMin, this->mRect.mYMax, this->mRect.mXMax, this->mRect.mYMin, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// bool MOAIVertexFormat::ComputeBounds ( void* buffer, u32 size, USBox& bounds ) { u32 total = this->mVertexSize ? ( size / this->mVertexSize ) : 0; if ( !total ) return false; u32 coordAttributeIdx = this->mAttributeUseTable [ ARRAY_VERTEX ].mAttrID; if ( coordAttributeIdx >= this->mTotalAttributes ) return false; MOAIVertexAttribute& coordAttr = this->mAttributes [ coordAttributeIdx ]; if ( coordAttr.mType != GL_FLOAT ) return false; // TODO: handle other types if ( coordAttr.mSize < 2 ) return false; buffer = ( void* )(( size_t )buffer + coordAttr.mOffset ); float* components = ( float* )buffer; USVec3D coord ( components [ 0 ], components [ 1 ], ( this->mVertexSize > 2 ? components [ 2 ] : 0.0f )); bounds.Init ( coord ); bounds.Inflate ( 0.0000001f ); // prevent 'empty' bounds on cardinal direction lines or single vertex objects for ( u32 i = 1; i < total; ++i ) { buffer = ( void* )(( size_t )buffer + this->mVertexSize ); components = ( float* )buffer; coord.Init ( components [ 0 ], components [ 1 ], ( this->mVertexSize > 2 ? components [ 2 ] : 0.0f )); bounds.Grow ( coord ); } return true; }
//----------------------------------------------------------------// USBox MOAIDeck::GetBounds ( u32 idx, MOAIDeckRemapper* remapper ) { UNUSED ( idx ); UNUSED ( remapper ); USBox bounds; bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); return bounds; }
/** @name setBounds @text Set the dimensions of a bounding box at a given index. @in MOAIBoundsDeck self @in number idx @in number xMin @in number yMin @in number zMin @in number xMax @in number yMax @in number zMax @out nil */ int MOAIBoundsDeck::_setBounds ( lua_State* L ) { MOAI_LUA_SETUP ( MOAIBoundsDeck, "UN" ) u32 idx = state.GetValue < u32 >( 2, 1 ) - 1; if ( idx < self->mBoundsArray.Size ()) { USBox bounds = state.GetBox ( 3 ); bounds.Bless (); self->mBoundsArray [ idx ] = bounds; self->SetBoundsDirty (); } return 0; }
//----------------------------------------------------------------// USBox MOAISurfaceDeck2D::GetItemBounds ( u32 idx ) { USBox bounds; if ( idx < this->mBrushes.Size ()) { USRect rect = this->mBrushes [ idx ].mBounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; } bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// USBox MOAIGfxQuadDeck2D::ComputeMaxBounds () { USRect rect; rect.Init ( 0.0f, 0.0f, 0.0f, 0.0f ); u32 size = this->mQuads.Size (); for ( u32 i = 0; i < size; ++i ) { rect.Grow ( this->mQuads [ i ].GetVtxBounds ()); } USBox bounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// void USPrism::GetAABB ( USBox& box ) const { USVec3D walker = mLoc; box.Init ( walker ); walker.Add ( mYAxis ); box.Grow ( walker ); walker.Add ( mZAxis ); box.Grow ( walker ); walker.Sub ( mYAxis ); box.Grow ( walker ); walker.Add ( mXAxis ); box.Grow ( walker ); walker.Sub ( mZAxis ); box.Grow ( walker ); walker.Add ( mYAxis ); box.Grow ( walker ); walker.Add ( mZAxis ); box.Grow ( walker ); }
//----------------------------------------------------------------// USBox MOAISurfaceDeck2D::ComputeMaxBounds () { u32 size = this->mBrushes.Size (); USRect rect; rect.Init ( 0.0f, 0.0f, 0.0f, 0.0f ); for ( u32 i = 0; i < size; ++i ) { rect.Grow ( this->mBrushes [ i ].mBounds ); } USBox bounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// USBox MOAIBoundsDeck::ComputeMaxBounds () { USBox bounds; u32 size = this->mBoundsArray.Size (); if ( size == 0 ) { bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); } else { this->mMaxBounds = this->mBoundsArray [ 0 ]; for ( u32 i = 1; i < size; ++i ) { bounds.Grow ( this->mBoundsArray [ i ]); } } return bounds; }
//----------------------------------------------------------------// void MOAIPartitionLevel::GatherProps ( MOAIPartitionResultBuffer& results, MOAIProp* ignore, const USBox& box, u32 planeID, u32 mask ) { float halfSize = this->mCellSize * 0.5f; USRect rect = box.GetRect ( planeID ); MOAICellCoord coord0 = this->mGridSpace.GetCellCoord ( rect.mXMin - halfSize, rect.mYMin - halfSize ); MOAICellCoord coord1 = this->mGridSpace.GetCellCoord ( rect.mXMax + halfSize, rect.mYMax + halfSize ); int xTotal = coord1.mX - coord0.mX + 1; int yTotal = coord1.mY - coord0.mY + 1; int width = this->mGridSpace.GetWidth (); int height = this->mGridSpace.GetHeight (); if ( xTotal > width ) xTotal = width; if ( yTotal > height ) yTotal = height; for ( int y = 0; y < yTotal; ++y ) { for ( int x = 0; x < xTotal; ++x ) { MOAICellCoord offset = this->mGridSpace.WrapCellCoord ( coord0.mX + x, coord0.mY + y ); u32 addr = this->mGridSpace.GetCellAddr ( offset ); this->mCells [ addr ].GatherProps ( results, ignore, box, mask ); } } }
//----------------------------------------------------------------// USBox MOAIGfxQuadDeck2D::GetItemBounds ( u32 idx ) { USBox bounds; u32 size = this->mQuads.Size (); if ( size ) { idx = ( idx - 1 ) % size; USRect rect = this->mQuads [ idx ].GetVtxBounds (); bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; } bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// void USBox::GetFitting ( const USBox& target, USVec3D& offset, USVec3D& scale ) const { float w = this->Width (); float h = this->Height (); float d = this->Depth (); float tw = target.Width (); float th = target.Height (); float td = target.Depth (); scale.mX = ( w != 0.0f ) && ( tw != 0.0f ) ? tw / w : 1.0f; scale.mY = ( h != 0.0f ) && ( th != 0.0f ) ? th / h : 1.0f; scale.mZ = ( d != 0.0f ) && ( td != 0.0f ) ? td / d : 1.0f; offset.mX = target.mMin.mX - ( this->mMin.mX * scale.mX ); offset.mY = target.mMin.mY - ( this->mMin.mY * scale.mY ); offset.mZ = target.mMin.mZ - ( this->mMin.mZ * scale.mZ ); }
//----------------------------------------------------------------// bool USFrustum::Cull ( const USBox& box ) const { if ( !box.Overlap ( mAABB )) return true; if ( this->mUsePlanes ) { if ( USSect::BoxToPlane ( box, mPlanes [ NEAR_PLANE ]) > 0 ) return true; if ( USSect::BoxToPlane ( box, mPlanes [ FAR_PLANE ]) > 0 ) return true; if ( USSect::BoxToPlane ( box, mPlanes [ LEFT_PLANE ]) > 0 ) return true; if ( USSect::BoxToPlane ( box, mPlanes [ RIGHT_PLANE ]) > 0 ) return true; if ( USSect::BoxToPlane ( box, mPlanes [ TOP_PLANE ]) > 0 ) return true; if ( USSect::BoxToPlane ( box, mPlanes [ BOTTOM_PLANE ]) > 0 ) return true; } return false; }