19.1 3D Scenes


19.1 3D Scenes

In Chapter 17 a 2D ClanLib scene manager was created to manage and control 2D graphics in a single scene using a layer system, similar to the layers used by popular photo applications like GIMP and Photoshop. Here, 2D images such as surfaces and sprites were arranged on transparent layers. The layers were arranged in a specific z-order stack and the list of layers were said to be child nodes of the whole scene. Each image or sprite was said to be a child of the layer, and consequently the layer was the parent of the images and sprites. Using this hierarchical system proved to be effective because each object could define its position as a relative (x, y) offset from its parent, and every object could express its location in a single coordinate system.

OGRE 3D uses a similar concept and applies this to 3D objects arranged in a scene. Like in ClanLib, a 3D scene is a single coordinate system inside which objects exist. For OGRE, the 3D coordinate system is like real-world coordinates. Everything has an (x, y, z) position measured from the origin at (0, 0, 0). When the scene is painted (rendered) to the display on each frame the view from which the scene is seen by the gamer is the view from a camera. In OGRE, scenes are viewed via cameras, which have a position within the scene like any other object.

19.1.1 Entities

A scene is populated by objects, and an object in OGRE is called an entity. These can be models (meshes) like a goblin, robot, or whatever. Usually, these are modeled in 3D rendering applications like 3ds Max or Blender 3D, and then imported into OGRE. An entity is similar to a surface or sprite in a 2D system. As we shall see, OGRE represents entities using the entity class. A single model may itself reference many different resources. Resources can be all kinds of different file data, and most commonly these will be textures. Let's take the example of a brick wall. The mesh for a brick wall might simply be an appropriately sized box. The texture will be a flat, 2D image of a brick wall, and this image will then be wallpapered onto the surface of the box mesh to appear as though it were actually made from bricks.

19.1.2 Scene Nodes

In our 2D system, sprite and image objects were collected into transparent layers that could be stacked atop one another. Since OGRE is three dimensional, the layer model is not appropriate since a layer can exist only in two dimensions. Instead, OGRE organizes the scene in a hierarchical tree of scene nodes, like nodes in an XML file. Each node is an invisible anchor that has an (x, y, z) position, and any node may be a child of another. So each node can have many child nodes, and each node may have only one direct parent node. In a 3D system, scene nodes are analogous to layers and, like layers, objects such as entities need to be attached to scene nodes if a programmer wants them to be included in a scene. OGRE encapsulates scene nodes into the SceneNode class.




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