feb1eebf747cbaea5704af66cc3dabce379df417
5 //#include "Sphere.hxx"
6 //#include "Triangle.hxx"
7 //#include "InfinitePlane.hxx"
10 #include "PerspectiveCamera.hxx"
12 void RenderFrame(Camera
&camera
, const std::string
& fileName
) {
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));
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));
25 Image
img(camera
.resX(), camera
.resY()); // image array
26 Ray ray
; // primary ray
28 for(int y
= 0; y
< camera
.resY(); y
++)
29 for(int x
= 0; x
< camera
.resX(); x
++) {
31 /* Initialize your ray here */
33 camera
.InitRay(x
+ 0.5, y
+ 0.5, ray
); // initialize ray
35 Vec3f col
= Vec3f(0, 0, 0); // background color
38 if (s1.Intersect(ray))
40 if (s2.Intersect(ray))
42 if (s3.Intersect(ray))
44 if (p1.Intersect(ray))
46 if (t1.Intersect(ray))
48 if (t2.Intersect(ray))
51 img(x,y) = col; // store pixel color
54 img
.WritePPM(fileName
); // write final image
57 #define RESX 640 // image x-resolution
58 #define RESY 480 // image y-resolution
61 int main(int, char**) {
62 // test vector implementation
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
;
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
;
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
;
97 cout
<< "bar.normalize(): " << bar
<< ", should be (0,0.44,0.89)" << endl
;
99 cout
<< "foo.normalize(): " << foo
<< ", should be (0.80,0.53,0.26)" << endl
;
101 cout
<< "bar := foo: bar = " << bar
<< ", should be (0.80,0.53,0.26)" << endl
;
103 /* render three images with different camera settings */
105 PerspectiveCamera c1(Vec3f(0, 0, 10), Vec3f(0, 0, -1), Vec3f(0, 1, 0), 60,
107 RenderFrame(c1, "perspective1.ppm");
109 PerspectiveCamera c2(Vec3f(-8, 3, 8), Vec3f(1, -.1, -1), Vec3f(0, 1, 0), 45,
111 RenderFrame(c2, "perspective2.ppm");
113 PerspectiveCamera c3(Vec3f(-8, 3, 8), Vec3f(1, -.1, -1), Vec3f(1, 1, 0), 45,
115 RenderFrame(c3, "perspective3.ppm");*/
This page took 0.047434 seconds and 3 git commands to generate.