The examples all seem to manipulate the scene nodes directly and they are not really object oriented in design. Are there any object oriented game examples?
I was thinking of writing a domain layer with a world and linking each domain object to the scene nodes that would be effected by the domain? Then I would call update for each movable object in the game and it would make changes to the corresponding scene node? Once the world is updated, I could just render the scene?
Is this a valid approach? What your your recommend?
Thanks
Game Design using the Irrlicht Engine
-
Sean Doherty
- Posts: 40
- Joined: Tue Jul 20, 2004 12:21 am
Game Design using the Irrlicht Engine
Sean Doherty, BCS
www.FreelanceGames.com
www.FreelanceGames.com
Of course it is valid. Here is example I am using to load and control simple piece of space rock:
I call control function each loop.
Code: Select all
class rockObject
{
public:
rockObject(irr::IrrlichtDevice* device, const irr::c8 *filename,
float X=0, float Y=0, float Z=0, float x=0, float y=0, float z=0);
~rockObject();
void control();
protected:
irr::core::vector3df rotation;
irr::scene::IAnimatedMesh *mesh;
irr::scene::IAnimatedMeshSceneNode *node;
};
rockObject::rockObject(irr::IrrlichtDevice* device, const irr::c8 *filename,
float X, float Y, float Z, float x, float y, float z)
{
rotation = irr::core::vector3df(x, y, z);
mesh = device->getSceneManager()->getMesh(filename);
node = device->getSceneManager()->addAnimatedMeshSceneNode(mesh);
if (node)
{
node->setMaterialFlag(irr::video::EMF_LIGHTING, true);
node->setPosition(irr::core::vector3df(X,Y,Z));
}
}
rockObject::~rockObject()
{
}
void rockObject::control()
{
irr::core::vector3df r = node->getRotation();
r += rotation;
node->setRotation(r);
}Better than that would be to use a base class, Object, that the other objects could inherit from. Then, if you ever needed to perfom an action on a type of object that is reused a lot you could just use the base class.
For example, a loading function. You could have:
Object* rock = loadObject(rockObject);
Whereby you could load the filename of the mesh into the rock object and so have one modular function that is easiy extendable.
The object class may look like:
class Object
{
public:
virtual void control() = 0;
virtual void setsetMeshLoc(c8* file) = 0;
virtual c8* getMeshLoc() = 0;
protected:
c8* meshLoc;
}
Then you could just inherit from object and know that any Object you create will have a control function, a set mesh and get mesh function so that you could perform the same action on any type of mesh, using the same functions over and over again. In that way you would need to write much less code every time you add another type of Object. That's the great thing about OO, it can simplfy the amount of code you write significantly.
For example, a loading function. You could have:
Object* rock = loadObject(rockObject);
Whereby you could load the filename of the mesh into the rock object and so have one modular function that is easiy extendable.
The object class may look like:
class Object
{
public:
virtual void control() = 0;
virtual void setsetMeshLoc(c8* file) = 0;
virtual c8* getMeshLoc() = 0;
protected:
c8* meshLoc;
}
Then you could just inherit from object and know that any Object you create will have a control function, a set mesh and get mesh function so that you could perform the same action on any type of mesh, using the same functions over and over again. In that way you would need to write much less code every time you add another type of Object. That's the great thing about OO, it can simplfy the amount of code you write significantly.
If you're after object oriented game engine ideas then you should check out gamedev.net and gamasutra.com which both contain many useful articles on the subject of game engine design. You probably won't be able to find anything irrlicht specific but you will find that a lot of people have tackled similar problems from different angles.
The main thing is to get something finished that the player can actually play.
The main thing is to get something finished that the player can actually play.