d0b1d6ecf4d6bb931b632f1bae461e56986a3cbc
[MicroTrace.git] / MicroTrace.cxx
1 #include <string>
2
3 #include "Vec3f.hxx"
4 //#include "Sphere.hxx"
5 //#include "Triangle.hxx"
6 //#include "InfinitePlane.hxx"
7
8 #include "Image.hxx"
9 #include "PerspectiveCamera.hxx"
10
11 void RenderFrame(Camera &camera,
12 const std::string& fileName)
13 {
14 /* scene objects */
15
16 /*
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));
21
22 /*
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));
25 */
26 Image img(camera.resX(),camera.resY()); // image array
27 Ray ray; // primary ray
28
29 for(int y=0;y<camera.resY();y++)
30 for (int x=0;x<camera.resX();x++)
31 {
32
33 /* Initialize your ray here */
34
35 camera.InitRay(x+0.5,y+0.5,ray); // initialize ray
36
37 Vec3f col = Vec3f(0,0,0); // background color
38
39 /*
40 if (s1.Intersect(ray))
41 col = Vec3f(1,0,0);
42 if (s2.Intersect(ray))
43 col = Vec3f(0,1,0);
44 if (s3.Intersect(ray))
45 col = Vec3f(0,0,1);
46 if (p1.Intersect(ray))
47 col = Vec3f(1,1,0);
48 if (t1.Intersect(ray))
49 col = Vec3f(0,1,1);
50 if (t2.Intersect(ray))
51 col = Vec3f(1,1,1);
52
53 img(x,y) = col; // store pixel color
54 */
55 }
56 img.WritePPM(fileName); // write final image
57 }
58
59 #define RESX 640 // image x-resolution
60 #define RESY 480 // image y-resolution
61
62 int main(int, char**)
63 {
64 /* render three images with different camera settings */
65
66 PerspectiveCamera c1(Vec3f(0,0,10),Vec3f(0,0,-1),Vec3f(0,1,0),60,RESX,RESY);
67 RenderFrame(c1,"perspective1.ppm");
68
69 PerspectiveCamera c2(Vec3f(-8,3,8),Vec3f(1,-.1,-1),Vec3f(0,1,0),45,RESX,RESY);
70 RenderFrame(c2,"perspective2.ppm");
71
72 PerspectiveCamera c3(Vec3f(-8,3,8),Vec3f(1,-.1,-1),Vec3f(1,1,0),45,RESX,RESY);
73 RenderFrame(c3,"perspective3.ppm");
74 }
This page took 0.039432 seconds and 3 git commands to generate.