Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jun 28, 2012 5:09 pm 
Offline

Joined: Thu Jun 28, 2012 5:06 pm
Posts: 17
Super N00b question: How can I get rigid bodies to rotate? They move around fine, and tumble around, but never rotate! When I print the rotation quaternion, it is always just the initial rotation I gave the body.

Thank you for your time!


Last edited by CireNeikual on Fri Jun 29, 2012 1:28 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Rigid Body Rotation
PostPosted: Thu Jun 28, 2012 11:14 pm 
Offline

Joined: Fri Jan 06, 2012 1:04 pm
Posts: 7
CireNeikual wrote:
Super N00b question: How can I get rigid bodies to rotate? They move around fine, and tumble around, but never rotate! When I print the rotation quaternion, it is always just the initial rotation I gave the body.

Thank you for your time!


There are several ways to get a btRigidBody to spin. Call any of applyTorque, applyAngularImpulse, or setAngularVelocity and you can make the a rigidbody rotate, but make sure that you have initialised the inertia of the rigidbody first.

-Josh


Top
 Profile  
 
 Post subject: Re: Rigid Body Rotation
PostPosted: Fri Jun 29, 2012 1:38 am 
Offline

Joined: Thu Jun 28, 2012 5:06 pm
Posts: 17
Thanks for the response, but I meant having it rotate when it collides with something, like when a box is tumbling down a slope. It should happen normally without me doing anything, so it must be something with how I retrieve the angles. Right now, if a box falls on the ground at an angle, it will just stay at that angle, no matter what. I set up the body like this:

Code:
m_pCollisionShape = new btBoxShape(bt(m_pModel->GetAABB().GetHalfDims()));

   m_pMotionState = new btDefaultMotionState(btTransform(btQuaternion(0.2f, 0.6f, 0.1f, 1.0f).normalized(), bt(m_aabb.GetCenter())));

   const float mass = 1.0f;

   m_pCollisionShape->calculateLocalInertia(mass, btVector3(0.0f, 0.0f, 0.0f));

   btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, m_pMotionState, m_pCollisionShape, btVector3(0.0f, 0.0f, 0.0f));

   m_pRigidBody = new btRigidBody(rigidBodyCI);

   m_pPhysicsWorld->m_pDynamicsWorld->addRigidBody(m_pRigidBody);

   m_pRigidBody->setAngularVelocity(btVector3(0.2f, 0.5f, 0.2f));


And here is how I retrieve the angles:

Code:
btTransform transform;
   m_pMotionState->getWorldTransform(transform);
   
   // Update box model
   m_pModel->SetPosition(cons(transform.getOrigin()));

   m_pModel->SetRotation(cons(transform.getRotation()));


When I print transform.getRotation(), the values are always just what I initialized it to, it never changes over time when the boxes tumble around. transform.getOrigin() updates just fine.

EDIT: Actually, it seems that it is not how I am retrieving the rotations, but the simulation just doesn't have any! All rigid bodies have infinite angular momentum or something, since I can do ridiculous stuff like this:

Image


Top
 Profile  
 
 Post subject: Re: Rigid Body Rotation
PostPosted: Fri Jun 29, 2012 10:38 am 
Offline

Joined: Mon Jul 19, 2010 3:11 am
Posts: 48
Code:
 
m_pCollisionShape->calculateLocalInertia(mass, btVector3(0.0f, 0.0f, 0.0f));

btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, m_pMotionState, m_pCollisionShape, btVector3(0.0f, 0.0f, 0.0f));


in this lines you got a bug, basicly you are passing zero vector as inertia and it should be vector calculated in first line as reference. Try that:
Code:
btVector3 inertia;
m_pCollisionShape->calculateLocalInertia(mass, intertia);

btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, m_pMotionState, m_pCollisionShape,inertia);


Top
 Profile  
 
 Post subject: Re: Rigid Body Rotation
PostPosted: Fri Jun 29, 2012 1:28 pm 
Offline

Joined: Thu Jun 28, 2012 5:06 pm
Posts: 17
Aha, I see how it works now :oops: ! Thanks for the help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group