Exemple #1
0
//----------------------------------------------------------------//
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;
}
Exemple #2
0
//----------------------------------------------------------------//
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 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;
}
Exemple #4
0
//----------------------------------------------------------------//
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;
}