Esempio n. 1
0
static void
Main()
{
  HorizonLook horizon_look;
  horizon_look.Initialise();

  WindowStyle with_border;
  with_border.Border();

  HorizonWindow horizon(horizon_look);
  horizon.Create(main_window, main_window.GetClientRect(), with_border);
  main_window.SetFullWindow(horizon);

  auto timer = MakeLambdaTimer([&horizon](){
      AttitudeState attitude;
      attitude.bank_angle_computed = true;
      attitude.pitch_angle_computed = true;
      attitude.bank_angle = Angle::Zero();
      attitude.pitch_angle = Angle::Zero();

      horizon.SetAttitude(attitude);
    });
  timer.Schedule(250);

  main_window.RunEventLoop();

  timer.Cancel();
}
Esempio n. 2
0
void a4_render(// What to render
               SceneNode* root,
               // Where to output the image
               const std::string& filename,
               // Image size
               int width, int height,
               // Viewing parameters
               const Point3D& eye, const Vector3D& view,
               const Vector3D& up, double fov,
               // Lighting parameters
               const Colour& ambient,
               const std::list<Light*>& lights,
               double fogDist
               )
{
  // Fill in raytracing code here.

  std::cerr << "Stub: a4_render(" << root << ",\n     "
            << filename << ", " << width << ", " << height << ",\n     "
            << eye << ", " << view << ", " << up << ", " << fov << ",\n     "
            << ambient << ",\n     {";

  for (std::list<Light*>::const_iterator I = lights.begin(); I != lights.end(); ++I) {
    if (I != lights.begin()) std::cerr << ", ";
    std::cerr << **I;
  }
  std::cerr << "});" << std::endl;

  Vector3D viewVector = view;
  Vector3D upVector = up;
  Vector3D sideVector = viewVector.cross(upVector);
  viewVector.normalize();
  upVector.normalize();
  sideVector.normalize();
  
  Image img(width, height, 3);

  int progress = 0;
  int numPixels = width*height;
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      int newProgress = (int)((double)(y*width + x)/numPixels*100);
      if(newProgress >= progress+5){
        progress = newProgress;
        std::cerr << progress << std::endl;
      }

      double d = height/2.0/tan(toRadian(fov)/2);
      Vector3D dir = (x-(width/2.0))*sideVector + 
          ((height/2.0)-y)*upVector + d*viewVector;
      dir.normalize();
      Ray ray = Ray(eye, dir);

      bool fogOn = true;
      if(fogDist <= 0)
        fogOn = false;
      Colour* color = rayTrace(ambient, eye, ray, root, lights, 5, fogDist);
      Colour fog(1,1,1);
      if(color == NULL) {
        // sunset colours
        Colour horizon(0.94, 0.55, 0.05);
        Colour zenith(0.2, 0.27, 0.4);
        Colour bg = zenith*(1-(double)y/height) + horizon*((double)y/height);
        if(fogOn)
          color = new Colour(0.8,0.8,0.8);
        else
          color = new Colour(bg);
      }

      img(x, y, 0) = color->R();
      img(x, y, 1) = color->G();
      img(x, y, 2) = color->B();
    }
  }
  img.savePng(filename);
  
}
Esempio n. 3
0
/*! \fn void horizon(float zoom,int abs,int ord,int **tab)
* \author  Florian Chaulet Frederic Torcheux Pauline de Bouet du Portal.
* \version 0.1
* \date 14 Novembre 2011
* \brief Dessine une fractale flamme ayant pour forme l'horizon
* \param zoom valeur du zoom, grossissement de la fractale
* \param abs decalage sur l'axe horizontal en fonction de l'appui sur les touches directionnelles
* \param ord decalage sur l'axe vertical en fonction de l'appui sur les touches directionnelles
* \param **tab tableau permettant de voir combien de fois un point apparait a une certaine coordonnee
*/
void horizon(float zoom,int abs,int ord,int **tab){
    /* Initialisation des differentes variables
       Variable de zoom*/

    /*Evenement molette */
    SDL_Event event;
    int continuer=1;



	int j,k,z;
	int couleur;
	int i1,i2,i3;
	int i,r;
	int val1,val2,val3,val4;

	/* Determine la taille de l'image */
	int image_x;
	int image_y;

    	/* Création de surface */
	SDL_Surface *ecran = NULL, *pixel99 = NULL ;
	SDL_Rect position1;
	SDL_Rect position2;
	SDL_Rect position3;

    	float a,b,c,d,e,f;/* un point est un couple de coordonnées*/

	/*chargement des donnes contenues dans flamme.txt*/
	chargementModif("flamme.txt",&val1,&val2,&val3,&val4);

	/*affectation des donnees recuperees aux variables du programme*/
	image_x = val1;
	image_y = val2;
if(zoom == -1)zoom = val3;

	tab = (int*)malloc(image_x * sizeof(int*));
	for(i3 = 0; i3 < image_x; i3++){
		tab[i3] = (int)malloc(image_y * sizeof(int));
	}

	/*on initialise notre pixel*/
	pixel99 = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, 1,32, 0, 0, 0, 0);
	
	/*initialisation des cases du tableau  0*/
	for(i1=0;i1<image_x;i1++) {
		for(i2=0;i2<image_y;i2++) {
			tab[i1][i2] = 0;
		}
	}

    /* On affecte une valeur au 3 point : (a,b) , (c,d) et (e,f)*/
	a = 100*2;
	b = 50*2;
	c = 50*2;
	d = 100*2;
	e = 100*2;
	f = 100*2;

    /* Parametrage SDL*/
	ecran = initialisationEcranTitre(ecran, image_x, image_y, "Flamme Horizon");
  	srand(time(NULL));


    /*Fonction de traçage*/
	for(i=0;i<val4;i++) {
        r = rand() %10;
        if(r == 1 || r == 2){
            a = tan (a);
            b = tan (b);
            c = tan (c);
            d = tan (d);
            e = tan (e);
            f = tan (f);
        }
        else{
            a = cos (a);
            b = tan (b);
            c = sin (c);
            d = tan (d);
            e = cos (e);
            f = sin (f);
        }
        /* positionne les pixels / points au centre de l'ecran*/
    position1.x = (a * zoom + image_x / 2)+abs;
    position1.y = (b * zoom + image_y / 2)+ord;
    position2.x = (c * zoom + image_x / 2)+abs;
    position2.y = (d * zoom + image_y / 2)+ord;
    position3.x = (e * zoom + image_x / 2)+abs;
    position3.y = (f * zoom + image_y / 2)+ord;

		if ((position1.x < image_x) && (position1.y < image_y) && (position1.x >=0) && (position1.y >=0)){
		tab[(int)position1.x][(int)position1.y] = tab[(int)position1.x][(int)position1.y] +1;
		}
		if ((position2.x < image_x) && (position2.y < image_y) && (position2.x >=0) && (position2.y >=0)){
		tab[(int)position2.x][(int)position2.y] = tab[(int)position2.x][(int)position2.y]+1;
		}
		if ((position3.x < image_x) && (position3.y < image_y) && (position3.x >=0) && (position3.y >=0)){
		tab[(int)position3.x][(int)position3.y] =tab[(int)position3.x][(int)position3.y]+1;
		}
	}


	for (j=0;j<image_x; j++){
		for (k=0;k<image_y; k++){
			if(j > 0 && k > 0 && j < image_x-1 && k < image_y-1){
				couleur=(tab[j-1][k-1]+tab[j-1][k]+tab[j-1][k+1]+tab[j][k-1]+tab[j][k+1]+tab[j+1][k-1]+tab[j+1][k]+tab[j+1][k+1])/8;
			}
			
			position1.x = j;
			position1.y = k;
			
			SDL_FillRect(pixel99, NULL, SDL_MapRGB(pixel99->format, couleur, couleur, couleur));
			SDL_BlitSurface(pixel99, NULL, ecran, &position1);
		}
	}
    /*Dessine l'ecan et les elements collés*/

         while (continuer)
        {
        SDL_PollEvent(&event);
        if( event.type == SDL_MOUSEBUTTONUP ){
                    if( event.button.button == SDL_BUTTON_WHEELUP ){
                                zoom=zoom+10;
				continuer = 0;
                                horizon(zoom,abs,ord,tab);

                    }

                }
                else if( event.type == SDL_MOUSEBUTTONDOWN ){
                    if( event.button.button == SDL_BUTTON_WHEELDOWN ){
                                zoom=zoom-10;
				continuer = 0;
                                horizon(zoom,abs,ord,tab);
                    }

                }

                switch(event.type){
                    case SDL_QUIT:
                        continuer = 0;
                        break;
                    case SDL_KEYDOWN:
                        switch(event.key.keysym.sym){
                                case SDLK_UP:
                                    ord=ord+100;
				continuer = 0;
                                   horizon(zoom,abs,ord,tab);
                                    break;
                                case SDLK_DOWN:
                                    ord=ord-100;
				continuer = 0;
                                    horizon(zoom,abs,ord,tab);
                                    break;
                                case SDLK_RIGHT:
                                    abs=abs+100;
				continuer = 0;
                                    horizon(zoom,abs,ord,tab);
                                    break;
                                case SDLK_LEFT:
                                    abs=abs-100;
					continuer = 0;
                                    horizon(zoom,abs,ord,tab);
                                    break;
                            }
                            break;
                }
    SDL_Flip(ecran);
          }
    /*Libere les données les pixels*/
    libererMem(ecran, pixel99);
}