Ejemplo n.º 1
0
void Test_Surface::testFunction(Surface &f) {
  qsrand(1);
  ParameterMap parameters = f.getParameters();
//  cerr << f.getFunctionName().toStdString() << " parameters ("<< parameters.size() << "): " << parameters.toString() << endl;
  f(0.,0.);
  VecMath::Rotation<4> r(random_number<double>(), random_number<double>(), random_number<double>(), random_number<double>(), random_number<double>(), random_number<double>());
  VecMath::Vector<4> t(random_number<double>(), random_number<double>(), random_number<double>(), random_number<double>());
  f.Transform(r, t);
  f.Project(2., 4., false);
  f.Draw(view_);
  f.ReInit(1., 1., 1., -2., 2., 0.2, -2., 2., 0.2);
}
Ejemplo n.º 2
0
Archivo: Map.cpp Proyecto: ZealousV/ART
void Map::DrawBackground(Window screen, Graphics* assets){
	Point2D dim = GetMapDimension();
	Surface* surface =& (assets->forest[0]);
	Surface* parallax = & (assets->forestParallax);
	int forestStart = (int)dim.Y;//The bottom of the map

	int Xstart = 0;
	int Xcount = 0;
	int parallaxStartX =0;
	//(Bottom of map - (the current camera position + the height of the screen)) divided by the height of the background surface -1
	//== (bottom of map - the bottom of the screen)/height of background -1
	//==how many backgrounds are already beneath this position?
	int Ycount = (int)((forestStart - (_mapPosition.Y+screen.GetHeight())) / surface->GetHeight()) - 1;
	//the starting point for the background to draw
	int Ystart = (int)dim.Y - surface->GetHeight()*Ycount;
	while(Ystart>_mapPosition.Y){
		//The vertical height determines the kind of background
		surface->SetTransparency(255);
		if(Ycount == 0)
		{surface = &(assets->forest[0]); parallax=&(assets->forestParallax);}
		else if(Ycount == 1)
		{surface =&( assets->air[0]);parallax=0;}
		else if(Ycount == 2)
		{surface = &(assets->space1);parallax=0;}
		else if(Ycount < 0)
		{surface->SetTransparency(0);parallax=0;}
		else {surface = &(assets->space2);parallax=0;}
		//This one is handled, go the next one
		Ystart -= surface->GetHeight();
		//The starting position of the next background to render
		Xstart = (int)(_mapPosition.X - ((Uint32)_mapPosition.X % (Uint32)surface->GetWidth()));
		//How many backgrounds are already left of this?
		Xcount = (int)(_mapPosition.X/surface->GetWidth());
		if (parallax!=0 && parallax->IsInit())
		{
			int parallaxStartX=(int)(_mapPosition.X/2 - ((Uint32)(_mapPosition.X/2) % (Uint32)parallax->GetWidth()));
			while(parallaxStartX < _mapPosition.X + screen.GetWidth()){		
				parallax->Draw(screen,(Uint32)(parallaxStartX-_mapPosition.X/2), (Uint32)(Ystart-_mapPosition.Y)+400);
				parallax->Draw(screen,(Uint32)(parallaxStartX-_mapPosition.X/2), (Uint32)(Ystart-_mapPosition.Y)+400);
				parallaxStartX += parallax->GetWidth();
			}
		}
		while(Xstart < _mapPosition.X + screen.GetWidth()){
			//Handle the current image for the looping backgrounds
			if(Ycount == 1){
				if(Xcount>2)Xcount = Xcount%3;
				surface = &(assets->air[Xcount]);
				Xcount++;
			}
			else if(Ycount == 0){
				if(Xcount>3) Xcount = Xcount%4;
				surface = &(assets->forest[Xcount]);
				Xcount++;
			}
			surface->Draw(screen, (Uint32)(Xstart-_mapPosition.X), (Uint32)(Ystart-_mapPosition.Y));	
			Xstart += surface->GetWidth();
		}
		Ycount++;
	}
			
}
Ejemplo n.º 3
0
/** @brief Open the frame file and construct the image of the frame
  */
bool WindowBox::BuildFrame()
{
  // only bother if we have a frame template
  if (!FrameVisible) {
    return false;
  }
  FrameSurface.Init(Size.W, Size.H);

  Surface spritePage;
  if (!spritePage.LoadImage(FRAMES_DIR + SLASH + FrameName + ".png")) {
    LOG(FrameName + " - frame image missing");
    FrameVisible = false;
    return false;
  } else if (spritePage.W != GRID * 4) {
    const real scale = (real)GRID * (real)4 / (real)spritePage.W;
    spritePage.Zoom(scale, scale);
    LOG("frame image size incorrect, scaling to fit");
  }

  // sprite image layout
  // 00C 01M 02E 03C   corner middle edge corner
  // 04M 05M 06I 07M   middle middle icon middle
  // 08E 09D 10U 11E   edge    down   up   edge
  // 12C 13M 14E 15C   corner middle edge corner

  Rect src(GRID, GRID);
  Rect dst(GRID, GRID);

  // create the base frame
  for (szt i = 0, colS = Size.W / GRID; i < colS; ++i) {
    for (szt j = 0, rowS = Size.H / GRID; j < rowS; ++j) {
      szt index;
      if (j == 0) {
        if (i == 0) {
          index = 0;
        } else if (i == colS / 2 && colS > 8) {
          index = 1;
        } else if (i < colS - 1) {
          index = 2;
        } else {
          index = 3;
        }
      } else if (j < rowS - 1) {
        if (i == 0) {
          if (j == rowS / 2 && rowS > 8) {
            index = 4;
          } else {
            index = 8;
          }
        } else if (i < colS - 1) {
          index = 5;
        } else {
          if (j == rowS / 2 && rowS > 8) {
            index = 7;
          } else {
            index = 11;
          }
        }
      } else {
        if (i == 0) {
          index = 12;
        } else if (i == colS / 2 && colS > 8) {
          index = 13;
        } else if (i < colS - 1) {
          index = 14;
        } else {
          index = 15;
        }
      }
      src.X = GRID * (index % 4);
      src.Y = GRID * (index / 4);
      dst.X = GRID * i;
      dst.Y = GRID * j;
      spritePage.SetClip(src);
      spritePage.Draw(FrameSurface, dst);
    }
  }

  // create icons
  FrameUp.Init(GRID, GRID);
  FrameIcon.Init(GRID, GRID);
  FrameDown.Init(GRID, GRID);
  src.X = GRID * 2;
  src.Y = GRID * 2;
  spritePage.SetClip(src);
  spritePage.Draw(FrameUp);
  src.X = GRID * 2;
  src.Y = GRID * 1;
  spritePage.SetClip(src);
  spritePage.Draw(FrameIcon);
  src.X = GRID * 1;
  src.Y = GRID * 2;
  spritePage.SetClip(src);
  spritePage.Draw(FrameDown);

  // set up icon locations
  UpDst.W = UpDst.H = GRID;
  UpDst.X = Size.X + Size.W - 2 * GRID;
  UpDst.Y = Size.Y;
  DownDst.W = DownDst.H = GRID;
  DownDst.X = UpDst.X;
  DownDst.Y = Size.Y + Size.H - GRID;
  IconDst.W = IconDst.H = GRID;
  IconDst.X = Size.X + Size.W - GRID;
  IconDst.Y = Size.Y + GRID;

  return true;
}