Example #1
0
void init_height_map_from_bmp(char *mapfile)
{
	point p;
	int i, j;
	SDL_Surface *img;
	img = SDL_LoadBMP(mapfile);
	SDL_LockSurface(img);
	for(i=0; i<LENGTH; i++)
	{
		for(j=0; j<HEIGHT; j++)
		{
			Uint8 *red, *green, *blue;
			p = to_world(point(i,j));
			world_coord_map[i][j] = vector(p.x, p.y, 0);
			int img_x = img->h / HEIGHT;
			int img_y = img->w / LENGTH;
			Uint32 pix = getpixel(img, i, j);
			SDL_Color color = getColor(pix, img->format);
			//			std::cout<<"test"<<color.r;
			//SDL_GetRGB(pix, img->format, red, green, blue);
			//double value = (red + green + blue) / 768;
			//std::cout<<"Value ="<<value<<std::endl;
			map[i][j] = (double)pix / (img->format->BytesPerPixel * 256);
		}
	}
	SDL_UnlockSurface(img);
	SDL_FreeSurface(img);
}
Example #2
0
bool do_input(point& p_mouse, light_source &light)
{
  SDL_Event d;
  while (SDL_PollEvent(&d))
    {
      if (d.type == SDL_QUIT)
        return false;
      
      if (d.type == SDL_MOUSEMOTION)
	{
	  int x,y;       // Mouse position in screen coordinates
	  SDL_GetMouseState(&x, &y);
	  //	  p_mouse = point(x/(float)LENGTH*(X2-X1)+X1, (float)y/HEIGHT*(Y2-Y1)+Y1);
	  p_mouse = to_world(point(x,y));
	  light.loc.x = p_mouse.x;
	  light.loc.y = p_mouse.y;
	  redraw = true;
	  //	  	  std::cout << map[x][y] << std::endl;
	}	

      if (d.type == SDL_MOUSEBUTTONDOWN)
	{
	  switch(d.button.button)
	    {
	    case 4:
	      if (light.loc.z > .3)
		light.loc.z -= .2;
	      break;
	    case 5:
	      light.loc.z += .2;
	      break;
	    }
	  //std::cout << "Light location changed to: " << light.loc << std::endl;

	}

      if (d.type == SDL_KEYDOWN)
        {
          switch (d.key.keysym.sym)
            {
	    case (SDLK_q):
	      {
		return false;
		break;
	      } 
            }
        }
    }
  return true;
 }
Example #3
0
void init_height_map()
{
  int i, j;
  point p;
  double temp;
  for (i=0; i<LENGTH; i++)
    for (j=0; j<HEIGHT; j++) {
      p = to_world(point(i,j));
      world_coord_map[i][j] = vector(p.x, p.y, 0);
      temp = f(p);
      // Set boundaries to 0, for sanity
      //      if (i==0 || j==0 || i==(LENGTH-1) || j==(HEIGHT-1))
      //	  temp = 0;
      map[i][j] = temp;
      old_map[i][j] = temp;
    }
}
Example #4
0
int DiagSplit::T(Patch *patch, float2 Pstart, float2 Pend)
{
	float3 Plast = make_float3(0.0f, 0.0f, 0.0f);
	float Lsum = 0.0f;
	float Lmax = 0.0f;

	for(int i = 0; i < params.test_steps; i++) {
		float t = i/(float)(params.test_steps-1);

		float3 P = to_world(patch, Pstart + t*(Pend - Pstart));

		if(i > 0) {
			float L;

			if(!params.camera) {
				L = len(P - Plast);
			}
			else {
				Camera* cam = params.camera;

				float pixel_width = cam->world_to_raster_size((P + Plast) * 0.5f);
				L = len(P - Plast) / pixel_width;
			}

			Lsum += L;
			Lmax = max(L, Lmax);
		}

		Plast = P;
	}

	int tmin = (int)ceil(Lsum/params.dicing_rate);
	int tmax = (int)ceil((params.test_steps-1)*Lmax/params.dicing_rate); // XXX paper says N instead of N-1, seems wrong?

	if(tmax - tmin > params.split_threshold)
		return DSPLIT_NON_UNIFORM;
	
	return tmax;
}