Castle Game Engine Documentation
Total Page:16
File Type:pdf, Size:1020Kb
Castle Game Engine documentation Michalis Kamburelis Castle Game Engine documentation Michalis Kamburelis Copyright © 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Michalis Kamburelis You can redistribute and/or modify this document under the terms of the GNU General Public License [http://www.gnu.org/licenses/gpl.html] as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Table of Contents Goals ....................................................................................................................... vii 1. Overview of VRML ............................................................................................... 1 1.1. First example ............................................................................................... 1 1.2. Fields .......................................................................................................... 3 1.2.1. Field types ........................................................................................ 3 1.2.2. Placing fields within nodes ................................................................ 5 1.2.3. Examples .......................................................................................... 5 1.3. Children nodes ............................................................................................. 7 1.3.1. Group node examples ........................................................................ 7 1.3.2. The Transform node ........................................................................ 10 1.3.3. Other grouping nodes ...................................................................... 12 1.4. DEF / USE mechanism ............................................................................... 13 1.4.1. VRML file as a graph ..................................................................... 17 1.5. VRML 1.0 state ......................................................................................... 17 1.5.1. Why VRML 2.0 is better ................................................................. 21 1.6. Other important VRML features ................................................................. 23 1.6.1. Inline nodes .................................................................................... 23 1.6.2. Texture transformation ..................................................................... 24 1.6.3. Navigation ...................................................................................... 27 1.6.4. IndexedFaceSet features ................................................................... 28 1.6.5. Prototypes ....................................................................................... 30 1.6.6. X3D features ................................................................................... 31 1.6.7. Events mechanism ........................................................................... 32 1.6.8. Scripting ......................................................................................... 35 1.6.9. More features .................................................................................. 36 2. Scene Manager ..................................................................................................... 38 2.1. Scene manager, and basic example of using our engine ................................ 38 2.2. Manage your own scene manager ............................................................... 39 2.3. 2D controls manager .................................................................................. 40 2.4. Custom viewports ...................................................................................... 40 3. Reading, writing, processing VRML scene graph ................................................... 42 3.1. TVRMLNode class basics .......................................................................... 42 3.2. The sum of VRML 1.0 and 2.0 ................................................................... 43 3.3. Reading VRML files .................................................................................. 46 3.4. Writing VRML files ................................................................................... 47 3.4.1. DEF / USE mechanism when writing ............................................... 47 3.4.2. VRML graph preserving .................................................................. 48 3.5. Constructing and processing VRML graph by code ...................................... 49 3.6. Traversing VRML graph ............................................................................ 49 3.7. Geometry nodes features ............................................................................ 49 3.7.1. Bounding boxes .............................................................................. 49 3.7.2. Triangulating ................................................................................... 50 3.8. WWWBasePath property ............................................................................ 54 3.9. Defining your own VRML nodes ................................................................ 55 3.10. VRML scene ............................................................................................ 55 3.10.1. VRML shape ................................................................................. 55 3.10.2. Simple tree of shapes ..................................................................... 56 3.10.3. Events ........................................................................................... 56 3.10.4. Various comfortable routines .......................................................... 57 3.10.5. Caching ......................................................................................... 57 iii Castle Game En- gine documentation 3.10.6. Events and ChangedField notifications ............................................ 58 4. Octrees ................................................................................................................. 60 4.1. Collision detection ..................................................................................... 60 4.2. How octree works ...................................................................................... 61 4.2.1. Checking for collisions using the octree ............................................ 63 4.2.2. Constructing octree .......................................................................... 65 4.3. Octrees for dynamic worlds ........................................................................ 66 4.3.1. Transforming between world and local coordinates ............................ 67 4.3.2. The future — dynamic irregular octrees ............................................ 68 4.4. Similar data structures ................................................................................ 68 5. Ray-tracer rendering ............................................................................................. 70 5.1. Using octree .............................................................................................. 70 5.2. Classic deterministic ray-tracer ................................................................... 70 5.3. Path-tracer ................................................................................................. 71 5.4. RGBE format ............................................................................................. 72 5.5. Generating light maps ................................................................................ 72 6. OpenGL rendering ................................................................................................ 76 6.1. VRML lights rendering .............................................................................. 76 6.1.1. Lighting model ................................................................................ 76 6.1.2. Rendering lights .............................................................................. 77 6.2. Geometry arrays ......................................................................................... 78 6.2.1. Rendering using geometry arrays and VBO ...................................... 79 6.2.2. Caching of shapes arrays and VBOs ................................................. 79 6.3. Basic OpenGL rendering ............................................................................ 81 6.3.1. OpenGL resource cache ................................................................... 83 6.3.2. Specialized OpenGL rendering routines vs Triangulate approach ........ 83 6.4. VRML scene class for OpenGL .................................................................. 84 6.4.1. Material transparency using OpenGL alpha blending ......................... 85 6.4.2. Material transparency using polygon stipple ...................................... 88 6.4.3. Shape granularity ............................................................................ 89 7. Animation ............................................................................................................. 91 7.1. Interactive VRML: TCastleScene with ProcessEvents = true ...... 91 7.1.1. 3D formats support .......................................................................... 91 7.2. Non-interactive precalculated animation: TCastlePrecalculatedAn- imation ......................................................................................................... 91 7.2.1. 3D formats support .......................................................................... 92 7.2.2.