当前位置: 首页>>代码示例>>C++>>正文


C++ SimpleCamera::GetPos方法代码示例

本文整理汇总了C++中SimpleCamera::GetPos方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleCamera::GetPos方法的具体用法?C++ SimpleCamera::GetPos怎么用?C++ SimpleCamera::GetPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleCamera的用法示例。


在下文中一共展示了SimpleCamera::GetPos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calculate_pixel

bool calculate_pixel(float x, float y, task_detail_t *task, batch_blob_t *datablob, pixel_data_t *pixel)
{	
	// Clear pixel
	Pxf::Math::Vec3f fpixel(0.0f, 0.0f, 0.0f);
	fpixel.r = 0.0f;
	fpixel.g = 0.0f;
	fpixel.b = 0.0f;
	
	SimpleCamera* cam = (SimpleCamera*) datablob->cam;

	// Center ray
	Vec3f screen_coords(-1.0f + x, 1.0f - y,0.0f);
	ray_t cray;
	cray.o = Vec3f(0.0f,0.0f,1.41421356f);
	cray.o += cam->GetPos();

	Quaternion orientation = (*cam->GetOrientation());
	Normalize(orientation);

	//screen_coords = orientation * screen_coords;
	//Normalize(screen_coords);
	screen_coords += cam->GetPos();

	/*
	if (!calc_multisample_ray(&cray, datablob, &fpixel, 0.001f, 0))
	{
		Pxf::Message("calculate_pixel", "Ray shooting failed!");
		return false;
	}*/

	// find closest primitive
	for(int pixel_x = 0; pixel_x < datablob->samples_per_pixel; ++pixel_x)
	{
		for(int pixel_y = 0; pixel_y < datablob->samples_per_pixel; ++pixel_y)
		{
			// Offset ray
			ray_t ray = cray;
			Vec3f new_screen_coords = screen_coords;
			
			// TODO: Make sampling more non-uniform
			//new_screen_coords.x += (1.0f / ((float)datablob->pic_w * (float)datablob->samples_per_pixel)) * (float)pixel_x;
			//new_screen_coords.y += (1.0f / ((float)datablob->pic_h * (float)datablob->samples_per_pixel)) * (float)pixel_y;
			
			new_screen_coords.x += (0.5f / ((float)datablob->pic_w)) * (datablob->samples[rand() % 255] * 2.0f - 1.0f);
			new_screen_coords.y += (0.5f / ((float)datablob->pic_h)) * (datablob->samples[rand() % 255] * 2.0f - 1.0f);
			ray.d = new_screen_coords - cray.o;
			ray.d = orientation * ray.d;
			Normalize(ray.d);
			
			// Calc direct light
			Pxf::Math::Vec3f light_contrib;
			if (!calc_ray_contrib(&ray, datablob, &light_contrib, 0))
			{
				Pxf::Message("calculate_pixel", "Light calculations failed!");
				return false;
			}
			fpixel += light_contrib;
			
		}
	}
	
	fpixel /= datablob->samples_per_pixel * datablob->samples_per_pixel;
	
	fpixel.x = Pxf::Math::Clamp(fpixel.x, 0.0f, 1.0f);
	fpixel.y = Pxf::Math::Clamp(fpixel.y, 0.0f, 1.0f);
	fpixel.z = Pxf::Math::Clamp(fpixel.z, 0.0f, 1.0f);
		
	pixel->r = (unsigned char)(fpixel.r * 255.0f);
	pixel->g = (unsigned char)(fpixel.g * 255.0f);
	pixel->b = (unsigned char)(fpixel.b * 255.0f);	
	
	return true;
}
开发者ID:pxf,项目名称:pxf-tech2,代码行数:73,代码来源:Renderer.cpp


注:本文中的SimpleCamera::GetPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。