Questions about bullet physics

Leadwerks
Posts: 7
Joined: Wed Jan 21, 2009 10:59 pm

Questions about bullet physics

Post by Leadwerks »

Hi, I have some questions about this physics SDK.

-Is a character controller provided? Where can I find a demo of this? Does it handle stairs and ramps correctly? Are there any outstanding issues the controllers have?

-Are there functions to calculate the torque (or velocity) required to make a rigid body oriented to an arbitrary rotation?

-Does the SDK have a C interface, or is it all C++ methods?

-Is a fixed/rigid joint implemented?

-Is motion smoothing automatic, or do I need to interpolate it myself between the last two physics update results?

I am quite far along with another physics library, but I have hit some dead ends that aren't getting any better. Thanks for your answers.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Questions about bullet physics

Post by Erwin Coumans »

Leadwerks wrote:Hi, I have some questions about this physics SDK.

-Is a character controller provided? Where can I find a demo of this? Does it handle stairs and ramps correctly? Are there any outstanding issues the controllers have?
Yes, see Bullet/Demos/CharacterDemo. It can be used as a starting point, but most developers will likely extend or replace it with their own version, tied to their own game logic.
-Are there functions to calculate the torque (or velocity) required to make a rigid body oriented to an arbitrary rotation?
There are functions to calculate required linear and angular velocity. Just use apply impulse and apply central impulse, or joint motors.
-Does the SDK have a C interface, or is it all C++ methods?
The C++ API of Bullet is recommended, but there is a partial C API too, see Bullet/Demos/BulletDinoDemo for example. If there are particular features you need in the C API, just let us know.
-Is a fixed/rigid joint implemented?
Yes, just use a btGeneric6DofConstraint and lock all linear and angular axis.
-Is motion smoothing automatic, or do I need to interpolate it myself between the last two physics update results?
It is automatic if you use the btMotionState to update the transform.

Hope this helps,
Erwin
gm09
Posts: 9
Joined: Fri Aug 05, 2011 1:27 am

Re: Questions about bullet physics

Post by gm09 »

Yes, just use a btGeneric6DofConstraint and lock all linear and angular axis.
How can I lock the axes? I'm trying to create a rigid joint between two rigid bodies as well and this is the piece of code I have:

Code: Select all

                btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));  
		btCollisionShape* colShape2 = new btBoxShape(btVector3(1,1,1)); 
                m_collisionShapes.push_back(colShape);
                m_collisionShapes.push_back(colShape2);

		btTransform startTransform; 
		startTransform.setIdentity();

		btScalar mass(1.f);

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

		btVector3 localInertia(0,0,0);
		if (isDynamic){
			colShape->calculateLocalInertia(mass,localInertia);
                        colShape2->calculateLocalInertia(mass,localInertia);
                }

                startTransform.setOrigin(btVector3(0,2,0)); 
                btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
                startTransform.setIdentity();
                startTransform.setOrigin(btVector3(0,4,2));
                btDefaultMotionState* myMotionState2 = new btDefaultMotionState(startTransform);
                btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
                btRigidBody::btRigidBodyConstructionInfo rbInfo2(mass,myMotionState2,colShape2,localInertia);
                btRigidBody* rigid_body1 = new btRigidBody(rbInfo);
                btRigidBody* rigid_body2 = new btRigidBody(rbInfo2);

                btTransform frameIn1, frameIn2;
                frameIn1 = btTransform::getIdentity();
                frameIn1.setOrigin(btVector3(btScalar(0.), btScalar(2.), btScalar(0.)));
                frameIn2 = btTransform::getIdentity();
                frameIn2.setOrigin(btVector3(btScalar(0.), btScalar(4.), btScalar(2.)));

                btGeneric6DofConstraint* pGen6DOF = new btGeneric6DofConstraint(*rigid_body1, *rigid_body2, frameIn1, frameIn2, true);
                pGen6DOF->setLimit(0, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLimit(1, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLimit(2, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLimit(3, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLimit(4, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLimit(5, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLimit(6, btScalar(0.0f), btScalar(0.0f));
                pGen6DOF->setLinearLowerLimit(btVector3(0.0f, 0.0f, 0.0f));
                pGen6DOF->setLinearUpperLimit(btVector3(0.0f, 0.0f, 0.0f));
                pGen6DOF->setAngularLowerLimit(btVector3(0.0f, 0.0f, 0.0f));
                pGen6DOF->setAngularUpperLimit(btVector3(0.0f, 0.0f, 0.0f));

                m_dynamicsWorld->addRigidBody(rigid_body1);
                m_dynamicsWorld->addRigidBody(rigid_body2);

                m_dynamicsWorld->addConstraint(pGen6DOF, true);
                pGen6DOF->setDbgDrawSize(btScalar(5.f));
It's not working though. The bodies are in the desired position but when I pull them around, they still drift apart/there are gaps between the bodies; what am I missing here?

Thanks,
gm09