예제 #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;
}
예제 #2
0
//----------------------------------------------------------------//
void ZLQuaternion::Multiply ( const ZLQuaternion& rhs ) {

	ZLVec3D cross;
	cross.Cross ( mV, rhs.mV );
	
	ZLVec3D resultVec;
	resultVec.Init ( rhs.mV );
	resultVec.Scale ( mS );
	
	ZLVec3D scaledVec;
	scaledVec.Init ( mV );
	scaledVec.Scale ( rhs.mS );
	
	resultVec.Add ( scaledVec );
	resultVec.Sub ( cross );
	
	mS = mS * rhs.mS - mV.Dot ( rhs.mV );
	mV.Init ( resultVec );
	
}
//----------------------------------------------------------------//
ZLVec3D MOAIAnimCurveVec::GetCurveDelta () const {

	ZLVec3D delta;

	u32 size = this->mKeys.Size ();
	if ( size > 1 ) {
		delta = this->mSamples [ size - 1 ];
		delta.Sub ( this->mSamples [ 0 ]);
	}
	else {
		delta.Init ( 0.0f, 0.0f, 0.0f );
	}
	return delta;
}
예제 #4
0
파일: GIIHelper.cpp 프로젝트: pixpil/gii
int GIIHelper::_setWorldLoc( lua_State *L ){
	MOAILuaState state (L);
	if ( !state.CheckParams ( 1, "UN" )) return 0;
	MOAITransform* dst = state.GetLuaObject< MOAITransform >(1, true);
	float x = state.GetValue< float >( 2, 0.0f );
	float y = state.GetValue< float >( 3, 0.0f );
	float z = state.GetValue< float >( 4, 0.0f );
	ZLVec3D loc;
	loc.Init( x, y, z );		
	const ZLAffine3D* inherit = dst->GetLinkedValue < ZLAffine3D* >( PACK_ATTR ( MOAITransformBase, MOAITransformBase::INHERIT_TRANSFORM ), 0 );	
	if( inherit ) {
		ZLAffine3D inverse;
		inverse.Inverse( *inherit ); 
		inverse.Transform( loc );
	}
	dst->SetLoc( loc );	
	dst->ScheduleUpdate();
	return 0;
}