Esempio n. 1
0
void Raytracer::SetParams(Camera* camera, const char* path, int w, int h, AntiAlias aa)
{
	//Timer timer;
	raycount = 0;
	mode = aa;
	width = w;
	height = h;

	visualnodes.Clear();
	visualtransforms.Clear();
	visualboxes.Clear();
	lightnodes.Clear();
	lighttransforms.Clear();

	// go through the scene graph and cache stuff
	Node* root = camera->GetRoot();
	for(Node* node = root; node; node=node->GetNext())
	{
		if(node->HasFlag(Node::VISUAL))
		{
			Visual* visual = static_cast<Visual*>(node);
			visualnodes.PushBack(visual);
			visualtransforms.PushBack(visual->GetWorldTransform());
			visualboxes.PushBack(visual->GetWorldBox());
		}
		else if(node->HasFlag(Node::LIGHT))
		{
			Light* light = static_cast<Light*>(node);
			lightnodes.PushBack(light);
			lighttransforms.PushBack(light->GetWorldTransform());
		}
	}

	if(mode == ADAPTIVE)
	{
		width++;
		height++;
	}
	else if(mode == SUPERSAMPLE2X)
	{
		width *= 2;
		height *= 2;
	}
   
    // calculate image plane stuff
    float d = 10;     // distance from camera to plane (n'importe quoi...)        
    float sj = 2 * d * math::Tan(math::ToRadians(camera->GetHorizontalFov() / 2));	// width of plane
    float sk = sj * ((float)height/(float)width);	// height
	origin = camera->GetWorldTransform().GetTranslation(); 
    vector3f dirz = camera->GetWorldTransform().GetDirection();	// forward vector
    vector3f diry = vector3f(0,1,0);    // up vector
    vector3f dirx = Normalize(CrossProduct(dirz,diry));    // side vector
    p = origin + (d * dirz) - ((sj/2) * dirx) + ((sk/2) * diry);	// upper-left pixel of image plane
	incrementx = (sj*(1.f/(width-1))*dirx);	// one-pixel increment in x direction
	incrementy = (sk*(1.f/(height-1))*diry);	// one-pixel increment in y direction

	delete[] buffer;
	buffer = new vector3f[width * height];

	setparams = true;
}