Beispiel #1
0
int main( int argc, char* argv[] )
{
    std::cout << "Hello!\n";

    ray_tracer cnc_ray_tracer = ray_tracer();
 //    CnC::debug::trace(cnc_ray_tracer.frame);
 //   CnC::debug::trace(cnc_ray_tracer.frame_fragment);
 //   CnC::debug::trace(cnc_ray_tracer.execution_time);

    cnc_ray_tracer.number_frames = 12;
    cnc_ray_tracer.number_fragments = 8;

    cnc_ray_tracer.image_height = 1080;
    cnc_ray_tracer.image_width = 1920;

    cnc_ray_tracer.number_pixel_samples = 4;
    cnc_ray_tracer.number_light_samples = 4;

    pushStaticScene(cnc_ray_tracer.static_scene);

  	cnc_ray_tracer.luminaires.push_back(new Luminaire(
  			Multispectral3D(0.1, 0.1, 0.1), Sphere(Point3D(0, 20, -30), 3), 4));

  	// Start the graph
    cnc_ray_tracer.frame.put(0);
    cnc_ray_tracer.wait();

    // Delete the static scene
  	for(unsigned i = 0; i < cnc_ray_tracer.static_scene.size(); ++i) {
  		cnc_ray_tracer.static_scene[i]->deleteShape();
  		delete cnc_ray_tracer.static_scene[i];
  	}

  	// Delete the lights
  	for(unsigned i = 0; i < cnc_ray_tracer.luminaires.size(); ++i) {
  	 	delete cnc_ray_tracer.luminaires[i];
  	}

		for(int fragment = 0; fragment < cnc_ray_tracer.number_fragments; fragment++) {
			std::vector<Point2D*> points;
			cnc_ray_tracer.pixel_locations.get(
					pair(cnc_ray_tracer.number_frames - 1, fragment), points);
			for(int i = 0; i < points.size(); i++)
				delete points[i];
		}

    return 0;
}
Beispiel #2
0
int		main(int ac, char **av)
{
	t_env e;

	init_env(&e);
	parsing(&e, ac, av[1]);
	init_eye(&e);
	get_lightspot_number(&e);
	init_viewpoint(&e);
	e.v = 0;
	e.v2 = 0;
	e.nl = 1 / e.nl;
	e.mlx = mlx_init();
	e.win = mlx_new_window(e.mlx, e.width, e.height, e.name);
	ray_tracer(&e);
	mlx_expose_hook(e.win, expose_hook, &e);
	mlx_key_hook(e.win, event_mlx, &e);
	mlx_loop(e.mlx);
	return (0);
}
Beispiel #3
0
int		event_mlx(int keycode, t_env *e)
{
	static int etat;

	if (!etat)
		etat = 0;
	another_keycode(keycode, e);
	move_cam(e, keycode);
	if (keycode == 49)
	{
		if (etat == 3)
			etat = 0;
		else
			etat++;
		ft_putstr("Etat Numero : ");
		ft_putnbr(etat);
		print_obj(etat);
	}
	movable(keycode, e, etat);
	ray_tracer(e);
	return (1);
}
Beispiel #4
0
TEST(RayTracerTest, TurbineMeshTest) {
  SceneLoader& loader = SceneLoader::GetInstance();
  std::string path = "../assets/blade.ply";
  std::string status = "";
  Scene scene;
  std::cout << "loading" << std::endl;
  bool success = loader.LoadScene(path, scene, status);
  EXPECT_TRUE(success);
  EXPECT_EQ("OK", status);
  std::cout << "done loading" << std::endl;
  int image_width = 1024;
  int image_height = 1024;
  glm::vec3 eye_pos = glm::vec3(-274.564f, -282.243f, 950.0f);
  glm::vec3 at_pos = glm::vec3(-274.564f, -282.243f, 254.327f);
  glm::vec3 up_dir = glm::vec3(0.0f, 1.0f, 0.0f);
  std::cout << "set camera" << std::endl;
  glm::mat4x4 look_at = LookAt(eye_pos, at_pos, up_dir);
  Camera camera(image_width, image_height, Orthographic(0.0f, 1.0f), look_at);
  std::cout << "camera set" << std::endl;

  Light point_light;
  glm::vec3 point_light_color = glm::vec3(0.4f, 0.4f, 0.4f);
  point_light.ka = point_light_color;
  point_light.kd = point_light_color;
  point_light.ks = point_light_color;
  point_light.ray = Ray(glm::vec3(0.0, -400.0, 400.0f), glm::vec3(0.0f));
  point_light.type = Light::kPoint;
  point_light.attenuation_coefficients = glm::vec3(0.25f, 0.003372407f,
      0.000045492f);

  Light directional_light;
  glm::vec3 directional_light_color = glm::vec3(0.4f, 0.4f, 0.4f);
  directional_light.ka = directional_light_color;
  directional_light.kd = directional_light_color;
  directional_light.ks = directional_light_color;
  directional_light.ray = Ray(glm::vec3(0.0f), glm::vec3(0.0f, -1.0f, -1.0f));
  directional_light.type = Light::kDirectional;

  scene.AddLight(point_light);
  scene.AddLight(directional_light);

  Trimesh* trimesh = static_cast<Trimesh*>(scene.scene_objects()[0]);
  OctreeType octree;
  std::cout << "Building octree" << std::endl;
  octree.Build(trimesh->faces());
  //octree.set_trace(true);
  //octree.Print(std::cout);
  std::cout << "Octree built.\n";
  std::cout << "bounds = " << octree.GetBounds() << " center = "
      << octree.GetBounds().GetCenter() << std::endl;
  trimesh->set_accelerator(&octree);
  Image image;
  image.Resize(image_width, image_height);
  RayTracer ray_tracer(&scene, &camera);
  ray_tracer.set_display_progress(!use_timing);
  ray_tracer.set_display_stats(!use_timing);
  ray_tracer.set_background_color(glm::vec3(0.05f, 0.05f, 0.05f));

  timeval t_start, t_finish;
  if (use_timing)
    gettimeofday(&t_start, NULL);
  std::cout << "Rendering..." << std::endl;
  ray_tracer.Render(image);
  if (use_timing) {
    gettimeofday(&t_finish, NULL);
    float sec = t_finish.tv_sec - t_start.tv_sec + t_finish.tv_usec / 1000000.0f
        - t_start.tv_usec / 1000000.0f;
    std::cout << "Render time:" << sec << std::endl;
  } else
    std::cout << "Done." << std::endl;

  ImageStorage& storage = ImageStorage::GetInstance();
  success = storage.WriteImage("blade_octree.jpg", image, status);
  EXPECT_TRUE(success);
  EXPECT_EQ("OK", status);
}