I've read a lot of things on the virtual functions, but I'm still not able to get something to work how I want.
Basically, I've got the following class:
class Body
{
protected:
scene::ISceneNode* Model;
virtual void setModel();
public:
Body( core::vector3df Position, core::vector3df Rotation );
};
Body::Body( core::vector3df Position, core::vector3df Rotation )
{
CurrentThrust = 0;
setModel();
Model->setPosition( Position );
Model->setRotation( Rotation );
}
void Body::setModel()
{
Model = Engine::Instance->GetSceneManager()->addCubeSceneNode();
Model->setMaterialFlag( video::EMF_LIGHTING, false );
}
I am create new classes inheriting Body, and the idea is that I override "setModel()" in those classes, and the constructor will load my new model, instead of the default; like below
class Craft : public Body
{
protected:
virtual void setModel();
public:
Craft( core::vector3df Position, core::vector3df Rotation );
};
Craft::Craft( core::vector3df Position, core::vector3df Rotation ) : Body(Position, Rotation)
{
// Other stuff
}
void Craft::setModel()
{
Model = Engine::Instance->GetSceneManager()->addAnimatedMeshSceneNode( Engine::Instance->GetSceneManager()->getMesh("resource/X-17 Viper flying.obj") ); // addCubeSceneNode();
Model->setMaterialFlag( video::EMF_LIGHTING, false );
Model->setScale( core::vector3df(0.1f) );
}
However, it always creates a Cube model instead of my Viper mode when I create a new instance of Craft.
Is it possible to get virtual functions to work like I'm thinking? or do I need to just change my constructors to create the models in their respective classes?
Thanks