OGRE (Object-Oriented Graphics Rendering Engine)

Our First Scene Node and Entity

 

A ship in space

What use is outer space if there are no space ships in it? Its time to make something that we can fly around in. We are going to do this by creating instances of two object types. Entities and Scene Nodes.

Member variables

Create some member variables to store pointers to the Scene Node and Entity for use later.

	Entity* mShip;
SceneNode* mShipNode;

Entities

An Entity in Ogre is a moveable object based on a mesh. These meshes are loaded through the Resource Manager and its position is determined by a Scene Node that it is attached to. To create our ship, add a line into the createScene method in SpaceApplication.h (after setting the sky box)

	mShip = mSceneMgr->createEntity("razor", "razor.mesh");

Just like the skybox, we supply a resource name to the Scene Manager and it will locate it. In this case it is the name of a mesh file (razor.mesh) which is found in the Media directory. Another important thing to note about we just did, we gave the entity a name. This name (razor) has to be unique within the application or the Scene Manager will give you an error.

The Scene Node

As mentioned above, Entities attach to Scene Nodes which dictate their position in the scene. Scene Nodes can be attached to other tree nodes to create a type of positional hierachy, but for the purposes of this tutorial just one will do.

To create this Scene Node we ask the root node of the scene to create it for us. The root node is maintained by Ogre and every entity that is part of the scene is directly or indirectly attached to it. When we ask the root node to create the node for us we are saying that the root node is the node's parent. After creating it we set its position orientation relative to the scene node (effectively the absolute position in the scene as far as this tutorial goes, but not necessarily true in other circumstances).

	mShipNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

Almost there... attach the ship Entity to the Scene Node.
	mShipNode->attachObject(mShip);

Lighting

Lastly, we have to turn on some lights or you won't be able to see anything. Lets just use some ambient lighting supplied by the Scene Manager for now. Place this line at the start of createScene.

	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

Compile and run. Have a walk around the ship.

Back to Index   << Previous section Next section >>