**Cubes Project Report** **Heikki Ikäheimonen heikki.ikaheimonen@gmail.com** ![](2017-02-24_001_cubes_g3d_r1090__My_custom_scene.jpg) Introduction ============================================================= This project introduced three different ways of creating scenes from simple cubes, by directly editing data file, by using GUI editor and by programmatically generating the scene file. The project also had a warmup section to get familiar with the G3D engine and a questions section for testing understanding of the engine and aspects of programming. The project specification can be found from http://graphicscodex.com/projects/cubes/index.html System Overview ============================================================= The cubes project is based on the starter project from G3D engines sample projects. The projects main entry point is in the App class inheriting from GApp of the G3D engine. The project has only one other class, MySceneBuilder class that programmatically creates two of the required scenes on program startup, the staircase scene and a scene of my own designing. Other scenes are in scene folder under data-file as a .Scene.Any files created by hand. Major Class/Function | Description ---------------------|------------ [class App](../build/doc/class_app.html) | Initializes and runs the application and calls MySceneBuilder's build methods. [class MySceneBuilder](../build/doc/class_my_scene_builder.html) | Builds and saves custom scenes to a scene file. [MySceneBuilder::BuildStaircaseScene](../build/doc/class_my_scene_builder.html#a341d938f05fc1a32842c1c59c8520c09) | Builds the staircase scene file and saves to disk. [MySceneBuilder::BuildCubeTunnelScene](../build/doc/class_my_scene_builder.html#add9df378fb23c2643ada169f063e1aaf) | BuildScene creates and saves my custom scene to disk. Coordinate System ===================================================== The default 3d coordinate system in G3D is right handed. The following diagram describes x,y,z axes and the pitch, yaw and roll in the coordinate system. ************************************************************************************************* * +y * * ^ * * | * * | ◄╮ roll around z - axis * * pitch around x-axis ⤹ +-----> +x * * / ⤴ yaw around y -axis * * v * * +z * ************************************************************************************************* Results ===================================================== ![white cube translated and rotated](2017-02-24_000_cubes_g3d_r1090__.jpg) White cube scene showing one white cube rotated 45 degrees about vertical axis and translated -2 units on z-axis. ![cornell box scene](2017-02-19_001_cubes_g3d_r1090__cornell_box_with_white_skybox.jpg) Cornell box scene where walls and boxes are tranformed crate.obj objects. ![stairs scene](2017-02-19_000_cubes_g3d_r1090__stairs.jpg) Scene that is created in C++ code from MySceneBuilder::BuildStaircaseScene creating a spiralling stairs consisting of 50 scaled and textured cubes. ![My custom scene](2017-02-24_001_cubes_g3d_r1090__My_custom_scene.jpg) A Scene of my creation with depth of field blur giving it more artictic look. Custom Scene Process ===================================================== I wanted to make something abstract but simple and decided to make a tunnel made of cubes. I wanted to programmatically count the location of the cubes making the tunnel so I decided to create the scene in C++ by writing to std::ostream. I decided to create 36 stretched cubes in for loop, I chose 36 so I can rotate each equally 10 degrees when counting the location of the cube, since I chose tunnel I could count the location as point on a circle in x-y plane and increasing angle by 10 degree every loop. $$ x = r*cos(angle*i), y = r*sin(angle*i)$$ where r is range and i is the loop index from 0 to 35. ![tunnel made of cubes](2017-02-21_000_cubes_g3d_r1090__tunne_of_cubes.jpg) After this I wanted to add something to the middle of the tunnel. ![added cube](2017-02-22_000_cubes_g3d_r1090__added_cube.jpg) To make it look more interesting I started to experiment with materials. I also adjusted in the scene viewer the debug cameras settings for Depth of field to get more artistic look. After I was happy with DoF settings and camera location I pressed save in the GUI and checked the modified file. From the modified file I copied by hand the camera settings to the C++ class. The final scene had 40 cubes 36 making the tunnel and 4 making a cube object in middle, materials and also depth of field blur experimented from the debug camera gui. ![My custom scene](2017-02-24_001_cubes_g3d_r1090__My_custom_scene.jpg) Typeset Equation in Markdeep ===================================================== $$ \frac{df(x)}{dx} = \lim_{h\to 0}\left[\frac{f(x + h) - f(x -h)}{2h}\right]$$ Questions ===================================================== 1. What are the differences between the `Scene*` and `shared_ptr` data types in C++? + Scene* is a raw pointer that is deleted when the owner of the pointer gets deleted. The shared_ptr is type of smart pointer that is a container for a Scene pointer and it maintains reference counting of the ownership. The pointer contained in shared_ptr is destroyed when all the copies of shared_ptr have been destroyed. 2. How does G3D know where the scene files are located? + It searches scenes from scene folder using G3D10DATA user environment variable that points to "%g3d%\G3D10\data-files;%g3d%\data10\common;%g3d%\data10\game;%g3d%\data10\research;%g3d%\G3D10\data-files" and also from scene folder projects dataDir that is set in App.cpp main method in cubes project to FileSystem::currentDirectory(); 3. Why should you to put your initialization code into `App::onInit` instead of constructor `App::App`? (Tip: There are many reasons. Try throwing an exception from each, and consider the implications of throwing an exception from a class's constructor.) + One reason is that if the constructor fails the desctructor is called and we might be deleting something that is never created. Another reason is that common exceptions are automatically catch when using onInit but not from the constructor. 4. What is the call chain that invokes `App::onGraphics3D`? + From examining the call stack can be found that from initialization call chain is: - App::onInit() -> GApp::loadScene -> GApp::onGraphics3D -> App::onGraphics3D + After initialization onGraphics3D call chain starts from onRun: - GApp::onRun() -> GApp::oneFrame()-> GApp::onGraphics3D -> App::onGraphics3D 5. Where is the file `cube.obj` stored on the file system? How did the `Scene` parser know to load it from there? + cube.obj is in folder under %g3d%\data10\common that is found using G3D10DATA user environment variable. 6. You can create a material in a scene file from a `Color3`. There are many more ways to construct a G3D material, however. One of these takes separate `lambertian`, `glossy`, `emissive`, and `transmissive` values. Speculate on why a homogeneous material (i.e., one without a pattern or image) would require four separate "colors" in its specification. + Lambertian, glossy, emissive and transmissive all define different attributes for the material giving the object different features of which color s being reflected. For example Lamberitna defines matter or diffusive property, glossy color defines which color is reflected in a specular direction and transmissive color defines color of transparency in material. Reflection ===================================================== With this project I learned to use G3D engine for creating a project and creating scenes in different ways. I learned about the sctructure of scene files and how to manipulate entities in the scene. I also learned how to use the Markdeep and about keeping a development journal with the G3D engine. Many other things I was already familiar like tranformations of objects e.g. but I learned how to use functions of the G3D engine to scale, rotate and translate objects. In the project I created the objects and tranfromed their locations rather quick but I spend too much time to trying to find satiscfactory materials and lighting settings. Time ===================================================== Task | Time | Date ---------------------|------------|---------- warmup | 00:30:00 | 2017-02-17 whitecube| 00:40:00 | 2017-02-18 cornell box | 1:30:00 | 2017-02-18 stairs | 1:30:00 | 2017-02-19 own scene | 1:05:00 | from 2017-02-21 to 2017-02-25 report and polishing | 1:30:00 | 2017-02-25 Total: 6:45:00