Problem with zero gravity ins space-simulation

Boron
Posts: 5
Joined: Mon Jul 12, 2010 7:15 pm

Problem with zero gravity ins space-simulation

Post by Boron »

Hi together,

I'm new to BulletPhysics and I have the problem that my objects (spaceships) are "falling down" when my simulation starts. I set the gravity of my DynamicWorld to zero and I don't apply it anywhere. Also there are no forces in my world. It seems to be totally irrelevant to which value I set the gravity of the world - the objects are always falling in the same direction (positive y-direction). Here's some code:

The init-method

Code: Select all

	
[...]

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btConstraintSolver *solver = new btSequentialImpulseConstraintSolver();

mDynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
mDynamicsWorld->setGravity(btVector3(0,0,0));

btRigidBody::btRigidBodyConstructionInfo info(
	mass(),          // > zero
	mMotionState = new Scene::InterObjectMotionState(),
	new btBoxShape(btVector3(400, 80, 90)),
	btVector3(position().x, position().y, position().z)
);

mRigidBody = new btRigidBody(info);

mDynamicsWorld->addRigidBody(mRigidBody);

[...]
My tick-method

Code: Select all

[...]

// timer contains time since last tick
mDynamicsWorld->stepSimulation(mTimer->getMilliseconds() / 1000.0f, 1);
mTimer->reset();

[...]
My MotionState for Interpolation with Ogre

Code: Select all

InterObjectMotionState::InterObjectMotionState(void)
{
}

InterObjectMotionState::~InterObjectMotionState(void)
{
}

void InterObjectMotionState::getWorldTransform(btTransform &worldTrans) const
{
	//worldTrans = mTransform;
}

void InterObjectMotionState::setWorldTransform(const btTransform &worldTrans)
{
	if(mSceneNode)
	{
		btVector3 const & pos = worldTrans.getOrigin();
		mSceneNode->setPosition(pos.x(), pos.y(), pos.z());
		std::cout << "\ny: " << worldTrans.getOrigin().y();        // y always gets larger, but why?
	}
}

I really hope you can help me. I tried a lot, I looked at the demo's code, in the wiki-tutorials, the manual and the API but it seems, that i'm too stupid to find the answer there :?


TIA,

Boron
Boron
Posts: 5
Joined: Mon Jul 12, 2010 7:15 pm

Re: Problem with zero gravity ins space-simulation

Post by Boron »

Ok, I found the problem myself I think: Now I initiate the transform inside the MotionState with the identity-matrix for rotation and the initial position of the object as the origin. The ships are no longer falling into the endless space :-).