Mass Gravity Issues

Fdot
Posts: 6
Joined: Wed Sep 29, 2010 8:02 am

Mass Gravity Issues

Post by Fdot »

Hi,

I got some problems with the right mass and gravity. If I hit an object it flies away. Or if I jump (lift me a little up) I slide slowly down. So my question is how to set the values right?

I actually set the gravity to

Code: Select all

_dynamicsWorld->setGravity(btVector3(0,-99.8,0));
I think -9.8 or -10 would be better, but then it's like I'm standing in the sky.

The init code for the physics object:

Code: Select all

	void BodyHandler::AddPhysicsBody(std::string strObjectID, bool bolStatic)
	{
		Ogre::SceneNode* ptrSceneNode = Scenegraph::GetSingleton().GetSceneNode(strObjectID);
		Ogre::Entity* mEntity = Scenegraph::GetSingleton().GetEntity(strObjectID);

		BtOgre::StaticMeshToShapeConverter converter(mEntity);
		btCollisionShape* ptrShape;
		btScalar mass;

		/*
		 * Static RigidBody - doesn't move
		 */
		if(bolStatic)
		{
			ptrShape = converter.createSphere();
			mass = 0;
		}

		/*
		 * Dynamic Body
		 */
		else
		{
			ptrShape = converter.createConvex();
			mass = 10000;
		}

		btVector3 inertia;
		ptrShape->calculateLocalInertia(mass, inertia);

		BtOgre::RigidBodyState *state = new BtOgre::RigidBodyState(ptrSceneNode);

		btRigidBody* mBody = new btRigidBody(mass, state, ptrShape, inertia);


		mBody->setInvInertiaDiagLocal(btVector3(0,0,0));
		mBody->updateInertiaTensor();

		mapBodies[ ptrSceneNode->getName() ] = mBody;

		PhysicsController::GetSingleton().GetPhysicsWorld()->addRigidBody(mBody);
	}
I use Ogre3D and BtOGre (http://www.ogre3d.org/forums/viewtopic.php?f=5&t=46856).

What do I wrong?
Fdot
Posts: 6
Joined: Wed Sep 29, 2010 8:02 am

Re: Mass Gravity Issues

Post by Fdot »

I build the stepSimulation part a bit better, but that didn't fix the problem:

Code: Select all

btScalar timestep = Clock::GetSingleton().GetTime() - _lngTime;
_lngTime = Clock::GetSingleton().GetTime();
btScalar ts = timestep/1000000;
btScalar fixedTimeStep=btScalar(1.)/btScalar(60.);
int maxSubSteps = ts/fixedTimeStep + 1;
_dynamicsWorld->stepSimulation(ts, maxSubSteps, fixedTimeStep);
I really have no clue what to do or where I can fix that :(

edit: I work on Linux.
User avatar
gennoevus
Posts: 39
Joined: Sun Oct 10, 2010 4:39 am

Re: Mass Gravity Issues

Post by gennoevus »

Hi,

I'm new too, so don't take what I say as advice, but think of it as 'possible things to try.'

The first thing I notice is that your timestep is very very small. Why are you dividing it my a million?

Code: Select all

btScalar ts = timestep/1000000;
What happens if you do this:

Code: Select all

btScalar ts = timestep;
Also, maybe you should start setting your masses, etc. to sane values. A mass of 10000 is crazy! Unless it is supposed to be a large tank or something ... Test with masses closer to 1, and objects that are about 1 unit in dimensions. (just until you have everything working) It would also be better so set your gravity back to -9.8. Instead of changing these values to work with the simulation, change the simulation to work with these values.

...Just some ideas. I didn't read through every line of code so I may have missed something but hopefully that is something you can start with?