コード例 #1
0
ファイル: MOAIVertexFormat.cpp プロジェクト: Odie/moai-beta
//----------------------------------------------------------------//
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;
}