Skip to content

Scenes, Nodes and Components

opatut edited this page Jul 31, 2011 · 2 revisions

This tutorial should give an overview about architectural principles of the engine. You will not learn how to program a game from this tutorial, though you are encouraged to get to know the engine a bit first. You have been warned! For a list of all tutorials visit the Tutorials page in this wiki.

What are nodes?

A node is nothing more than a segment of the scene tree. There is the root node in each Scene, and other nodes can be attached to it as children. The depth of this tree is unlimited, and each node can have unlimited children.

Each node will have a position, rotation and scale. All child nodes inherit these from their parent and add their relative position, rotation and scale.

What are scenes?

A scene is basically a node that has an associated Ogre::SceneManager and a PhysicsWorld. Scenes are held by States.

What are components?

Components are modifiers for Nodes. Each node can have many different components adding functionality to the otherwise empty Node. This can be for example Meshes or Sounds in 3D space or other functionality modifying the properties or appearance of the Node.

Component callbacks

The components may trigger custom callbacks, e.g. a TriggerComponent waiting for a player to appear in a specified area can call the Triggered callback. There are 2 ways of subscribing to the callback:

Method 1: Signals & Slots

This method should be prefered.

TriggerComponent* comp = new TriggerComponent();
comp.BindSlot("Triggered", boost::bind(&MyClass::MyCallback));
mNode.AddComponent(comp);

Using boost::bind it is possible to create a signal for the Triggered slot.

Method 2: Inheritance from the Component

This should only be used when the callback should do the same for many instances of the Component. Inherit from the Component and overwrite the virtual OnTriggered() method.

class CustomTriggerComponent : public TriggerComponent { 
    // make your own constructor etc. here
    virtual void OnTriggered() { 
        // do your custom stuff 
    } 
}

mNode.AddComponent(new CustomTriggerComponent());