4 //#include "Sphere.hxx"
5 //#include "Triangle.hxx"
6 //#include "InfinitePlane.hxx"
9 #include "PerspectiveCamera.hxx"
11 void RenderFrame(Camera
&camera
,
12 const std::string
& fileName
)
17 Sphere s1(Vec3f(-2,1.7,0),2);
18 Sphere s2(Vec3f(1,-1,1),2.2);
19 Sphere s3(Vec3f(3,0.8,-2),2);*/
20 //InfinitePlane p1(Vec3f(0,-1,0),Vec3f(0,1,0));
23 Triangle t1(Vec3f(-2,3.7,0),Vec3f(1,2,1),Vec3f(3,2.8,-2));
24 Triangle t2(Vec3f(3,2,3),Vec3f(3,2,-3),Vec3f(-3,2,-3));
26 Image
img(camera
.resX(),camera
.resY()); // image array
27 Ray ray
; // primary ray
29 for(int y
=0;y
<camera
.resY();y
++)
30 for (int x
=0;x
<camera
.resX();x
++)
33 /* Initialize your ray here */
35 camera
.InitRay(x
+0.5,y
+0.5,ray
); // initialize ray
37 Vec3f col
= Vec3f(0,0,0); // background color
40 if (s1.Intersect(ray))
42 if (s2.Intersect(ray))
44 if (s3.Intersect(ray))
46 if (p1.Intersect(ray))
48 if (t1.Intersect(ray))
50 if (t2.Intersect(ray))
53 img(x,y) = col; // store pixel color
56 img
.WritePPM(fileName
); // write final image
59 #define RESX 640 // image x-resolution
60 #define RESY 480 // image y-resolution
64 /* render three images with different camera settings */
66 PerspectiveCamera
c1(Vec3f(0,0,10),Vec3f(0,0,-1),Vec3f(0,1,0),60,RESX
,RESY
);
67 RenderFrame(c1
,"perspective1.ppm");
69 PerspectiveCamera
c2(Vec3f(-8,3,8),Vec3f(1,-.1,-1),Vec3f(0,1,0),45,RESX
,RESY
);
70 RenderFrame(c2
,"perspective2.ppm");
72 PerspectiveCamera
c3(Vec3f(-8,3,8),Vec3f(1,-.1,-1),Vec3f(1,1,0),45,RESX
,RESY
);
73 RenderFrame(c3
,"perspective3.ppm");
This page took 0.051794 seconds and 5 git commands to generate.