Пример #1
0
//----------------------------------------------------------------//
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;
}
Пример #2
0
//----------------------------------------------------------------//
float USBox::GetRadius () const {

	USVec3D spans = mMax;
	spans.Sub ( mMin );
	spans.Scale ( 0.5f );
	return spans.Length ();
}
Пример #3
0
//----------------------------------------------------------------//
bool _vecToXYPlane ( const USVec3D& v0, const USVec3D& v1, USVec2D& result ) {

	USVec3D vec;
	
	vec = v1;
	vec.Sub ( v0 );

	if ( vec.mZ != 0.0f ) {

		result.mX = vec.mX;
		result.mY = vec.mY;
		
		float t = v0.mZ / -vec.mZ;
		
		if (( t > 0.0f ) && ( t <= 1.0f )) {
		
			result.Scale ( t );
		
			result.mX += v0.mX;
			result.mY += v0.mY;
			
			return true;
		}
	}
	return false;
}
Пример #4
0
//----------------------------------------------------------------//
void USPrism::GetCenter ( USVec3D& center ) const {

	center = this->mXAxis;
	center.Add ( this->mYAxis );
	center.Add ( this->mZAxis );
	center.Scale ( 0.5f );
	center.Add ( this->mLoc );
}
Пример #5
0
USVec3D SeekSteering::GetSteering( Character* character, const USVec3D& targetPos )
{
	USVec3D newDir = targetPos - character->GetLoc();
	
	newDir.Norm();
	newDir *= character->GetMaxVel();

	USVec3D speed = newDir - character->GetLinearVelocity();
	speed.Norm();

	return speed * character->GetMaxAcc();
}
Пример #6
0
//----------------------------------------------------------------//
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 );
}
Пример #7
0
//----------------------------------------------------------------//
void USPlane3D::Init ( USVec3D& p1, USVec3D& p2, USVec3D& p3 ) {

	USVec3D r;

	mNorm = p2;
	mNorm.Sub ( p1 );

	r = p3;
	r.Sub ( p1 );

	mNorm.Cross ( r );
	mNorm.Norm ();

	mDist = -mNorm.Dot ( p1 );
}
Пример #8
0
USVec3D SeekSteering::GetSteeringArrive( Character* character, const USVec3D& targetPos )
{
	USVec3D newDir = targetPos - character->GetLoc();
	float radius =   character->GetDstRadius();
	float distance = newDir.Length();

	newDir.Norm();

	if( distance > radius )	newDir *= character->GetMaxVel();
	else					newDir *= character->GetMaxVel() * ( distance / radius );
	

	USVec3D speed = newDir - character->GetLinearVelocity();
	speed.Norm();

	return speed * character->GetMaxAcc();

}
Пример #9
0
//----------------------------------------------------------------//
float USDist::VecToPlane ( const USVec3D& v, const USPlane3D& p ) {

	float d = v.Dot ( p.mNorm ) + p.mDist;
	return (( d < FP_NEAR ) && ( d > -FP_NEAR )) ? 0.0f : d;
}
Пример #10
0
//----------------------------------------------------------------//
void USPlane3D::Init ( USVec3D& p, USVec3D& n ) {
	mNorm = n;
	mDist = -p.Dot ( n );
}