示例#1
0
Scene::Scene()
{
    Object* object;
    object = new Ball(Vec3f(1,0,-0.71),0.3);
    _objects.push_back(new Ball(Vec3f(-5,0,0.5),1.5,Vec3f(210,210,210)));
    _objects.push_back(new TextureBall(Vec3f(0,1.6,-0.2),0.8,":/texture/stone.jpg"));
    _objects.push_back(new Ball(Vec3f(1.1,0.6,-0.5),0.5,Vec3f(100,100,255)));
    _objects.push_back(new GlassBall(Vec3f(1.2,-0.2,-0.8),0.2));
    _objects.push_back(new GlassBall(Vec3f(1.9,0.5,-0.85),0.15));
    _objects.push_back(new GlassBall(Vec3f(1.7,0.1,-0.85),0.15));
    _objects.push_back(new GlassBall(Vec3f(1.3,-0.8,-0.85),0.15));
    //_objects.push_back(new GlassBall(Vec3f(0,0,0),1));
    object = new Plane(Vec3f(0,0,-1),Vec3f(0,0,1));
    object->LoadTexture(":/texture/floor.bmp",100);
    object->material.setSmoothSurface();
    _objects.push_back(object);
    object = new Plane(Vec3f(0,0,30),Vec3f(0,0,-1));
    object->LoadTexture(":/texture/sky.jpg",10);
    object->material.setStone();
    _objects.push_back(object);
    _objects.push_back(new Plane(Vec3f(-10,0,0),Vec3f(-1,1,0)));
    _objects.last()->material.setWall();
    _objects.push_back(new Plane(Vec3f(-10,0,0),Vec3f(-1,-1,0)));
    _objects.last()->material.setWall();
    AddModel("G:/lesson/CSGraphic/Raytracer/resource/fixed.perfect.dragon.100K.0.07.obj",Vec3f(0.7,-1.5,-0.3),1);
    AddModel("G:/lesson/CSGraphic/Raytracer/resource/bunny.fine.obj",Vec3f(-0.8,-3.5,-1.335),10);
    //AddModel("G:/lesson/CSGraphic/Raytracer/resource/sphere.obj",Vec3f(0,0,0),1);
    LightInit();
    qDebug() << "finish";
}
示例#2
0
int main(void) 
{
   // set up for random num generator
  	//srand ( time(NULL) );
    srand ( 0);

   Image img(WINDOW_WIDTH, WINDOW_HEIGHT);
   Camera* cam = CameraInit();
   PointLight* light = LightInit();
   Ray* r = new Ray();
	double aspectRatio = WINDOW_WIDTH; 
	aspectRatio /= WINDOW_HEIGHT;
  
  	//SCENE SET UP
  	// (floor)
   Plane* floor = new Plane();
   //floor->center = CreatePoint(0, -1 * WINDOW_HEIGHT / 2, -1 * WINDOW_WIDTH / 2);
   //floor->color = CreateColor(200, 200, 200);
   //floor->normal = CreatePoint(0, 0, -1 * WINDOW_WIDTH / 2);
   // (spheres)
   Sphere* spheres = CreateSpheres();

	// RAY TRACING
	//
   
	r->origin = cam->eye;
   r->direction = cam->lookAt;
   r->direction.x = -1 * aspectRatio * tan(FOV / 2);

   for (int i=0; i < WINDOW_WIDTH; i++) {
   	r->direction.y = tan(FOV / 2);
		for (int j=0; j < WINDOW_HEIGHT; j++) {
         //Looping over the Rays
     		img.pixel(i, j, RayTrace(r, spheres, floor, light));
      		
      	//printf("o: (%lf, %lf, %lf)   ", r.origin.x, r.origin.y, r.origin.z);
         //printf("d: (%lf, %lf, %lf)\n", r.direction.x, r.direction.y, r.direction.z);
      		
      	r->direction.y -= 2 * tan(FOV / 2) / WINDOW_HEIGHT;
		}
		r->direction.x += 2 * tan(FOV / 2) / WINDOW_HEIGHT;
  	}
  	
	// IMAGE OUTPUT
	//
  	// write the targa file to disk
  	img.WriteTga((char *)"vanilla.tga", true); 
  	// true to scale to max color, false to clamp to 1.0
}