Exemplo n.º 1
0
void CCAMERA::MakeRayAtCurrrentMousePosition( SFVEC3F &aOutOrigin,
                                              SFVEC3F &aOutDirection ) const
{
    MakeRay( SFVEC2I( m_lastPosition.x,
                      m_windowSize.y - m_lastPosition.y ),
             aOutOrigin, aOutDirection );
}
Exemplo n.º 2
0
void s3DWindow::OnDrag(const sWindowDrag &dd)
{
  if(QuakeMode)
  {
    sInt mx,my;
    sGetMouseHard(mx,my);
    RotY += (mx-OldMouseHardX)*0.002f; OldMouseHardX = mx;
    RotX += (my-OldMouseHardY)*0.002f; OldMouseHardY = my;
    sSetMouse(Client.CenterX(),Client.CenterY());
  }
  else
  {
    DragRay=MakeRay(dd.MouseX-Client.x0,dd.MouseY-Client.y0);
    sWire->HandleDrag(this,dd,OnCheckHit(dd));
  }
}
Exemplo n.º 3
0
void CTracer::RenderImage(Params & params)
{
	// Reading input texture sample
	CImage* pImage = LoadImageFromFile("data/disk_32.png");
	if (!pImage) {
		std::cout << "Received NULL pointer when loading texture. Probably wrong file." << std::endl;
		return;
	}
	saved_images.push_back(pImage);
	image_shapes.push_back(img_shape(0));
	// Reading background (stars) texture
	CImage* stars = LoadImageFromFile("data/stars.jpg");
	if (!stars) {
		std::cout << "Received NULL pointer when loading texture. Probably wrong file." << std::endl;
		return;
	}
	saved_images.push_back(stars);
	image_shapes.push_back(img_shape(1));

	// Filling in properties
	m_camera.m_resolution = glm::uvec2(params.xRes, params.yRes);
	m_camera.m_pixels.resize(params.xRes * params.yRes);
	m_camera.m_pos = params.camera_pos;
	params.up /= glm::length(params.up);
	params.up *= params.yRes;
	m_camera.m_up = params.up;
	params.right /= glm::length(params.right);
	params.right *= params.xRes;
	m_camera.m_right = params.right;
	params.view_dir /= glm::length(params.view_dir);
	params.view_dir *= params.yRes / (2.0 * tan(params.view_angle.y / 2.0));
	m_camera.m_forward = params.view_dir;
	m_camera.m_viewAngle = params.view_angle;
	double black_hole_radius = 2 * grav_const * params.black_hole_mass / light_speed / light_speed;
	black_hole.center = glm::dvec3(0, 0, 0);
	black_hole.radius = black_hole_radius;
	black_hole.mass = params.black_hole_mass;
	// setting disk params
	disk.center = glm::dvec3(0, 0, 0);
	disk.in_rad = black_hole_radius;
	disk.out_rad = black_hole_radius * params.disk_bh_rad_ratio;
	disk.normal = glm::vec3(0, 0, 1);
	for (int i = 0; i < 2; ++i) {
		planet_enable[i] = params.planet_enable[i];
		planets[i].center = params.planet_center[i];
		planets[i].radius = params.planet_rad[i];
		planet_colors[i] = params.planet_color[i];
	}
	alpha_blending_enable = params.alpha_blending_enable;
	antialiasing_rays = params.antialiasing_rays;
	
	// Rendering
	double gap, x_shift, y_shift;
	glm::vec3 rays_accum(0, 0, 0);
	SRay ray;
	for (int i = 0; i < params.yRes; i++) {
		for (int j = 0; j < params.xRes; j++)
		{
			rays_accum.r = rays_accum.b = rays_accum.g = 0;
			x_shift = y_shift = gap = 1.0 / (antialiasing_rays + 1);
			for (int x_rays = 0; x_rays < antialiasing_rays; ++x_rays, x_shift += gap) {
				for (int y_rays = 0; y_rays < antialiasing_rays; ++y_rays, y_shift += gap) {
					ray = MakeRay(glm::uvec2(j, i), x_shift, y_shift);
					rays_accum += TraceRay(ray);
				}
			}
			rays_accum /= (antialiasing_rays * antialiasing_rays);
			m_camera.m_pixels[i * params.xRes + j] = rays_accum;
			//m_camera.m_pixels[i * params.xRes + j] = rgb_cut(img_get_pxl_rgba(1, i, j)) / 255.0f;
		}
	}
}