# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: [SOLVED] Rigid Body RotationPosted: Thu Jun 28, 2012 5:09 pm

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

 Post subject: Re: Rigid Body RotationPosted: Thu Jun 28, 2012 11:14 pm

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

 Post subject: Re: Rigid Body RotationPosted: Fri Jun 29, 2012 1:38 am

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:

Top

 Post subject: Re: Rigid Body RotationPosted: Fri Jun 29, 2012 10:38 am

Joined: Mon Jul 19, 2010 3:11 am
Posts: 49
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

 Post subject: Re: Rigid Body RotationPosted: Fri Jun 29, 2012 1:28 pm

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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Google [Bot] and 4 guests

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

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities
Powered by phpBB® Forum Software © phpBB Group