Strange problem with interpolation-substeps

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

Strange problem with interpolation-substeps

Post by Boron »

Hi,

I use a dynamic world to move bullets and detect collisions inside my space-rts. My internale game-tick is 100 ms and I'm calling

Code: Select all

mDynamicsWorld->stepSimulation(mTimer->getMilliseconds() / 1000.0f, 60);
	mTimer->reset();
everey tick. I want an interpolation for displaying a smooth movement of my bullets. The bullets are rigid-bodies and I apply a force to them to let them move. The problem is that the bullets are "jumping" in a 100ms-tick and their movement isn't smooth.
The motionstate for the bullets looks like that:

Code: Select all

BulletMotionState::BulletMotionState(DataStructures::BulletData * bulletData)
{
	mBillboard = 0;
	mBulletData = bulletData;
	mTransform.setOrigin(btVector3(bulletData->origin().x, bulletData->origin().y, bulletData->origin().z));
	mTimer = new Ogre::Timer();
}

BulletMotionState::~BulletMotionState(void)
{
}

void BulletMotionState::getWorldTransform(btTransform &worldTrans) const
{
	worldTrans.setIdentity();
	worldTrans.setOrigin(mTransform.getOrigin());
}

void BulletMotionState::setWorldTransform(const btTransform &worldTrans)
{

	if(mBillboard)
	{
		btVector3 pos = worldTrans.getOrigin();
		pos = pos * SCENE_SCALE;

		std::cout << "\ntimer: " << Tools::IntToString((int)mTimer->getMilliseconds()) << "    Pos: " << Tools::FloatToString(pos.x()) << ", " << Tools::FloatToString(pos.z());
		mTimer->reset();
		
		mBillboard->setPosition(pos.x(), pos.y(), pos.z());
	}
}
As you can see, I use the Ogre3D-engine and I use billboards to represent the bullets.
I have an Ogre::Timer to see, how many ms are gone between two position-changes of the bullet and to debug my problem, I make a console-output. It looks like that:

Code: Select all

timer: 103    Pos: 249.856, 7.22558
timer: 0    Pos: 249.858, 7.32275
timer: 0    Pos: 249.861, 7.41993
timer: 0    Pos: 249.864, 7.51711
timer: 0    Pos: 249.867, 7.61429
timer: 0    Pos: 249.87, 7.71146
timer: 103    Pos: 249.871, 7.72896
timer: 0    Pos: 249.874, 7.82613
timer: 0    Pos: 249.877, 7.92331
timer: 0    Pos: 249.88, 8.02049
timer: 0    Pos: 249.883, 8.11767
timer: 0    Pos: 249.885, 8.21484
timer: 0    Pos: 249.888, 8.31202
timer: 101    Pos: 249.892, 8.41503
timer: 0    Pos: 249.894, 8.51221
timer: 0    Pos: 249.897, 8.60939
timer: 0    Pos: 249.9, 8.70656
timer: 0    Pos: 249.903, 8.80374
timer: 0    Pos: 249.906, 8.90092
timer: 108    Pos: 249.911, 9.04474
You can see, that the position is interpolated correctly. There are 6 substeps in one application-tick (remember the stepSimulation-call above). It seems, that the setWorldTransform-method is called six times in a row instead of evenly distributed calls within one simulation step (of 100ms).

I hope you can help me with this problem, because I don't see the mistake I make here ...


Thanks in advance

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

Re: Strange problem with interpolation-substeps

Post by Boron »

I still have this problem :(