Example #1
0
//////////////////////////////////////////////////////////////////////
// Create an image and write it out to a file
//////////////////////////////////////////////////////////////////////
int main()
{
  int width = 400;
  int height = 400;
  VEC3F* image = new VEC3F[width * height]; // pixel values
  VEC3F* ray[width * height]; 				// array of VEC3F pointers
  int maxFrames = 1; 						// set to 30 to make 30 sequenced images
  
  for(int v = 0; v < maxFrames; v++) { 
	
    int i = 0; 
	for (int y = 0; y < height; y++) {
	  for (int x = 0; x < width; x++, i++) {
	    ray[i] = generateRay(x, y, -0.5f, 0.5f, -0.5f, 0.5f, width, height, v);  // generate Ray
		image[i] = rayColor(ray[i]); // get RGB pixel color of ray intersecting on surface
	  }
	}
	
	//save sequence of images for movie
	// std::stringstream stream;
	// stream << "image" << v << ".ppm";
	// std::string arraystring = stream.str();	
	// const char* filename = arraystring.c_str();
	
	//writePPM(image, width, height, filename);
	   } // v for loop
  writePPM(image, width, height, "image.ppm"); // comment this when saving movie
  delete[] image;

  return 0;
}
Example #2
0
/*
	
	This function you will have to modify

*/
void drawRayFunc(int x, int y){
	if(drawRay==true){
		// Draw a bounding box around the sphere to help debug your intersection

		Point eyePointP = getEyePoint(); 
		Vector rayV = generateRay(); 

		float t = Intersect(eyePointP, rayV, Matrix());
		std::cout << "t: " << t << std::endl;

		Point isectPointWorldCoord = getIsectPointWorldCoord(eyePointP, rayV, t);

		if (t > 0) {
			glColor3f(1, 0, 0);
			glutWireCube(1.0f);
			if (paint == 1) {
				paintObject(isectPointWorldCoord);
			}
			else{
				glColor3f(red_Scroll / (float)255.0f, green_Scroll / (float)255.0f, blue_Scroll / (float)255.0f);
				glPushMatrix();
					glTranslatef(isectPointWorldCoord[0], isectPointWorldCoord[1], isectPointWorldCoord[2]);
					glutSolidSphere(0.05f, 10, 10);
				glPopMatrix();
			}
		}

		/*


				You can fill this in if it helps you debug

				This is the function you should call insersect in

				and then have some output whether we intersected or

				not with the object


		*/
	}
}
Example #3
0
PixelMap * Camera::render(short aa=1) {
	//local variables
	int tVW				= aa*this->getVWidth();
	int tVH				= aa*this->getVHeight();
	Polygon * tracedPg;
	Color tracedColor;
	bool end;
	
	//Initialize PixelMap with given dimensions
	PixelMap * render	= new PixelMap ("render", tVW, tVH);
	
	//apply the new vWidth and Height to Camera
	if (aa != 1) {
		this->setView(tVW, tVH, this->getVAngle(), true);
	}
	
	//reset vPos in Camera
	resetVPos();
	
	//generate first ray
	generateRay(true);
	
	cout << "\nRendering initialized.\n\tResolution: \t" << tVW/aa << "x" << tVH/aa << " at " << aa << "xAA\n\tPolygons: \t" << allPolygons.size() << endl;
	
	while (true) {
		//generate ray for new vPos
		generateRay();
		
		//start of new position --> update vector inDivPolygons to pass to trace()
		if (this->checkDiv) this->checkDivPgs();
		
		//RayTracing. Returns pointer to the valid polygon from a given vector including pointers to polygons in that division
		if (this->getDivSize() != 1) {
			tracedPg	= this->vRay.trace(&(this->inDivPolygons));
		}
		else {
			tracedPg	= this->vRay.trace();	//use all polygons
		}
		
		//check for intersection. No intersection: set pixel to backgroundcolor
		if (tracedPg->isActive()) {
			tracedColor	= tracedPg->getColor();
		}
		else {
			tracedColor = black;
		}
		
		//set pixel in PixelMap to color of polygon and move to next pixel (2nd arg TRUE) in the PixelMap
		render->setPixel(tracedColor, this->getVPos());
		
		//move to the next pixel in vPos. End loop if vPos reached top right
		end		= nextPixel();
		if (end) break;
	}
	
	
	//apply AntiAliasing
	*render	= render->antiAliase(aa);
	
	cout << "Rendering finished.\n" << endl;
	
	//reset vWidth and Height to old values
	if (aa != 1) {
		this->setView(tVW/aa, tVH/aa, this->getVAngle(), true);
	}
	
	return render;
}