InVoxel() for all Primitives, including fix for Triangle::CalcBounds()
[MicroTrace.git] / MicroTrace.cxx
index d0b1d6e..6bb474c 100644 (file)
@@ -1,74 +1,58 @@
+#ifdef _OPENMP
+#include <omp.h>
+#endif
+
 #include <string>
 
 #include "Vec3f.hxx"
-//#include "Sphere.hxx"
-//#include "Triangle.hxx"
-//#include "InfinitePlane.hxx"
-
 #include "Image.hxx"
 #include "PerspectiveCamera.hxx"
+#include "Scene.hxx"
 
-void RenderFrame(Camera &camera,
-                const std::string& fileName)
-{
-  /* scene objects */
-
-  /*
-    Sphere s1(Vec3f(-2,1.7,0),2);
-    Sphere s2(Vec3f(1,-1,1),2.2);
-    Sphere s3(Vec3f(3,0.8,-2),2);*/
-  //InfinitePlane p1(Vec3f(0,-1,0),Vec3f(0,1,0));
 
-  /*
-    Triangle t1(Vec3f(-2,3.7,0),Vec3f(1,2,1),Vec3f(3,2.8,-2)); 
-    Triangle t2(Vec3f(3,2,3),Vec3f(3,2,-3),Vec3f(-3,2,-3));    
-  */
-  Image img(camera.resX(),camera.resY()); // image array
-  Ray ray;                            // primary ray
+void RenderFrameCone(const std::string& fileName)
+{
+  /* Scene definition */
+  Scene scene;
   
-  for(int y=0;y<camera.resY();y++)
-    for (int x=0;x<camera.resX();x++) 
-      {
-       
-       /* Initialize your ray here */
-       
-       camera.InitRay(x+0.5,y+0.5,ray); // initialize ray
-       
-       Vec3f col = Vec3f(0,0,0); // background color
+  scene.ParseOBJ("cone.obj", 1.0f);
+  // alter the camera definition appropriately to see the cow
+  // you may need to implement some set/get routines for the scene class
+  scene.setCamera(new PerspectiveCamera(Vec3f(0,0,0.5),
+                                       Vec3f(0,0,-1),
+                                       Vec3f(0,1,0),
+                                       60,
+                                       640,
+                                       480));
+  
+  
+  Image img(scene.camera()->resX(),scene.camera()->resY()); // image array
+  // primary ray
+#pragma omp parallel for
+  for(int y = 0; y < scene.camera()->resY(); y++)
+    {
+      for (int x = 0; x < scene.camera()->resX(); x++) 
+       {
+         
+         /* Initialize your ray here */
+         Ray ray;
+         scene.camera()->InitRay(x+0.5,y+0.5,ray); // initialize ray
        
-       /*      
-               if (s1.Intersect(ray))
-               col = Vec3f(1,0,0);
-               if (s2.Intersect(ray))
-               col = Vec3f(0,1,0);
-               if (s3.Intersect(ray))
-               col = Vec3f(0,0,1);
-               if (p1.Intersect(ray))
-               col = Vec3f(1,1,0);
-               if (t1.Intersect(ray))
-               col = Vec3f(0,1,1);
-               if (t2.Intersect(ray))
-               col = Vec3f(1,1,1);
-               
-               img(x,y) = col; // store pixel color
-       */
-      }
+         Vec3f col = scene.RayTrace(ray);
+         
+         img(x,y) = col; // store pixel color
+       }
+    }
   img.WritePPM(fileName); // write final image
 }
 
+
+
 #define RESX 640 // image x-resolution
 #define RESY 480 // image y-resolution
 
 int main(int, char**)
 {
-  /* render three images with different camera settings */
-
-  PerspectiveCamera c1(Vec3f(0,0,10),Vec3f(0,0,-1),Vec3f(0,1,0),60,RESX,RESY);
-  RenderFrame(c1,"perspective1.ppm");
-
-  PerspectiveCamera c2(Vec3f(-8,3,8),Vec3f(1,-.1,-1),Vec3f(0,1,0),45,RESX,RESY);
-  RenderFrame(c2,"perspective2.ppm");
-
-  PerspectiveCamera c3(Vec3f(-8,3,8),Vec3f(1,-.1,-1),Vec3f(1,1,0),45,RESX,RESY);
-  RenderFrame(c3,"perspective3.ppm");
+  RenderFrameCone("cone.ppm");
 }
This page took 0.021214 seconds and 4 git commands to generate.