//----------------------------------------------------------------// bool MOAIVertexFormat::ComputeBounds ( void* buffer, u32 size, ZLBox& 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 != ZGL_TYPE_FLOAT ) return false; // TODO: handle other types if ( coordAttr.mSize < 2 ) return false; buffer = ( void* )(( size_t )buffer + coordAttr.mOffset ); float* components = ( float* )buffer; ZLVec3D coord ( components [ 0 ], components [ 1 ], ( coordAttr.mSize > 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 ], ( coordAttr.mSize > 2 ? components [ 2 ] : 0.0f )); bounds.Grow ( coord ); } return true; }
//----------------------------------------------------------------// void ZLPrism::GetAABB ( ZLBox& box ) const { ZLVec3D 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 ); }
//----------------------------------------------------------------// ZLBox MOAIMesh::GetItemBounds ( u32 idx ) { UNUSED ( idx ); if ( this->mVertexBuffer ) { return this->mVertexBuffer->GetBounds (); } ZLBox bounds; bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// ZLBox MOAIGridDeck2D::GetItemBounds ( u32 idx ) { ZLBox bounds; u32 size = this->mBrushes.Size (); if ( this->mGrid && size ) { // TODO: handle oversized decks (don't assume unit sized deck items) idx = ( idx - 1 ) % size; MOAIGridDeckBrush& brush = this->mBrushes [ idx ]; ZLRect rect = this->mGrid->GetBounds ( brush.mMin, brush.mMax ); rect.Offset ( brush.mOffset.mX - rect.mXMin, brush.mOffset.mY - rect.mYMin ); 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; }
//----------------------------------------------------------------// bool MOAICollisionShape::Overlap ( const MOAITransformBase& t0, const ZLQuad& q0, const MOAITransformBase& t1, const ZLQuad& q1, ZLBox& bounds ) { ZLQuad tq0 = q0; tq0.Transform ( t0.GetLocalToWorldMtx ()); ZLQuad tq1 = q1; tq1.Transform ( t1.GetLocalToWorldMtx ()); ZLRect rect; bool result = tq0.Intersect ( tq1, rect ); bounds.Init ( rect, ZLBox::PLANE_XY, 0.0f, 0.0f ); return result; }
//----------------------------------------------------------------// ZLBox MOAIBoundsDeck::ComputeMaxBounds () { ZLBox 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; }
//----------------------------------------------------------------// ZLBox MOAIGridDeck2D::ComputeMaxBounds () { ZLBox bounds; u32 size = this->mBrushes.Size (); if ( size == 0 ) { bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); } else { bounds = this->GetItemBounds ( 1 ); for ( u32 i = 1; i < this->mBrushes.Size (); ++i ) { bounds.Grow ( this->GetItemBounds ( i )); } } return bounds; }
//----------------------------------------------------------------// ZLBox MOAIScriptDeck::ComputeMaxBounds () { ZLRect rect = this->mRect; if ( this->mOnTotalRect ) { MOAILuaStateHandle state = MOAILuaRuntime::Get ().State (); this->PushLocal ( state, this->mOnTotalRect ); state.DebugCall ( 0, 4 ); rect.mXMin = state.GetValue < float >( -4, 0.0f ); rect.mYMin = state.GetValue < float >( -3, 0.0f ); rect.mXMax = state.GetValue < float >( -2, 0.0f ); rect.mYMax = state.GetValue < float >( -1, 0.0f ); rect.Bless (); } ZLBox bounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// ZLBox MOAIScriptDeck::GetItemBounds ( u32 idx ) { ZLRect rect = this->mRect; if ( this->mOnRect ) { MOAILuaStateHandle state = MOAILuaRuntime::Get ().State (); this->PushLocal ( state, this->mOnRect ); lua_pushnumber ( state, idx ); state.DebugCall ( 1, 4 ); rect.mXMin = state.GetValue < float >( -4, 0.0f ); rect.mYMin = state.GetValue < float >( -3, 0.0f ); rect.mXMax = state.GetValue < float >( -2, 0.0f ); rect.mYMax = state.GetValue < float >( -1, 0.0f ); rect.Bless (); } ZLBox bounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; }