12 #include <boost/tokenizer.hpp>
28 std::cout <<
"Render time: " << (int)_seconds <<
" seconds\n";
30 else if (_seconds > 60.0f && _seconds < 3600.0f)
32 int minutes = (int)_seconds / (
int)60;
33 float seconds = (int)_seconds % (
int)60;
35 std::cout <<
"Render time: " << minutes <<
"min " << seconds <<
"seconds\n";
39 int main(
int argc,
char *argv[])
43 std::cout <<
"ERROR, you must indicate the scene file you want to read from.\n"
44 "Usage: ./aidan [path_to_textfile]";
58 int anti_aliasing = 0;
60 std::vector<Light*> scene_lights;
61 std::vector<geo::Shape*> scene_objects;
62 std::string text_file = argv[1];
63 std::string image_name;
64 Parser scene_parser(image_name,
81 std::cout <<
"ERROR: Anti-aliasing should be 1 (no-antialising) or more." << std::endl;
82 assert(anti_aliasing > 0);
89 for(
unsigned int i = 0; i < scene_objects.size(); i++)
91 myScene_instance->
addObject(scene_objects.at(i));
95 for(
unsigned int i = 0; i < scene_lights.size(); i++)
97 myScene_instance->
addLight(scene_lights.at(i));
106 ngl::Vec3 campos(camPosX,camPosY,camPosZ);
107 ngl::Vec3 lookat(lookAtX,lookAtY,lookAtZ);
108 ngl::Vec3 diff_btw = campos - lookat; diff_btw.normalize();
109 ngl::Vec3 camdir = -diff_btw;
110 ngl::Vec3 camright = Y.cross(camdir);
111 ngl::Vec3 camdown = camright.cross(camdir);
115 myCamera_instance->
setParameters(campos,camdir,camright,camdown);
119 renderer_instance->
bind(myScene_instance, myFilm_instance, myCamera_instance, max_depth, anti_aliasing, image_name);
124 std::cout <<
"Rendering...\n";
127 renderer_instance->
render();
131 float seconds = (float)t/CLOCKS_PER_SEC;
141 std::cout << image_name <<
".ppm has been written successfully.\n";
142 std::string command =
"display " + image_name +
".ppm";
143 system(command.c_str());
void render()
Will trigger the class and start doing all the calculations.
void printOutTime(float _seconds)
Core of my program, central unit that manages all the other classes almost.
void setParameters(ngl::Vec3 _pos, ngl::Vec3 _dir, ngl::Vec3 _right, ngl::Vec3 _down)
Initialises the camera settings.
Implements the interface for creating a plane shape and the methods for finding its intersections...
All the operations regarding to file output and file input belong to this class. It abstracts the ide...
A class for implicit sphere definitions.
This hold all the objects and lights that the parser interpred and later pushed into the scene...
Parses a text file that user passes as an argument when executing the program.
void setDimensions(int _w, int _h)
Sets the dimensions of the Film.
Makes sure that no object is instanciated twice.
void bind(Scene *_scence, Film *_film, Camera *_camera, int _max_depth, int _anti_aliasing, std::string _image_name)
Grabs all the information and places it into the private interface.
void addObject(geo::Shape *_object)
Adds an shape obejct to the scene.
Holds all the operations regarding to input/output of colour information.
Hold all the objects and lights of the scene.
static void destroyInstance()
Destroys the instance thus freeing memory from the heap.
void addLight(Light *_light)
Adds a light to the scene structure.
This class is the heart of my raytracer. It is the core, where all the camera rays are calculated and...
static T * Instance()
If the instance is null it creates one, otherwise just returns the current one.
Holds camera functions which will be accessed by the Render class.
int main(int argc, char *argv[])
Reads from text file and iterates using boost tokenizer to "pickup" and store values based on syntax...