[ LiB ] |
This section shows the new updated cScene class with its new functionality. The class now includes the primitive and attribute read methods for the scene. Scene assets can be read from the file, which gives you a big advantage. The camera coordinate system is also included in the class. This gives the application the capability to perceive the scene from any position and orientation. The scene class also includes a few counter variables to determine the amount of triangles and spheres loaded by the read methods. It has a variable that's used to tell whether the data has been loaded using a scene definition file. The new code is listed in bold text:
#ifndef _C_SCENE_H #define _C_SCENE_H // 50 objects at a time to re-allocate #define MEMORY_OBJECTS_CHUNK 50 // 5 lights at a time to re-allocate #define MEMORY_LIGHT_CHUNK 5 #define RENDER_WIDTH 800 #define RENDER_HEIGHT 600 // new code #define BUFFER_LENGTH 80 class cScene { public: cScene(); ~cScene(); // scene load and destroy void Init_Scene(); void Kill_Scene(); // light methods void AddToObjectList(cObject ** pList, long *lCount, cObject tObject); void AddToLightList(cLight ** pList, int *nCount, cLight tObject); // color methods void PlotPixel(int x, int y, color3 color); void FillColor(color3 color); // New Code void Setup_Camera_Coords( cVector3 * X_Axis, cVector3 * Y_Axis, cVector3 * Z_Axis ); bool Read_In_Scene(char * filename); // scene primitivesbool bool Read_Camera(ifstream& is); bool Read_Light(ifstream& is); cMaterial Read_Material(ifstream& is); bool Read_Sphere(ifstream& is); bool Read_Triangle(ifstream& is); // attribute primitives cVector3 Read_Vector(ifstream& is); float Read_Scalar(ifstream& is); color3 Read_Color (ifstream& is); void Read_Comma (ifstream& is); // render settings class Render_Settings { public: Render_Settings() { use_diffuse_shading = false; use_diffuse_reflection = false; use_specular_reflection = false; use_refraction = false; use_specular_hightlights= false; } public: bool use_diffuse_shading, use_diffuse_reflection, use_specular_reflection, use_refraction, use_specular_hightlights; }; // Read lighting parameters from file bool Read_Render_Settings(ifstream& is); public: cObject * pObjectList; long nObjectCount; cLight * pLightList; int nLightCount; color3 ColorBuffer[ RENDER_WIDTH * RENDER_HEIGHT ]; // New Code for chapter 8 cVector3 CameraPosition, Look, Up, Viewing_Direction; float Viewing_Distance; bool isDataReady; long triangle_count, sphere_count; // The render settings object Render_Settings RenderSetting; }; // String comparison function bool COMPARE(char * in, char * out); #endif
NOTE
NOTE
The Render_Settings class should be defined in each scene definition file.
[ LiB ] |