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!
[SOLVED] Rigid Body Rotation
-
- Posts: 19
- Joined: Thu Jun 28, 2012 5:06 pm
[SOLVED] Rigid Body Rotation
Last edited by CireNeikual on Fri Jun 29, 2012 1:28 pm, edited 1 time in total.
Re: Rigid Body Rotation
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.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!
-Josh
-
- Posts: 19
- Joined: Thu Jun 28, 2012 5:06 pm
Re: Rigid Body Rotation
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:
And here is how I retrieve the angles:
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:
Code: Select all
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));
Code: Select all
btTransform transform;
m_pMotionState->getWorldTransform(transform);
// Update box model
m_pModel->SetPosition(cons(transform.getOrigin()));
m_pModel->SetRotation(cons(transform.getRotation()));
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:
Re: Rigid Body Rotation
Code: Select all
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));
Code: Select all
btVector3 inertia;
m_pCollisionShape->calculateLocalInertia(mass, intertia);
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, m_pMotionState, m_pCollisionShape,inertia);
-
- Posts: 19
- Joined: Thu Jun 28, 2012 5:06 pm
Re: Rigid Body Rotation
Aha, I see how it works now ! Thanks for the help!