Esempio n. 1
0
void Building::drawTowerRange()
{
      glPushAttrib(GL_COLOR_MATERIAL | GL_CURRENT_BIT | GL_ENABLE_BIT); 
      glPushMatrix();      
//      glEnable(GL_ALPHA_TEST);
      glTranslatef(position.x, position.y, position.z);
      
      float col[] = {0.5, 1.0, 1.0, 0.3 };
      glMaterialfv(GL_FRONT, GL_AMBIENT, col);
      Assets::greenRange->texture->bind();
      drawTexture(Vector3(0,2,0), Vector3(0,1,0), calcRange() * 2, Assets::greenRange);
      glBindTexture(GL_TEXTURE_2D, 0);      
      glPopMatrix();
      glPopAttrib();
}
Esempio n. 2
0
int getLook(GEOLOCATE_REC *g,double range,double yaw,double *plook)
{
  double ht,delta_range,look;
  double coslook;
  double earth_radius;
  int iter;

  /* The lowest point on Earth is the shore of the Dead Sea (Isreal/Jordan),
     and is 417.5 meters below sea level.  Worst case range should not
     indicate a level lower than this.  The 450.0 m tolerance below was
     selected as a number larger than this because a) the code uses a simple
     spherical model based on the earth radius at the center of the scene,
     and b) look angle results in a range vector longer than what the range
     would've been if the lowest spot on earth fell on the NADIR line.
  */
  double range_tolerance = 450.0; /* meters */

  /* Look angle in y'z' plane, Yaw angle in z''x' plane.
     First guess at a look angle-- a simple spherical guess: */
  /*
     NOTE: This function is only called when working with slant range
     and ground range (meta->sar->image_type == 'S' or 'G') images
     but not for map-projected data ...otherwise, the earth radius
     at center of scene may not be populated depending upon the source of
     the image data, e.g. if imported and geocoded entirely by ASF tools
     then the earth_radius field in the SAR portion of the metadata
     _would_ be populated, but if a GeoTIFF (for example) were imported
     then only the major/minor fields in the projection block would be
     populated, not the earth_radius field in the SAR block ...the
     init_geolocate_meta() takes this into account for the polar
     radius (g->rp) regardless, populates g->earth_radius for SAR
     images, but ignores g->earth_radius for projected images.  But as
     mentioned, this is OK since getLook() is only for 'S' and 'G'
     (SAR) images.
  */

  if (meta_is_valid_double(g->earth_radius)) {
    earth_radius = g->earth_radius;
  }
  else {
    earth_radius = g->rp;
    // FIXME: Else obtain from calcRange() ?  Else default to polar radius ?
  }

  ht=vecMagnitude(g->stVec.pos);
  if (range < (ht - earth_radius) - range_tolerance) {
      asfPrintWarning("getLook(): Range vector does not reach earth!\n");
      return 1;
  }
  if (ht < earth_radius - range_tolerance) {
      asfPrintWarning("getLook(): orbit is below earth's surface!\n");
      return 1;
  }

  /* Calculate look angle */
  coslook = (ht*ht+range*range-earth_radius*earth_radius)/(2.0*range*ht);
  if (!meta_is_valid_double(coslook)) {
      asfPrintWarning("getLook(): coslook was NaN!\n");
      return 1;
  }
  if (coslook > 1.0) {
      asfPrintWarning("getLook(): cosine(look angle) resulted in a value "
                      "larger than 1.0!\n");
      return 1;
  }
  look = acos(coslook);

  /* For a left-looking SAR, we define the look angle to be negative.*/
  if ( g->side == 'L')
    look=-look;

  /* FIXME: The use of an unweighted earth radius at center of scene will
     result in larger errors in regions of the image that are far (corners)
     from where the earth_radius value is accurate.  This may be an issue
     for wide-swath images such as ScanSAR.
  */
  for (iter=0;iter<100;iter++) {
    double sininc,taninc;
    delta_range = range - calcRange(g,look,yaw);
    /* Require decimeter convergence.  */
    if (fabs(delta_range) < 0.1) {
      *plook = look;
      return 0;
    } else { /* Havn't converged yet, so update look angle.  */
      sininc = (ht/earth_radius)*sin(look);   /* sin of inci. angle(approx) */
      taninc = sininc/sqrt(1-sininc*sininc);   /* tan of inci. angle */
      /* The linear approximation of atan should be applicable for
         these small arguments.  */
      look += delta_range/(range*taninc);   /* update for look angle */
    }
  }

  /*If we get here, our look iteration hasn't converged.*/
  asfPrintWarning("Error in getLook(): look iteration didn't converge.\n");
  return 1;
}
Esempio n. 3
0
int getDoppler(GEOLOCATE_REC *g,double look,double yaw,
               double *fd, double *fdot,
               vector *out_targPos,vector *out_relVel)
{
	vector relPos, /*Vector from spacecraft to targPos.*/
		sarPos, /*Position of spacecraft*/
		targPos, /*Position of target point.*/
		relVel, /*Relative velocity vector.*/
		sarVel, /*Velocity of spacecraft*/
		targVel, /*Velocity of targPos*/
		sarAcc, /*Accelleration of spacecraft*/
		targAcc, /*Accelleration of targPos*/
		relAcc; /*Relative sarAccelleration*/
	double range,angVel=g->angularVelocity;
	sarPos=g->stVec.pos;
	sarVel=g->stVec.vel;
	relPos.x= sin(yaw);
	relPos.y=-sin(look)*cos(yaw);
	relPos.z=-cos(look)*cos(yaw);
/*c   relPos unit vector points from s/c to targPos.  Rotate into earth axes:*/
	vecMul(g->look_matrix,relPos,&relPos);
/*c   scale relPos so it reaches from s/c to targPos */
	range = calcRange(g,look,yaw);
	vecScale(&relPos,range);
	vecAdd(relPos,sarPos,&targPos);
/*c
c
c  Now we have all three vectors in earth centered coordinates:
c     sarPos = sar satellite position
c     relPos = range vector from sar to targPos
c     targPos = target position
c
c   calculate velocity vectors targVel and relVel.
c*/
	targVel.x= -angVel*targPos.y;
	targVel.y= angVel*targPos.x;
	targVel.z= 0.0;
	vecSub(targVel,sarVel,&relVel);
/*c
c  Calcuate accelerations of sar and targPos sarAcc,targAcc
c  */
	sarAcc.x=0.0;
	sarAcc.y=0.0;
/*c     sar sarAcceleration toward earth center, via
   orbital considerations (accelleration is straight down,
   at      -GxMe / h**2) */
	sarAcc.z=-g->gxMe/vecDot(sarPos,sarPos);
	vecMul(g->look_matrix,sarAcc,&sarAcc);/* !put in e.c. coordinates
c   calculate sarAcceleration of targPos on earth surface:*/
	targAcc.x=-targPos.x*angVel*angVel;
	targAcc.y=-targPos.y*angVel*angVel;
	targAcc.z=0.0;
	vecSub(targAcc,sarAcc,&relAcc);
/*c
c   calculate doppler parameters
c*/
	if (out_targPos)
		*out_targPos=targPos;
	if (out_relVel)
		*out_relVel=relVel;
	if (fd)
		*fd=-2.0/(g->lambda*range)*vecDot(relPos,relVel);
	if (fdot)
		*fdot=-2.0/(g->lambda*range)*(vecDot(relVel,relVel)+vecDot(relPos,relAcc));

        /* success */
        return 0;
}
Esempio n. 4
0
struct SousReseau{
    int adresse[32];
    int masquecidr;
}
//*********************-Main-*********************
main(){
    int i,j,k,n,numberInt,maskcidr,choice,valToConv,nbSousRes,nbAdresses;
    int ipDecInt4[4],maskDecInt4[4],networkDecInt4[4],ipBinInt32[32],maskBinInt32[32],networkBinInt32[32],tabBinInt8[8],firstAdress4[4],lastAdress4[4],nextNetworkBinInt32[32],nextNetworkDecInt4[4],temp4[4],broadcastAdress4[4],nbAdressSousRes[32],rangeResBroadAd4[4] ;
    int masqueBin[32];
    int AdresseSousReseau[32][32];
    int rangeResBroadAd[4],rangeResNetworkAd[4];
    int rangeResNetworkAd4[4];
    int masquecidr,temp2,temp3;
    char ipChar100[100],masqueChar100[100],temp[4],binToDec32[32];
    char point=0; // Permet de verifié la structure de l'adresse ip donnée
    for( j=0 ; j<4 ; j++ ) // Initialisation des tableaux ip et masque à 0;
    {
        ipDecInt4[j] = maskDecInt4[j] = 0;
    }
    for ( j=0 ; j<32 ; j++)
    {
        ipBinInt32[j] = maskBinInt32[j] = 0 ;
    }
    sayHello();
    while (i != 6)
    {
        printf("\n");
        printf("***************** MENU PRINCIPAL *****************\n");
        printf("Entrez une valeur correspondant a votre choix :\n");
        printf("1) Saisir une adresse ip en mémoire\n");
        printf("2) Saisir un masque de sous réseau en mémoire\n");
        printf("---------------------------------------------------\n");
        printf("3) Info réseau actuellement en mémoire\n");
        printf("4) Conversion\n");
        printf("5) Sous-réseau\n");
        printf("6) Quitter\n");
        printf("**************************************************\n");
        if ( checkIfAdressExist(ipDecInt4,0) == 1 )
        {
            printf("ip actuellement en mémoire :     ");
            printAdress4(ipDecInt4);
        } else printf("Aucune adresse ip n'est actuellement en mémoire\n");
        if ( checkIfAdressExist(maskDecInt4,1) == 1 )
        {
            printf("Masque actuellement en mémoire : ");
            printAdress4(maskDecInt4) ;
        } else printf("Aucun masque n'est actuellement en mémoire\n");
        if ( checkIfAdressExist(ipDecInt4,0) == 1 && checkIfAdressExist(maskDecInt4,1) == 1 )
        { 
            saveNetworkAdresse(ipBinInt32,ipDecInt4,maskBinInt32,maskDecInt4,networkBinInt32,networkDecInt4);
            printf("Adresse réseau calculée :        ");
            printAdress4(networkDecInt4);
        }
        printf("**************************************************\n");
        scanf("%d",&i);
        switch (i){
        case 1 :
        printf("************* Saisie de l'adresse IP *************\n");
        if ( checkIfAdressExist(ipDecInt4,0) == 1 )
        {
            printf("Adresse ip actuellement en mémoire\n");
            printAdress4(ipDecInt4);
        } else { printf("Aucune adresse ip n'est rentrée en mémoire\n");}
        do{ 
            scanf("%s",ipChar100); // On demande une ip que l'on stock dans char100
            n = checkAdress(ipChar100,0) ; // On vérifie la validité de l'ip
            if ( n == 1 )
            {
                printf("Adresse IP valide\n");
                saveAdress(ipChar100,ipDecInt4,ipBinInt32,0); // Si l'ip est valide on sauvegarde l'ip donné dans le tableau ipDecInt4
            }
        } while ( n  != 1);  // tant que l'ip n'est pas valide : reprompt
        break;
      
        case 2 :
        printf("Entrez 1 pour saisir un masque en format adresse\n(xxx.xxx.xxx.xxx)\n");
        printf("Entrez 2 pour saisir un masque en format cidr (/xx)\n");
        scanf("%d",&choice);
        switch (choice){
            case 1 :
            printf("******** Saisie du masque : Format Adresse ********\n");
            if ( checkIfAdressExist(maskDecInt4,1) == 1 )
            {
                printf("Masque actuellement en mémoire :\n");
                printAdress4(maskDecInt4) ;
            } else { printf("Aucun masque n'est actuellement rentré en mémoire\n") ; }
            printf("Veuillez saisir un masque de sous réseau dans \nun format xxx.xxx.xxx.xxx\n");
            do{ 
                scanf("%s",masqueChar100); // On demande un masque que l'on stock dans masqueChar100
                n = checkAdress(masqueChar100,1) ; // On vérifie la validité du masque
                if ( n == 1 )
                {
                    printf("Masque valide\n");
                    saveAdress(masqueChar100,maskDecInt4,maskBinInt32,1); // Si l'ip est valide on sauvegarde l'ip donné dans le tableau ipDecInt4
                }
            } while ( n  != 1);  // tant que l'ip n'est pas valide : reprompt
            break;
            case 2 :      
            printf("********* Saisie du masque : Format CIDR *********\n");
            if ( checkIfAdressExist(maskDecInt4,1) == 1 )
            {
                printf("Masque actuellement en mémoire :\n");
                printAdress4(maskDecInt4) ;
            }
            else { printf("Aucun masque n'est actuellement rentré en mémoire\n") ; }
            printf("Veuillez entrer un masque en format CIDR\nC'est-à-dire un entier compris entre 0 et 32\n");
            scanf("%d",&maskcidr);
            if ( maskcidr <= 0 || maskcidr > 31 ) printf("La valeur cidr du masque doit être comprise entre 0 et 32\n");

            while ( maskcidr < 1 || maskcidr > 31 )
            {
                printf("Veuillez resaisir un masque en format cidr\n");
                scanf("%d",&maskcidr);
                if ( maskcidr <= 0 || maskcidr > 31 ) printf("La valeur cidr du masque doit être comprise entre 0 et 32\n");
            }
            if ( maskcidr == 31 ) printf("Note : Vous vous appretez à rentrer un masque ayant qu'un seul bit à 0\nLe réseau correspondant ne pourra comporter qu'une seul adresse ip\n");
            i = 0;
            while ( maskcidr != 0 )                       // maskcidr représente le nombre de 1 dans le masque
            {                                               //
               if (maskcidr >= 8 )                        // Tant que l'on a plus de 8 bit à 1 dans le masque
               {                                            //
                       maskDecInt4[i] = 255;         // => on remplis un octet de 1 soit 255 en décimal
                       for( k=i*8 ; k<i*8+8 ; k++ )
                       {
                            maskBinInt32[k] = 1 ;
                       }
                       maskcidr -= 8;                     // On retire les 8 bits à 1
                       i++;                                 // On avance d'un octet
               } else {                                     // Si il reste mois de 8 bits à 1
                       for ( j=0 ; j<maskcidr ; j++ )     // on rentre 2⁷ pour le premier bit puis 2⁶ puis 2⁵ etc...
                       {
                           maskDecInt4[i] += pow(2,(7-j));
                           maskBinInt32[i*8+j] = 1 ;
                       }
                       maskcidr = 0 ;
                   }
            } // Message indiquant la sauvegarde en mémoire du masque
            printf("Sauvegarde du masque %d.%d.%d.%d en mémoire\n", maskDecInt4[0],maskDecInt4[1],maskDecInt4[2],maskDecInt4[3] ); 
            break;
            default :
            break;
        }
        break;               
        case 3 :
            if( checkIfAdressExist(ipDecInt4,0) == 1 && checkIfAdressExist(maskDecInt4,1) == 1)
            {
               
                printf("------------------- Info réseau -------------------\n");
                // CALCUL DES ADRESSES
                calcNextNetwork(networkBinInt32,maskBinInt32,nextNetworkBinInt32); // PROCHAIN RESEAU EN BINAIRE
                convAdressBinToDec(nextNetworkBinInt32,nextNetworkDecInt4); // CONVERSION PROCHAIN RESEAU EN DECIMAL POINTE
                calcNextAdress(networkDecInt4,firstAdress4); // CALCUL DE LA PREMIERE ADRESSE IP DISPONIBLE
                calcPreviousAdress(nextNetworkDecInt4,broadcastAdress4); // CALCUL DE L ADRESSE DE BROADCAST
                calcPreviousAdress(broadcastAdress4,lastAdress4); // CALCUL DE LA DERNIERE ADRESSE IP DISPONIBLE

                // AFFICHAGE DES ADRESSES
                printf("******************* En binaire *******************\n");
                printf("Adresse ip : ");
                for ( j=0 ; j<32 ; j++ )
                {
                    printf("%d", ipBinInt32[j]);
                    if ( j == 7 || j == 15 || j == 23 ) { printf("."); }
                }
                printf("\nMasque     : ");
                for ( j=0 ; j<32 ; j++ )
                {
                    printf("%d", maskBinInt32[j]);
                    if ( j == 7 || j == 15 || j == 23 ) { printf("."); }
                }
                printf("\nReseau     : ");
                printAdress32(networkBinInt32);
                printf("\n******************* En décimal *******************\n");
                printf("Adresse ip     : ");
                printAdress4(ipDecInt4);
                printf("Masque         : ");
                printAdress4(maskDecInt4);
                printf("Adresse réseau : ");
                printAdress4(networkDecInt4);
                printf("\n1ère adresse ip disponible       : ");
                printAdress4(firstAdress4);
                printf("Nombres d'adresses ip disponible : %d\n",calcRange(maskBinInt32));             
                printf("Dernière adresse ip disponible   : ");
                printAdress4(lastAdress4);
                printf("Adresse de broadcast             : ");  
                printAdress4(broadcastAdress4);
                printf("Prochain réseau                  : ");   
                printAdress4(nextNetworkDecInt4);
                printf("----------------------------------------------------\n\n\n");
            } else {
                printf("Il faut une adresse ip et un masque valide pour afficher les infos du réseau\n");
                printf("Veuillez vérifier ces paramètres svp\n");
            }
        break;
        case 4 :
        choice = 0;
        while ( choice != 7 )
        {
        printf("******************* Conversion *******************\n");
        printf("1) Conversion d'un nombre décimal en binaire\n");
        printf("2) Conversion d'un nombre décimal en héxadécimal\n");
        printf("3) Conversion d'un nombre binaire en décimal\n");
        printf("4) Conversion d'un nombre binaire en héxadécimal\n");
        printf("5) Conversion d'un nombre héxadécimal en décimal\n");
        printf("6) Conversion d'un nombre héxadécimal en binaire\n");
        printf("7) Quitter Conversion\n");
        scanf("%d",&choice);
            switch (choice){
                case 1 :
                    printf("Quel est le nombre décimal à convertir en binaire?\n");
                    scanf("%d",&valToConv);
                    while ( valToConv > 255 || valToConv < 0 )
                    {
                        printf("Veuillez rentrer une valeur comprise entre 0 et 255\n");
                        scanf("%d",&valToConv);
                    }
                    printf("Votre valeur décimale : %d\n", valToConv);
                    printf("Conversion : " );
                    base10ToBinaire(valToConv,tabBinInt8);
                    for ( j=7 ; j>=0 ; j-- )
                    {
                        printf("%d",tabBinInt8[j]);
                    }
                    printf("\n");
                break;
                // REVOIR CES 3 POINTS
    /*            case 2 :
                    printf("Quel est le nombre décimal à convertir en héxadécimal?\n");
                    scanf("%d",&valToConv);
                    //printf("Votre valeur binaire : %d\n",binToDec32 );
                    printf("%d vaut %X en héxadécimal\n",valToConv,valToConv);
                break;
                case 3 :
                    printf("Quel est le nombre binaire à convertir en décimal?\n");
                    sscanf(binToDec32,"%d",&j);
                    temp3 = 0 ;
                    while ( binToDec32 >= 1 )
                    {
                        binToDec32 /= 10 ;
                        temp3++;
                    }
                    printf("Votre valeur en décimal : %d\n",binaireToBase10(binToDec32,temp3));
                break;
                case 4 :
                    printf("Quel est le nombre binaire à convertir en héxadécimal?\n");
                    scanf("%s",binToDec32);
                //    fgets(binToDec32,32,stdin);
                    temp3 = 0 ;
                    while ( binToDec32 >= 1 )
                    {
                        binToDec32 /= 10 ;
                        temp3++;
                    }
                    printf("Votre valeur en héxadécimal : %X\n",binaireToBase10(binToDec32,temp3));
                break; */
                case 5 :
                    printf("Quel est le nombre hexadécimal à convertir en décimal?\n");
                    scanf("%X",&valToConv);
                    printf("%X vaut %d en décimal\n",valToConv,valToConv );
                break;
                case 6 :
                    printf("Quel est le nombre hexadécimal à convertir en binaire?\n");
                    scanf("%X",&valToConv);
                    while ( valToConv > 255 || valToConv < 0 )
                    {
                        printf("Veuillez rentrer une valeur comprise entre 0 et 255\n");
                        scanf("%X",&valToConv);
                    }
                    base10ToBinaire(valToConv,tabBinInt8);
                    for ( j=0 ; j<8 ; j++ )
                    {
                        printf("%d",tabBinInt8[j]);
                    }
                    printf("\n");
                    break;
                case 7 :
                printf("Quitter Conversion\n");
                break;
                default :
                break;
            }
        }      
        break;
        case 5 :
        {
            struct SousReseau Adresse[100];
            for ( j = 0 ; j < 32 ; j++ )
            {
                masqueBin[j] = 1 ;
            }
            int nbAdressesTot,nbAdressesPossible ;
            nbAdressesTot = 0 ;
            if( checkIfAdressExist(ipDecInt4,0) == 1 && checkIfAdressExist(maskDecInt4,1) == 1)
            {
                for ( j = 0 ; j < 4 ; j++ )
                {
                    rangeResBroadAd4[j] = networkDecInt4[j] ;
                }

                printf("******************** SOUS-RESEAU *******************\n");
                printf("Combien de sous-réseaux souhaitez vous créer ?\n");
                scanf("%d",&nbSousRes);
                printf("Veuillez rentrer les sous réseau souhaité du PLUS GRAND au PLUS PETIT\n");
                for( j = 0 ; j < nbSousRes ; j++ )
                {
                    printf("Combien d'adresses doit contenir le sous-réseau n° %d ?\n",j+1 );
                    scanf("%d",&nbAdresses);
                    nbAdressSousRes[j] = nbAdresses ;
                    nbAdressesTot += nbAdresses ;
                }
                printf("sort\n");
                for( j = 31 ; j >= 0 ; j-- )
                {
                    if ( maskBinInt32[j] == 0 )
                    {
                        temp2++ ;
                    } else break ;
                }
                nbAdressesPossible = pow(2,temp2);
                if ( nbAdressesPossible < nbAdressesTot + 2 * nbSousRes )
                {
                    printf("Vous ne pouvez pas rentrer autant d'adresses étant donnée votre plage\n");
                    printf("Votre plage vous permet de dispser de %d \n",nbAdressesPossible );
                    printf("Rappel : chaque sous-réseau nécessite de deux adresses supplémentaire (réseau et broadcast)\n");
                } else
                {  
                    masquecidr = 32;
                    for ( j = 0 ; j < nbSousRes ; j++ )
                    {
                        while ( nbAdressSousRes[j] > 1 )                       
                        {
                                nbAdressSousRes[j] /= 2 ;
                                masquecidr-- ; 
                        }
                        Adresse[j].masquecidr = masquecidr ;
                        for ( k = 32 ; k >= masquecidr ; k-- )
                        {
                            masqueBin[k] = 0;
                            printf("%d",masqueBin[k] );
                        }

                        //Calcul de la plage réservée
                        printf("7\n");
                       
                        calcNextAdress(rangeResBroadAd,rangeResNetworkAd);
                        calcNextNetwork(rangeResNetworkAd,masqueBin,rangeResBroadAd);

                        printAdress4(rangeResNetworkAd);
                        printAdress4(rangeResBroadAd);


                    }
                    printf("9\n");

                }

            } else { printf("Il faut avoir en mémoire une adresse ip et un masque valide pour avoir cette option\nVeuillez vérifier ces paramètrs svp\n"); }
        }
        break;
        case 6 :
            printf("********************* SORTIE *********************\n");
            printf("Voulez vous vraiment quitter mon programme?? ;(\n");        
            printf("( 6 ) pour confirmer ;(\n");
            printf("**************************************************\n");
            scanf("%d",&i);
            if(i==6)
            {
                sayGoodBye();
            } else break;
        return;
    
        default :
        break;
        }
    }
}