rename eclipse project
[MicroTrace.git] / MicroTrace.cxx
1 #include <string>
2 #include <iostream>
3
4 #include "Vec3f.hxx"
5 //#include "Sphere.hxx"
6 //#include "Triangle.hxx"
7 //#include "InfinitePlane.hxx"
8
9 #include "Image.hxx"
10 #include "PerspectiveCamera.hxx"
11
12 void RenderFrame(Camera &camera, const std::string& fileName) {
13 /* scene objects */
14
15 /*
16 Sphere s1(Vec3f(-2,1.7,0),2);
17 Sphere s2(Vec3f(1,-1,1),2.2);
18 Sphere s3(Vec3f(3,0.8,-2),2);*/
19 //InfinitePlane p1(Vec3f(0,-1,0),Vec3f(0,1,0));
20
21 /*
22 Triangle t1(Vec3f(-2,3.7,0),Vec3f(1,2,1),Vec3f(3,2.8,-2));
23 Triangle t2(Vec3f(3,2,3),Vec3f(3,2,-3),Vec3f(-3,2,-3));
24 */
25 Image img(camera.resX(), camera.resY()); // image array
26 Ray ray; // primary ray
27
28 for(int y = 0; y < camera.resY(); y++)
29 for(int x = 0; x < camera.resX(); x++) {
30
31 /* Initialize your ray here */
32
33 camera.InitRay(x + 0.5, y + 0.5, ray); // initialize ray
34
35 Vec3f col = Vec3f(0, 0, 0); // background color
36
37 /*
38 if (s1.Intersect(ray))
39 col = Vec3f(1,0,0);
40 if (s2.Intersect(ray))
41 col = Vec3f(0,1,0);
42 if (s3.Intersect(ray))
43 col = Vec3f(0,0,1);
44 if (p1.Intersect(ray))
45 col = Vec3f(1,1,0);
46 if (t1.Intersect(ray))
47 col = Vec3f(0,1,1);
48 if (t2.Intersect(ray))
49 col = Vec3f(1,1,1);
50
51 img(x,y) = col; // store pixel color
52 */
53 }
54 img.WritePPM(fileName); // write final image
55 }
56
57 #define RESX 640 // image x-resolution
58 #define RESY 480 // image y-resolution
59 using namespace std;
60
61 int main(int, char**) {
62 // test vector implementation
63
64 Vec3f bar(1, 4, 5), foo(3, 2, 1);
65 cout << "Using example vector bar=" << bar << ", foo=" << foo << endl;
66 cout << "bar | foo = " << (bar | foo) << ", should be 16" << endl;
67 cout << "bar | bar = " << (bar | bar) << ", should be 42" << endl;
68 cout << "foo | foo = " << (foo | foo) << ", should be 14" << endl;
69 cout << "bar % foo = " << (bar % foo) << ", should be (-6,14,-10)" << endl;
70 cout << "bar % bar = " << (bar % bar) << ", should be (0,0,0)" << endl;
71 cout << "foo % foo = " << (foo % foo) << ", should be (0,0,0)" << endl;
72 cout << "bar.norm() = " << bar.norm() << ", should be 6.48" << endl;
73 cout << "foo.norm() = " << foo.norm() << ", should be 3.74" << endl;
74 cout << "bar*5 = " << (bar * 5) << ", should be (5,20,25)" << endl;
75 cout << "bar/5 = " << (bar / 5) << ", should be (0.2,0.8,1)" << endl;
76 cout << "bar + foo = " << (bar + foo) << ", should be (4,6,6)" << endl;
77 cout << "bar - foo = " << (bar - foo) << ", should be (-2,2,4)" << endl;
78 cout << "foo - bar = " << (foo - bar) << ", should be (2,-2,-4)" << endl;
79 cout << "bar * foo = " << (bar * foo) << ", should be (3,8,5)" << endl;
80 cout << "bar / foo = " << (bar / foo) << ", should be (0.33,2,5)" << endl;
81 cout << "foo / bar = " << (foo / bar) << ", should be (3,0.5,0.2)" << endl;
82
83 cout << "bar *= 4: " << (bar *= 4) << ", should be (4,16,20)" << endl;
84 cout << "bar /= 2: " << (bar /= 2) << ", should be (2,8,10)" << endl;
85 cout << "bar += foo: " << (bar += foo) << ", should be (5,10,11)" << endl;
86 cout << "bar -= Vec3f(5,6,3): " << (bar -= Vec3f(5, 6, 3))
87 << ", should be (0,4,8)" << endl;
88
89 cout << "bar[0] = " << bar[0] << ", should be 0" << endl;
90 cout << "bar[1] = " << bar[1] << ", should be 4" << endl;
91 cout << "bar[2] = " << bar[2] << ", should be 8" << endl;
92 cout << "foo[0] = " << foo[0] << ", should be 3" << endl;
93 cout << "foo[1] = " << foo[1] << ", should be 2" << endl;
94 cout << "foo[2] = " << foo[2] << ", should be 1" << endl;
95
96 bar.normalize();
97 cout << "bar.normalize(): " << bar << ", should be (0,0.44,0.89)" << endl;
98 foo.normalize();
99 cout << "foo.normalize(): " << foo << ", should be (0.80,0.53,0.26)" << endl;
100 bar = foo;
101 cout << "bar := foo: bar = " << bar << ", should be (0.80,0.53,0.26)" << endl;
102
103 /* render three images with different camera settings */
104 /*
105 PerspectiveCamera c1(Vec3f(0, 0, 10), Vec3f(0, 0, -1), Vec3f(0, 1, 0), 60,
106 RESX, RESY);
107 RenderFrame(c1, "perspective1.ppm");
108
109 PerspectiveCamera c2(Vec3f(-8, 3, 8), Vec3f(1, -.1, -1), Vec3f(0, 1, 0), 45,
110 RESX, RESY);
111 RenderFrame(c2, "perspective2.ppm");
112
113 PerspectiveCamera c3(Vec3f(-8, 3, 8), Vec3f(1, -.1, -1), Vec3f(1, 1, 0), 45,
114 RESX, RESY);
115 RenderFrame(c3, "perspective3.ppm");*/
116 }
This page took 0.060819 seconds and 5 git commands to generate.