Exemple #1
0
int				ray_color(t_ray *ray, t_env *e)
{
	double		spot_dist;
	int			color;
	t_list		*lst;
	t_ray		light;

	if (!ray->obj)
		return (COLOR_BACKGROUND);
	if (!e->scene->spot)
		return (ray->obj->param.color);
		/*
		Si le damier est voulue;
		*/
	//color = damier_color(ray);
	color = color_scale(ray->obj->param.color, ray->obj->param.ambiant);

	lst = e->scene->spot;
	while (lst)
	{
		init_light_ray(&light, ray, lst->content);
		ray_intersect(&light, e);
		spot_dist = 0;
		if (light.obj)
			spot_dist = mat_dist(&LST_CONTENT(lst, t_spot*)->position,
						&ray->intersection);
		if (!light.obj || spot_dist < light.dist)
			color = color_add(color, get_spot(ray, &light, lst->content));
		lst = lst->next;
	}
	//if(ray->obj && ray->obj->param.type == PLANE)
	//	color = damier_color(ray);
	return (color);
}
Exemple #2
0
	void initialize() override
	{
		const auto size = windowDimensions();
		linear_scale<float, float> window_scale(0, 1000, 0, size.x);
		linear_scale<float, float> lower_bottom(0, size.x, 5 * size.y / 6, 5 * size.y / 6);
		linear_scale<float, float> lower_top(0, size.x, 2 * size.y / 3, size.y / 6);
		linear_scale<float, float> upper_bottom(0, size.x, size.y / 3, 5 * size.y / 6);
		linear_scale<float, float> upper_top(0, size.x, size.y / 6, size.y / 6);
		linear_scale<float, float> x_scale(0, std::sqrt(size.x), 0, size.x);
		linear_color_scale<float> color_scale(0, size.x, sf::Color(128, 128, 128), sf::Color::Black);
		linear_scale<float, float> size_scale(0, size.x, 1, 6);

		const unsigned num_rects(15);
		sf::RectangleShape rect(sf::Vector2f(window_scale(100), window_scale(20)));
		rect.setOrigin(window_scale(50), window_scale(10));
		rect.setFillColor(sf::Color::Black);
		rect.setOutlineColor(sf::Color::White);
		rect.setOutlineThickness(window_scale(-1));

		sf::Vector2f top_left(0, 0);
		sf::Vector2f bottom_right(std::sqrt(size.x), size.y);
		maxProgress(num_rects);
		for(unsigned i = 0; i < num_rects; ++i)
		{
			float x = x_scale(randuniform(0, std::sqrt(size.x)));
			float scale = size_scale(x);
			rect.setScale(scale, scale);
			rect.setOutlineThickness(window_scale(-1)/scale);
			float y = linear_scale<float, float>(0, size.y, upper_top(x), upper_bottom(x))(randuniform(0, size.y));
			rect.setFillColor(color_scale(x));
			rect.setPosition(x, y);
			rects.push_back(rect);
			addProgress(0.5);
			y = linear_scale<float, float>(0, size.y, lower_top(x), lower_bottom(x))(randuniform(0, size.y));
			rect.setFillColor(sf::Color::Black);
			rect.setPosition(x, y);
			rects.push_back(rect);
			addProgress(0.5);
		}
		std::sort(rects.begin(), rects.end(), [](const sf::RectangleShape& lhs, const sf::RectangleShape& rhs)
		{
			return lhs.getPosition().x > rhs.getPosition().x;
		});

	}
Exemple #3
0
static int		get_diffuse(t_ray *ray, t_ray *light, t_spot *spot)
{
	double		dotprod;

	dotprod = mat_dot_product(&(light->dir), &(ray->normal));
	if (dotprod < 0)
		return (0);
	return (color_scale(ray->obj->param.color,
		dotprod * spot->param.diffuse * ray->obj->param.diffuse));
}
Exemple #4
0
static int		get_specular(t_ray *ray, t_ray *light, t_spot *spot)
{
	t_matrix		tmp;
	double			dotprod;

	dotprod = mat_dot_product(&(light->dir), &(ray->normal));
	tmp = M_DIR(
		M_IJ(&(light->dir), 0, 0) - 2 * dotprod * M_IJ(&(ray->normal), 0, 0),
		M_IJ(&(light->dir), 1, 0) - 2 * dotprod * M_IJ(&(ray->normal), 1, 0),
		M_IJ(&(light->dir), 2, 0) - 2 * dotprod * M_IJ(&(ray->normal), 2, 0));
	dotprod = mat_dot_product(&tmp, &ray->dir);
	if (dotprod < 0)
		return (0);
	dotprod = pow(dotprod, ray->obj->param.shininess);
	//changement couleur ici
	return (color_scale(0xffffff, dotprod
	* ray->obj->param.specular
	* spot->param.specular));
}
Exemple #5
0
Color renderAntiAliasedPixel(int x, int y, Scene scene, RenderStats* r){
  float x1 = (float) x / (float) scene.width;
  float x2 = ((float) x + 0.5)  / (float) scene.width;
  float y1 = (float) y / (float) scene.height;
  float y2 = ((float) y + 0.5)  / (float) scene.height;
  Ray ray1 = scene.camera.getRay(x1, y1);
  Ray ray2 = scene.camera.getRay(x1, y2);
  Ray ray3 = scene.camera.getRay(x2, y1);
  Ray ray4 = scene.camera.getRay(x2, y2);

  Color avg = trace(ray1, 0, scene, r);
  avg = color_add(avg, trace(ray2, 0, scene, r));
  avg = color_add(avg, trace(ray3, 0, scene, r));
  avg = color_add(avg, trace(ray4, 0, scene, r));


  avg = color_scale(avg, 0.25);

  return avg;
}
Exemple #6
0
void
x_gui_rep::prepare_color (int sf, color fg, color bg) {
  int nr_cols= sf*sf;
  if (nr_cols >= 64) nr_cols= 64;
  x_character col_entry (0, font_glyphs (), sf, fg, bg);
  color* cols= (color*) color_scale [col_entry];
  if (cols == NULL) {
    int fR, fG, fB, fA, bR, bG, bB, bA, j;
    get_rgb_color (fg, fR, fG, fB, fA);
    get_rgb_color (bg, bR, bG, bB, bA);
    if (fA != 255) {
      fR= (bR * (255 - fA) + fR * fA) / 255;
      fG= (bG * (255 - fA) + fG * fA) / 255;
      fB= (bB * (255 - fA) + fB * fA) / 255;
    }
    cols= tm_new_array<color> (nr_cols+1);
    for (j=0; j<=nr_cols; j++)
      cols [nr_cols-j]= rgb_color ((bR*j + fR*(nr_cols-j)) / nr_cols,
				   (bG*j + fG*(nr_cols-j)) / nr_cols,
				   (bB*j + fB*(nr_cols-j)) / nr_cols);
    color_scale (col_entry)= (void*) cols;
  }
}
Exemple #7
0
/*! \brief Main menu screen
 *
 * This is the main menu... just display the opening and then the menu and
 * then wait for input.  Also handles loading a saved game, and the config menu.
 *
 * \param   c zero if the splash (the bit with the staff and the eight heroes)
 *            should be displayed.
 * \returns 1 if new game, 0 if continuing, 2 if exit
 */
int start_menu (int skip_splash)
{
   int stop = 0, ptr = 0, redraw = 1, a, b;
   DATAFILE *bg;
   BITMAP *staff, *dudes, *tdudes;

#ifdef DEBUGMODE
   if (debugging == 0) {
#endif
      play_music ("oxford.s3m", 0);
      /* Play splash (with the staff and the heroes in circle */
      if (skip_splash == 0) {
         bg = load_datafile_object (PCX_DATAFILE, "KQT_PCX");
         staff = create_bitmap_ex (8, 72, 226);
         dudes = create_bitmap_ex (8, 112, 112);
         tdudes = create_bitmap_ex (8, 112, 112);
         blit ((BITMAP *) bg->dat, staff, 0, 7, 0, 0, 72, 226);
         blit ((BITMAP *) bg->dat, dudes, 80, 0, 0, 0, 112, 112);
         clear_bitmap (double_buffer);
         blit (staff, double_buffer, 0, 0, 124, 22, 72, 226);
         blit2screen (0, 0);

         kq_wait (1000);
         for (a = 0; a < 42; a++) {
            stretch_blit (staff, double_buffer, 0, 0, 72, 226, 124 - (a * 32),
                          22 - (a * 96), 72 + (a * 64), 226 + (a * 192));
            blit2screen (0, 0);
            kq_wait (100);
         }
         for (a = 0; a < 5; a++) {
            color_scale (dudes, tdudes, 53 - a, 53 + a);
            draw_sprite (double_buffer, tdudes, 106, 64);
            blit2screen (0, 0);
            kq_wait (100);
         }
         draw_sprite (double_buffer, dudes, 106, 64);
         blit2screen (0, 0);
         kq_wait (1000);
         destroy_bitmap (staff);
         destroy_bitmap (dudes);
         destroy_bitmap (tdudes);
		 unload_datafile_object(bg);
         /*
            TODO: this fade should actually be to white
            if (_color_depth == 8)
            fade_from (pal, whp, 1);
            else
          */
         do_transition (TRANS_FADE_WHITE, 1);
      }
      clear_to_color (double_buffer, 15);
      blit2screen (0, 0);
      set_palette (pal);
      bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX");
      for (a = 0; a < 16; a++) {
         clear_to_color (double_buffer, 15 - a);
         masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 60 - (a * 4),
                      320, 124);
         blit2screen (0, 0);
         kq_wait (a == 0 ? 500 : 100);
      }
      if (skip_splash == 0)
         kq_wait (500);
#ifdef DEBUGMODE
   } else {
      set_palette (pal);
      bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX");
   }
#endif

   reset_world ();

   /* Draw menu and handle menu selection */
   while (!stop) {
      if (redraw) {
         clear_bitmap (double_buffer);
         masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 0, 320, 124);
         menubox (double_buffer, 112, 116, 10, 4, BLUE);
         print_font (double_buffer, 128, 124, _("Continue"), FNORMAL);
         print_font (double_buffer, 128, 132, _("New Game"), FNORMAL);
         print_font (double_buffer, 136, 140, _("Config"), FNORMAL);
         print_font (double_buffer, 144, 148, _("Exit"), FNORMAL);
         draw_sprite (double_buffer, menuptr, 112, ptr * 8 + 124);
         redraw = 0;
      }
      display_credits ();
      blit2screen (0, 0);
      readcontrols ();
      if (bhelp) {
         unpress ();
         show_help ();
         redraw = 1;
      }
      if (up) {
         unpress ();
         if (ptr > 0)
            ptr--;
         else
            ptr = 3;
         play_effect (SND_CLICK, 128);
         redraw = 1;
      }
      if (down) {
         unpress ();
         if (ptr < 3)
            ptr++;
         else
            ptr = 0;
         play_effect (SND_CLICK, 128);
         redraw = 1;
      }
      if (balt) {
         unpress ();
         if (ptr == 0) {        /* User selected "Continue" */
            if (snc[0] == 0 && snc[1] == 0 && snc[2] == 0 && snc[3] == 0
                && snc[4] == 0)
               stop = 2;
            else if (saveload (0) == 1)
               stop = 1;
            redraw = 1;
         } else if (ptr == 1) { /* User selected "New Game" */
            stop = 2;
         } else if (ptr == 2) { /* Config */
            clear (double_buffer);
            config_menu ();
            redraw = 1;

            /* TODO: Save Global Settings Here */
         } else if (ptr == 3) { /* Exit */
            unload_datafile_object (bg);
            klog (_("Then exit you shall!"));
            return 2;
         }
      }
   }
   unload_datafile_object (bg);
   if (stop == 2) {
      /* New game init */
      for (a = 0; a < MAXCHRS; a++)
         memcpy (&party[a], &players[a].plr, sizeof (s_player));
      init_players ();
      memset (progress, 0, SIZE_PROGRESS);
      memset (treasure, 0, SIZE_TREASURE);
      numchrs = 0;
      for (a = 0; a < NUMSHOPS; a++) {
         for (b = 0; b < SHOPITEMS; b++)
            shops[a].items_current[b] = shops[a].items_max[b];
      }
      for (b = 0; b < 2; b++) {
         for (a = 0; a < MAX_INV; a++)
            g_inv[a][b] = 0;
      }
   }
   return stop - 1;
}
Exemple #8
0
int main()
{
  /* xyz */
  printf(" *** testing xyz *** \n");
  xyz v = xyz_expr(1,2,3);
  xyz add = xyz_add(v,v);
  xyz vv = xyz_expr(5,5,5);
  xyz sub = xyz_sub(v,vv);
  xyz n = xyz_neg(sub);
  xyz sc = xyz_scale(1.5,v);
  xyz sc2 = xyz_scale(-3.33,n);
  double dt = xyz_dot(v,sc);
  double mag = xyz_mag(v);
  xyz z = xyz_expr(0,0,0);
  xyz zn = xyz_norm(z);
  xyz vn = xyz_norm(v);
  
  printf("xyz_expr(1,2,3) =>\t%s\n",xyz_tos(v));
  printf("(1,2,3)+(1,2,3) =>\t%s\n",xyz_tos(add));
  printf("(1,2,3)-(5,5,5) =>\t%s\n",xyz_tos(sub));
  printf("-(-4,-3,-2) =>\t%s\n",xyz_tos(n));
  printf("scale (1,2,3) by 1.5 =>\t%s\n",xyz_tos(sc));
  printf("scale (4,3,2) by -3.33 =>\t%s\n",xyz_tos(sc2));
  printf("(1,2,3)*(1.5,3,4.5) =>\t%.2lf\n",dt);
  printf("magnitude of (1,2,3) =>\t%.2lf\n",mag);
  printf("norm (0,0,0) =>\t%s\n",xyz_tos(zn));
  printf("norm (1,2,3) =>\t%s\n",xyz_tos(vn));
  printf(" *****\n");

  /* color */
  printf(" *** testing color *** \n");
  color c = color_expr(1,0.5,0);
  color cc = color_expr(0.75,0,0.25);
  color mod = color_modulate(c,cc);
  color scc = color_scale(1.5, cc);
  color addc = color_add(c,cc);

  printf("color_expr(1,0.5,0) =>\t%s\n",color_tos(c));
  printf("(1,0.5,0)*(0.75,0,0.25) =>\t%s\n",color_tos(mod));
  printf("scale (0.75,0,0.25) by 1.5 =>\t%s\n",color_tos(scc));
  printf("(1,0.5,0)+(0.75,0,0.25) =>\t%s\n",color_tos(addc));
  printf("(0.75,0,0.25) on [0,255] =>");
  color_show_bytes(stdout,cc);
  printf(" *****\n");

  /* ray */
  printf(" *** testing ray *** \n");
  ray testray = {v,vv};
  printf("ray from (1,2,3) to (5,5,5) =>\t%s\n",ray_tos(testray));
  printf(" *****\n");

  /* sphere */
  printf(" *** testing sphere *** \n");
  sphere testsph = sphere_expr(v, 3.2, get_sc, c);
  printf("sphere at (1,2,3) with radius 3.2:\n");
  sphere_show(stdout,testsph);
  printf("\n *****\n");

  /* poster */
  printf(" *** testing poster *** \n");
  poster testpst = poster_expr(v, 4, 5.25, get_sc, c);
  printf("poster at (1,2,3) with width 4 and height 5.25:\n");
  poster_show(stdout,testpst);
  printf("\n *****\n");

  /* object */
  printf(" *** testing object *** \n");
  object objs = {SPHERE,{.s = testsph},NULL};
Exemple #9
0
/**
 * Start rendering a scene.
 * \param s Scene to render.
 * \param
 * \param pixmap Pointer to pixel map with result.
 * Must be large enough to hold #y0 - #y1 rows.
 */
void renderer_render(const struct scene *s, const struct renderer_chunk *chunk,
	struct color *pixmap){
	unsigned ymax = chunk->top + chunk->height;

	// How many meters per pixel.
	float inc = s->sensorWidth / (float)(s->width - 1);

	float yy = inc * ((float)(s->height) / 2 - chunk->top);

	float focus = s->focus / s->focalLength;

#if MEASUREMENTS_WITH_WARMUP
	MEASUREMENTS_WARMUP();
#endif
	MEASUREMENTS_START();

	for(unsigned y = chunk->top; y < ymax; ++y){
		float xx = - s->sensorWidth / 2;
		for(unsigned x = 0; x < s->width; ++x){
			color_black(pixmap);
			for(unsigned i = 0; i < s->raysPerPx; ++i){
				struct ray r;

				// filmPoint = {
				// 	-xx - random_number(0, inc),
				// 	-yy - random_number(0, inc),
				// 	-s->focalLength
				// 	}
				// focusPoint = - (lensCenter - filmPoint) * (s->focus / filmPoint.z)

				vector_t focusPoint = vector_set(
					focus * (xx + random_number(0, inc)),
					focus * (yy + random_number(0, inc)),
					s->focus);

				vector_t lensPoint = vector_multiply(vector_random_in_circle(), s->apertureDiameter);

				ray_from_points(&r, lensPoint, focusPoint);

#ifndef MEASUREMENTS_KD_TREE_STATS
				struct photon p;
				photon_random_init(&p);

				p.energy = render_ray(s, &r, p.wavelength, 0);

				photon_add_to_color(&p, pixmap);
#else
				struct object *obj;
				MEASUREMENTS_RAY_SCENE_INTERSECTION();
				kd_tree_ray_intersection(&(s->tree), &r, &obj);
				pixmap->r += measurementsObjectIntersectionCounter;
				pixmap->g += measurementsTreeTraversalCounter;
#endif
			}
			color_scale(pixmap, 1.0f / s->raysPerPx);

			//printf("x = %i y = %i pixmap->r = %.2f\n", x, y ,pixmap->r);
			++pixmap;

			xx += inc;
		}
		yy -= inc;
	}

	MEASUREMENTS_PRINT();
}