Align RigidBody from Normal

GLPhysx
Posts: 14
Joined: Sat Nov 28, 2009 11:28 pm

Align RigidBody from Normal

Post by GLPhysx »

I am using a capsule shape with setAngularFactor( 0.0f ), so I have to align the orientation of by rigidbody manually...

I have the following code:

Code: Select all


btVector3 y,
		  fw,
		  right,
		  up;

y.setValue( 0.0f, 0.0f, 1.0f );	
fw.setValue( ground_normal.x, ground_normal.y, ground_normal.z );

if( fabsf( fw.z() ) - fabsf( y.z() ) < 0.1f )
{ y.setValue( 0.0f, 1.0f, 0.0f ); }

right = btCross( y, fw ).normalize();
up = btCross( fw, right).normalize();


	btMatrix3x3 rot(right.x(), up.x(), fw.x(),
					right.y(), up.y(), fw.y(),
					right.z(), up.z(), fw.z() );

m_btRigidBody->getWorldTransform().setBasis( rot );

It is basically working but sometimes the object is become really jaggy or start jumping for no particular reason... Am I missing something?
GLPhysx
Posts: 14
Joined: Sat Nov 28, 2009 11:28 pm

Re: Align RigidBody from Normal

Post by GLPhysx »

Allright nevermind... a little lerp did the trick...