-
Notifications
You must be signed in to change notification settings - Fork 0
/
main3.cpp
82 lines (72 loc) · 3.48 KB
/
main3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <Util/cmdLineParser.h>
#include <Ray/window.h>
#include <Ray/box.h>
#include <Ray/cone.h>
#include <Ray/cylinder.h>
#include <Ray/sphere.h>
#include <Ray/torus.h>
#include <Ray/triangle.h>
#include <Ray/fileInstance.h>
#include <Ray/directionalLight.h>
#include <Ray/pointLight.h>
#include <Ray/spotLight.h>
using namespace std;
using namespace Ray;
using namespace Util;
CmdLineParameter< string > InputRayFile( "in" );
CmdLineParameter< int > WindowWidth( "width" , 640 );
CmdLineParameter< int > WindowHeight( "height" , 480 );
CmdLineParameter< int > Complexity( "cplx" , 10 );
CmdLineReadable* params[] =
{
&InputRayFile , &WindowWidth , &WindowHeight , &Complexity ,
NULL
};
void ShowUsage( const string &ex )
{
cout << "Usage " << ex << ":" << endl;
cout << "\t --" << InputRayFile.name << " <input ray File>" << endl;
cout << "\t[--" << WindowWidth.name << " <window width>=" << WindowWidth.value << "]" << endl;
cout << "\t[--" << WindowHeight.name << " <window height>=" << WindowHeight.value << "]" << endl;
cout << "\t[--" << Complexity.name << " <tessellation complexity>=" << Complexity.value << "]" << endl;
}
int main( int argc , char *argv[] )
{
CmdLineParse( argc-1 , argv+1 , params );
if( !InputRayFile.set ){ ShowUsage( argv[0] ) ; return EXIT_FAILURE; }
try
{
ShapeList::ShapeFactories[ Box ::Directive() ] = new DerivedFactory< Shape , Box >();
ShapeList::ShapeFactories[ Cone ::Directive() ] = new DerivedFactory< Shape , Cone >();
ShapeList::ShapeFactories[ Cylinder ::Directive() ] = new DerivedFactory< Shape , Cylinder >();
ShapeList::ShapeFactories[ Sphere ::Directive() ] = new DerivedFactory< Shape , Sphere >();
ShapeList::ShapeFactories[ Torus ::Directive() ] = new DerivedFactory< Shape , Torus >();
ShapeList::ShapeFactories[ Triangle ::Directive() ] = new DerivedFactory< Shape , Triangle >();
ShapeList::ShapeFactories[ FileInstance ::Directive() ] = new DerivedFactory< Shape , FileInstance >();
ShapeList::ShapeFactories[ ShapeList ::Directive() ] = new DerivedFactory< Shape , ShapeList >();
ShapeList::ShapeFactories[ TriangleList ::Directive() ] = new DerivedFactory< Shape , TriangleList >();
ShapeList::ShapeFactories[ StaticAffineShape::Directive() ] = new DerivedFactory< Shape , StaticAffineShape >();
GlobalSceneData::LightFactories[ DirectionalLight::Directive() ] = new DerivedFactory< Light , DirectionalLight >();
GlobalSceneData::LightFactories[ PointLight ::Directive() ] = new DerivedFactory< Light , PointLight >();
GlobalSceneData::LightFactories[ SpotLight ::Directive() ] = new DerivedFactory< Light , SpotLight >();
Scene scene;
ifstream istream;
istream.open( InputRayFile.value );
if( !istream ) THROW( "Failed to open file for reading: %s\n" , InputRayFile.value.c_str() );
istream >> scene;
Shape::OpenGLTessellationComplexity = Complexity.value;
Window::View( scene , WindowWidth.value , WindowHeight.value );
}
catch( const exception& e )
{
cerr << e.what() << endl;
return EXIT_FAILURE;
};
for( auto iter=ShapeList::ShapeFactories.begin() ; iter!=ShapeList::ShapeFactories.end() ; iter++ ) delete iter->second;
for( auto iter=GlobalSceneData::LightFactories.begin() ; iter!=GlobalSceneData::LightFactories.end() ; iter++ ) delete iter->second;
return EXIT_SUCCESS;
}