Valrus
03-12-2006 08:06:57
I am having a heck of a time getting the physics working properly in my game here, my main problem is that, well nothing seems to be updating. Bodies are getting created but just hang in the air and nothing moves when I run into it, no gravity is happening. My camera body will run into things as I move it around but nothing will happen other then just keeping me from moving through the body.
I'm using a bunch of code that I believe came from these forums, FPSCam and a NewtonFrameListener class.
some code...
Setting things up....the table I create does nothing.
frame started...
The Frame Listener...
Setting up the collision body...
Any ideas?
P.S. also having some trouble with bodies not attaching to nodes properly, I'll create the body and attach it to a scenenode but then it won't move with the node, might be realted? I don't know right now.
I'm using a bunch of code that I believe came from these forums, FPSCam and a NewtonFrameListener class.
some code...
Setting things up....the table I create does nothing.
this->pWorld = new OgreNewt::World();
this->pWorld->setWorldSize(Ogre::Vector3(-1750, -1750, -1750), Ogre::Vector3(1750, 1750, 1750));
pSceneMgr->setAmbientLight(Ogre::ColourValue(xLighting,xLighting,xLighting));
//pSceneMgr->setSkyBox(true,xSkyboxName);
//create the newton listener
pNewtonListener = new NewtonListener(this->pWorld,this->pSceneMgr,this->pRoot->getAutoCreatedWindow(),100,true);
this->pRoot->addFrameListener(pNewtonListener);
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
//Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("HUD");
//this->pGUIManager->loadImageSet("HUD.imageset");
//this->pGUIManager->loadLayout("HUD.xml");
this->pLevel = new RenderableEntity(xLevelMeshName, xLevelName, this->pSceneMgr, false);
this->pLevel->initTreeCollision(this->pWorld);
//create a table!
table1 = new RenderableEntity("CrapsTable.mesh","table1",this->pSceneMgr,false);
table1->initConvexCollision(this->pWorld,100,Ogre::Vector3(0,-10,0));
table1->getBody()->setPositionOrientation(Ogre::Vector3(200,0,0),Ogre::Quaternion::IDENTITY);
//table1->getBody()->translate(100,-50,0);
frame started...
bool StateSingleplayer::frameStarted(const Ogre::FrameEvent &evt)
{
pNewtonListener->frameStarted(evt);
ourPlayer->frameStarted(evt);
if (this->quit) return false;
return true;
}
The Frame Listener...
class NewtonListener : public FrameListener
{
public:
NewtonListener(OgreNewt::World *world, SceneManager *sceneMgr, RenderWindow *win, Real updateFrameRate, bool debug)
{
mWorld = world;
mDesiredFrameRate = updateFrameRate;
mUpdate = 1.0f / mDesiredFrameRate;
mElapsed = 0.0f;
mDebug = debug;
if (mDebug)
{
OgreNewt::Debugger::getSingleton().init(sceneMgr);
mInputDevice = PlatformManager::getSingleton().createInputReader();
mInputDevice->initialise(win,true,false);
}
else
{
mInputDevice = NULL;
}
}
bool frameStarted(const FrameEvent &evt)
{
if (!(Global::pausePhysics))
{
mElapsed += evt.timeSinceLastFrame;
LogManager::getSingleton().logMessage("[OgreNewt] Elapsed: "+Ogre::StringConverter::toString(mElapsed)+ " Update: "+Ogre::StringConverter::toString(mUpdate));
Real count = 0;
if ((mElapsed > mUpdate) && (mElapsed < (1.0f)) )
{
while (mElapsed > mUpdate)
{
mWorld->update( mUpdate );
mElapsed -= mUpdate;
count++;
}
}
else
{
if (mElapsed < (mUpdate))
{
//Not enough time has passed, so ignore.
}
else
{
mWorld->update( mElapsed );
count++;
}
}
LogManager::getSingleton().logMessage("[OgreNewt] Newton world updated this loop: "+Ogre::StringConverter::toString(count));
}
else
{
LogManager::getSingleton().logMessage("[OgreNewt] Newton paused.");
}
//Debugging lines.
if (mDebug)
{
mInputDevice->capture();
if (mInputDevice->isKeyDown(Ogre::KC_F3))
{
OgreNewt::Debugger::getSingleton().showLines(mWorld);
}
else
{
OgreNewt::Debugger::getSingleton().hideLines();
}
}
return true;
}
Setting up the collision body...
OgreNewt::ConvexCollision *pCol;
pCol = new OgreNewt::CollisionPrimitives::ConvexHull(world, this->pNode);
this->pBody = new OgreNewt::Body(world, pCol);
pCol->calculateInertialMatrix(this->inertia, this->centreOfMass);
delete pCol;
this->pBody->setMassMatrix(this->mass, this->inertia);
this->pBody->setAutoFreeze(false);
this->pBody->attachToNode(this->pNode);
this->pBody->setStandardForceCallback();
Any ideas?
P.S. also having some trouble with bodies not attaching to nodes properly, I'll create the body and attach it to a scenenode but then it won't move with the node, might be realted? I don't know right now.