Ejemplo n.º 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;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------//
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;
}
Ejemplo n.º 3
0
/**	@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 ()) {
		ZLBox bounds = state.GetBox ( 3 );
		bounds.Bless ();
		self->mBoundsArray [ idx ] = bounds;
		self->SetBoundsDirty ();
	}
	return 0;
}
Ejemplo n.º 4
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 );
}
//----------------------------------------------------------------//
void MOAIPartitionLevel::GatherProps ( MOAIPartitionResultBuffer& results, MOAIProp* ignore, const ZLBox& box, u32 planeID, u32 mask ) {

	float halfSize = this->mCellSize * 0.5f;

	ZLRect 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 );
		}
	}
}
Ejemplo n.º 6
0
//----------------------------------------------------------------//
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;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
//----------------------------------------------------------------//
void ZLBox::GetFitting ( const ZLBox& target, ZLVec3D& offset, ZLVec3D& 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 );
}
Ejemplo n.º 9
0
//----------------------------------------------------------------//
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;
}
Ejemplo n.º 11
0
//----------------------------------------------------------------//
bool ZLFrustum::Cull ( const ZLBox& box ) const {

	if ( !box.Overlap ( mAABB )) return true;

	if ( this->mUsePlanesForCull ) {
		if ( ZLSect::BoxToPlane ( box, mPlanes [ NEAR_PLANE ]) > 0 ) return true;
		if ( ZLSect::BoxToPlane ( box, mPlanes [ FAR_PLANE ]) > 0 ) return true;
		if ( ZLSect::BoxToPlane ( box, mPlanes [ LEFT_PLANE ]) > 0 ) return true;
		if ( ZLSect::BoxToPlane ( box, mPlanes [ RIGHT_PLANE ]) > 0 ) return true;
		if ( ZLSect::BoxToPlane ( box, mPlanes [ TOP_PLANE ]) > 0 ) return true;
		if ( ZLSect::BoxToPlane ( box, mPlanes [ BOTTOM_PLANE ]) > 0 ) return true;
	}
	return false;
}
Ejemplo n.º 12
0
//----------------------------------------------------------------//
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;
}
Ejemplo n.º 13
0
//----------------------------------------------------------------//
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;
}