What makes this different than the tokamak tutorial is that my classes are not derived off the scenenode which makes a call to Tokamak every frame (and kills the framerate). I decoupled the physics updating and put it in a timer loop. This effectively quadrupled my own frame rate.
the files are here:
http://www.ping.net/snapshots/irrtokamak.zip
you can see it in action by downloading my ping binaries:
http://www.ping.net/snapshots/ping7.zip
and here is a short tutorial on how to use the classes:
first - we make a sim manager for tokamak
Code: Select all
TokamakSimManager* physicsmanager = new TokamakSimManager(1.0f,45.0f,200,1,0.0f,-10.0f,0.0f);
Code: Select all
pnode = new TokamakRigidBody(node,physicsmanager,50.0f,ETG_BOX);
pnode->updateDataFromNode();
Code: Select all
// set up the floor
floorbody = physicsmanager->sim->CreateAnimatedBody();
// determine bounding box info
irr::core::aabbox3d<f32> nodeBox = floornode->getBoundingBox();
irr::core::vector3df size = nodeBox.MaxEdge - nodeBox.MinEdge;
// Create and set tokamak objects
neGeometry* geom = floorbody->AddGeometry();
geom->SetBoxSize(size.X,100.0,size.Z);
floorbody->UpdateBoundingInfo();
neV3 pos;
pos.Set(0.0f, -562.0f, 0.0f);
floorbody->SetPos(pos);
Code: Select all
int lastFPS = -1;
bool first = true;
irr::u32 lasttime = device->getTimer()->getTime();
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,90,90,156));
smgr->drawAll();
driver->endScene();
if (first)
{
**call your initPNode on all your objects **
first = false;
}
else
{
irr::u32 currtime = device->getTimer()->getTime();
if ((currtime - lasttime) > 15)
{
physicsmanager->updateSimulation();
**call updatePhysicsNodes() on all pnodes **
lasttime = currtime;
int fps = driver->getFPS();
if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Ping.net (%s)(fps:%d)",
driver->getName(), fps);
device->setWindowCaption(tmp);
lastFPS = fps;
}
}
}
}
that's it - the default on all rigidbodies is to use a box for collision - you can set it to be a cylinder or sphere if you wish (just look at the enumerated types in TokamakRigidBody
on my to do list:
- i might make a list of rigidbodies inside the SimManager so you dont have to manage your own list - one call to updateSimulation will take care of everything
- as you can see, i cannot call initPhysics until after the scene has rendered once - this is because the only way to get position info on an scenenode is from the AbsoluteTransform and this does not exist until after a render (this should be changed in irrlicht by the way!)
- add AnimatedBodies, Joints and Breakable objects
- right now i only pass position info into Tokamak - i should also convert and pass the rotation info for each scenenode
enjoy!
[/code]