Using the Chapter s Source Code

[ LiB ]

Using the Chapter's Source Code

In /Book Code/Chapter 09/ are three ray-tracing applications. The folder names are Ray Tracer 1 , Ray Tracer 2 , and Ray Tracer 3 . The general design of the applications follows a set of classes in a /Common folder and one Ray Tracer.cpp file for the general logic of the programs. You are going to include all of these classes into the ray-tracing applications in this chapter. These classes are required to implement ray tracing as well as photon mapping, so they are extremely important.

The entry point for the programs is inside main() . This is how you dictate to the application what type of logic should be executed for ray tracing. The body and main logic of the program are located in /Program Name /Ray Tracer.cpp . This is the brain of the program, where it calls the different methods of the scene class. The cScene class is a global object that is called throughout the ray-tracing program. The required class files (as well as the flow of the program) are listed in /Program Name/Ray Tracer.cpp . Take a look at the code:

 #include <stdio.h> #include <iostream.h> #include <fstream.h> #include <windows.h> #include <math.h> #include <stdio.h> #include <string.h> #include "Common\MathTools.h" #include "Common\Color3.h" #include "Common\cVector3.h" #include "Common\cRay.h" #include "Common\cObject.h" #include "Common\cLight.h" #include "Common\PPM.h" #include "Common\cScene.h" // SETUP OBJECTS cScene TheScene; int main(int argc, char* argv[]) {         // for timing         unsigned long Start_Time    = 0;         long                  Whole_Interval     = 0,                               seconds             = 0;         int                    G_Curr_Mins       = 0,                                G_Curr_Secs       = 0,                                Average           = 0;         // grab begin time         Start_Time = GetTickCount();       // RAY TRACER      printf(" TODO: Program Name Goes Here !\n");      // Begin      printf("Init Scene!\n");      TheScene.Init_Scene();      // Scene Stats      printf("Scene Stats!\n");      printf("Objects: %d Lights: %d\n",          TheScene.nObjectCount, TheScene.nLightCount);      // Trace      printf("Tracing Scene!\n");      TheScene.BeginTracing();      // We're all done!!      printf("Done Tracing Scene!\n");      TheScene.Kill_Scene();      // actual render time      Whole_Interval  = 0;      Whole_Interval  = (GetTickCount() - Start_Time);      seconds          = (Whole_Interval / 1000);      G_Curr_Mins      = (int)seconds / 60;      G_Curr_Secs      = (int)seconds % 60;      printf("Render Took %d Minute(s) and  %d Second(s)...",         G_Curr_Mins, G_Curr_Secs);      // halt and beep      Beep(1000, 500);      return 0; } 

As you can see, the general flow of the program is simple. At the beginning of the program the current tick count is saved in a variable. The program loads in the scene by calling TheScene.Init_Scene(). The scene stats are then reported after all the elements from the scene definition file are read in. The process begins tracing the rays in the scene by calling TheScene.BeginTracing(). After the ray-tracing algorithm has rendered the scene, the program releases memory by calling TheScene.Kill_Scene() . The time it took to render the scene is calculated and the computer speakers beep.

Let's take a look at a program designed to perform diffuse interaction and specular highlights in the next section.

[ LiB ]


Focus On Photon Mapping
Focus On Photon Mapping (Premier Press Game Development)
ISBN: 1592000088
EAN: 2147483647
Year: 2005
Pages: 128
Authors: Marlon John

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