vehicle

yan007

12-04-2006 01:46:46

hello,
i woulk like to make a vehicle, therefor i want to understand te code of Demo05_SimpleVehicle

but i dont get this piece of code:

SimpleVehicle::SimpleTire::~SimpleTire()
{
// destroy entity, and scene node.
Ogre::Entity* ent = (Ogre::Entity*)m_node->getAttachedObject(static_cast<unsigned short>(0));
m_node->detachAllObjects();
m_node->getCreator()->destroyEntity( ent );
m_node->getParentSceneNode()->removeAndDestroyChild( m_node->getName() );
}

SimpleVehicle::~SimpleVehicle(void)
{
std::vector< SimpleTire* > toDelete;

// delete tire objects.
for (SimpleTire* tire = (SimpleTire*)getFirstTire(); tire; tire=(SimpleTire*)getNextTire(tire))
{
toDelete.push_back( tire );
}

while (!toDelete.empty())
{
SimpleTire* tire = toDelete.back();
delete tire;
toDelete.pop_back();
}

// finally, destroy entity and node from chassis.
Ogre::Entity* ent = (Ogre::Entity*)m_chassis->getOgreNode()->getAttachedObject(static_cast<unsigned short>(0));
m_chassis->getOgreNode()->detachAllObjects();
m_chassis->getOgreNode()->getCreator()->destroyEntity( ent );
m_chassis->getOgreNode()->getParentSceneNode()->removeAndDestroyChild( m_chassis->getOgreNode()->getName() );

destroy();
}

i only know these two functions are destructors,

it would be nice if someone could explain this code, and also what a callback is, e.g.

// This is the important callback, which is the meat of controlling the vehicle.
void SimpleVehicle::userCallback()
{

// foop through wheels, adding torque and steering, and updating their positions.
for (SimpleTire* tire = (SimpleTire*)getFirstTire(); tire; tire=(SimpleTire*)getNextTire(tire))
{
// set the torque and steering! non-steering tires get the torque.

// is this a steering tire?
if (tire->mSteeringTire)
tire->setSteeringAngle( mSteering );
else
tire->setTorque( mTorque );

// finally, this command updates the location of the visual mesh.
tire->updateNode();
}

}