19.2 Creating 3D Scenes


19.2 Creating 3D Scenes

An OGRE scene node hierarchy is organized in a specific way. At the top of the hierarchy there is a root scene node (the ultimate ancestor), and beneath this there may be any number of scene nodes that in turn may contain more child nodes. Each scene node may also have attached to it any number of entities-meshes and other objects of the scene-that are to be included as part of the scene. The two objects responsible for creating and managing scenes in OGRE are SceneNode and Entity.

Let's illustrate the process of creating an example 3D scene that contains a single robot. The robot.mesh file is provided with the OGRE SDK and contains a sample mesh of a robot. It can be found in the media folder where OGRE was installed.

19.2.1 Create Entity

To load this mesh into a 3D scene, an Entity object needs to be created. This can be achieved by calling the createEntity method of the scene manager class. This class manages a scene, just like the ClanLib scene manager. Consider the following code, which is part of the createScene method of ExampleApplication. The createEntity method of the scene manager accepts a file name to a mesh file.

      Entity *Entity = mSceneMgr->createEntity("Robot", "Robot.mesh"); 

19.2.2 Create SceneNode

A SceneNode can contain Entities, and attaching them to a SceneNode makes them part of a scene. To create a new SceneNode in the scene and then attach an Entity to this SceneNode, consider the following code:

      SceneNode *Node = mSceneMgr->getRootSceneNode()->createChildSceneNode();      Node->attachObject(Entity); 

The code to create an Entity and SceneNode and then to make the Entity part of the scene follows.

      class SampleApp : public ExampleApplication      {      public:         // Basic constructor         SampleApp()         {}         AppListener *m_AppListener;      protected:         // Just override the mandatory create scene method         void createScene(void)         {            SceneNode *Node = mSceneMgr->getRootSceneNode()->createChildSceneNode();            Entity *Entity = mSceneMgr->createEntity("Robot", "Robot.mesh");            Node->attachObject(Entity);         }      }; 




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net