⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maze3d.c

📁 Many C samples. It is a good sample for students to learn C language.
💻 C
📖 第 1 页 / 共 5 页
字号:
                                      printf("     Fatal error:  %s\n",
                                       grapherrormsg(ErrorCode));
                                      fatal_error=TRUE;
                                    }
                                  for (x=max_x; x >= 0; x--)
                                    free((void *) user_page[x]);
                                }
                              else
                                while (x > 0)
                                  free((void *) user_page[--x]);
                              free((void *) user_page);
                            }
                          for (x=max_x; x >= 0; x--)
                            free((void *) computer_page[x]);
                        }
                      else
                        while (x > 0)
                          free((void *) computer_page[--x]);
                      free((void *) computer_page);
                    }
                  free((void *) stack);
                }
            }
        }
      while ((! fatal_error) && (user_still_interested));
      if (! fatal_error)
        put_defaults(argv[0],default_num_columns,default_tilt,
         &default_seed[0]);
      return;
    }

static void get_defaults(
  char   *argv,
  int    *default_num_columns,
  double *default_tilt,
  char   *default_seed)
    {
      register int  arg_index;
      static   char *arg_ptr;
               FILE *defaults;
      static   char file_name [256];
      static   int  last_period_index;
      static   char line [256];
      static   char *line_ptr;
      static   int  num_assigned;
      static   int  seed_length;
      static   char *seed_ptr;

      arg_index=0;
      arg_ptr=argv;
      last_period_index=-1;
      while ((*arg_ptr) && (arg_index < 252))
        {
          if (*arg_ptr == '.')
            last_period_index=arg_index;
          file_name[arg_index++]=*(arg_ptr++);
        }
      if ((*arg_ptr) || (last_period_index < 0))
        {
          *default_num_columns=30;
          *default_tilt=(double) 30.0;
          default_seed[0]='1';
          default_seed[1]='\0';
        }
      else
        {
          file_name[++last_period_index]='I';
          file_name[++last_period_index]='N';
          file_name[++last_period_index]='I';
          file_name[++last_period_index]='\0';
          if ((defaults=fopen(&file_name[0],"r")) == NULL)
            {
              *default_num_columns=30;
              *default_tilt=(double) 30.0;
              default_seed[0]='1';
              default_seed[1]='\0';
            }
          else
            {
              fgets(&line[0],256,defaults);
              line_ptr=&line[0];
              while ((*line_ptr == ' ') || (*line_ptr == (char) 9))
                line_ptr++;
              if ((*line_ptr == '\n') || (*line_ptr == '\0'))
                *default_num_columns=30;
              else
                {
                  num_assigned=sscanf(line_ptr,"%d",default_num_columns);
                  if ((num_assigned == 0) || (num_assigned == EOF))
                    *default_num_columns=30;
                }
              fgets(&line[0],256,defaults);
              line_ptr=&line[0];
              while ((*line_ptr == ' ') || (*line_ptr == (char) 9))
                line_ptr++;
              if ((*line_ptr == '\n') || (*line_ptr == '\0'))
                *default_tilt=(double) 30.0;
              else
                {
                  num_assigned=sscanf(line_ptr,"%lf",default_tilt);
                  if ((num_assigned == 0) || (num_assigned == EOF))
                    *default_tilt=(double) 30.0;
                }
              fgets(&line[0],256,defaults);
              line_ptr=&line[0];
              while ((*line_ptr == ' ') || (*line_ptr == (char) 9))
                line_ptr++;
              seed_ptr=default_seed;
              if ((*line_ptr == '\n') || (*line_ptr == '\0'))
                *(seed_ptr++)='1';
              else
                {
                  seed_length=0;
                  while ((seed_length < 8)
                  &&     (*line_ptr)
                  &&     (*line_ptr != '\n')) 
                    {
                      *(seed_ptr++)=*(line_ptr++);
                      seed_length++;
                    }
                }
              *seed_ptr='\0';
              fclose(defaults);
            }
        }
      return;
    }

void interrupt new_critical_error_handler()
    {
      file_opened=FALSE;
      return;
    }

static void put_defaults(
  char   *argv,
  int    num_columns,
  double tilt,
  char   *seed)
    {
      static int  arg_index;
      static char *arg_ptr;
             FILE *defaults;
      static char file_name [256];
      static int  last_period_index;

      arg_index=0;
      arg_ptr=argv;
      last_period_index=-1;
      while ((*arg_ptr) && (arg_index < 252))
        {
          if (*arg_ptr == '.')
            last_period_index=arg_index;
          file_name[arg_index++]=*(arg_ptr++);
        }
      if ((*arg_ptr == '\0') && (last_period_index >= 0))
        {
          file_name[++last_period_index]='I';
          file_name[++last_period_index]='N';
          file_name[++last_period_index]='I';
          file_name[++last_period_index]='\0';
          old_critical_error_handler=getvect(0x24);
          setvect(0x24,new_critical_error_handler);
          file_opened=TRUE;
          if ((defaults=fopen(&file_name[0],"w")) != NULL)
            {
              setvect(0x24,old_critical_error_handler);
              if (file_opened)
                {
                  fprintf(defaults,"%d\n%lf\n%s\n",num_columns,tilt,seed);
                  fclose(defaults);
                }
            }
          else 
            setvect(0x24,old_critical_error_handler);           
        }
      return;
    }

static void get_corners(
  double tilt)
    {
      static   double cos_tilt;
      static   int    i;
      register int    j;
      register int    k;
      static   double pixels_per_unit;
      static   double radians;
      static   double radians_per_degree;
      static   double sin_tilt;
      static   double x;
      static   double x_base [2];
      static   double x_eye;
      static   double x_prime;
      static   double x_prime_max;
      static   double y;
      static   double y_base [2];
      static   double y_center;
      static   double y_offset;
      static   double y_out_max;
      static   double y_prime;
      static   double y_prime_max;
      static   double y_prime_min;
      static   double z;
      static   double z_base [2];
      static   double z_center;
      static   double z_offset;
      static   double z_out_max;
      static   double z_prime;
      static   double z_prime_max;
      static   double z_prime_min;

      x_base[0]=(double) X_PIXEL_MIN;
      x_base[1]=(double) X_PIXEL_MAX;
      y_base[0]=(double) Y_PIXEL_MIN;
      y_base[1]=(double) Y_PIXEL_MAX;
      z_base[0]=(double) 0.0;
      z_base[1]=(double) ROOM_HEIGHT_IN_Y_PIXELS;
      radians_per_degree=atan(1.0)/45.0;
      radians=tilt*radians_per_degree;
      cos_tilt=cos(radians);
      sin_tilt=sin(radians);
      x=x_base[0];
      y=y_base[0];
      z=z_base[0];
      y_prime_min=x;
      x_prime_max=y*cos_tilt+z*sin_tilt;
      z_prime_min=-y*sin_tilt+z*cos_tilt;
      y_prime_max=y_prime_min;
      z_prime_max=z_prime_min;
      for (i=0; i <= 1; i++)
        for (j=0; j <= 1; j++)
          for (k=0; k <= 1; k++)
            {
              x=x_base[k];
              y=y_base[j];
              z=z_base[i];
              y_prime=x;
              if (y_prime > y_prime_max)
                y_prime_max=y_prime;
              else
                {
                  if (y_prime < y_prime_min)
                    y_prime_min=y_prime;
                }
              x_prime=y*cos_tilt+z*sin_tilt;
              if (x_prime > x_prime_max)
                x_prime_max=x_prime;
              z_prime=-y*sin_tilt+z*cos_tilt;
              if (z_prime > z_prime_max)
                z_prime_max=z_prime;
              else
                {
                  if (z_prime < z_prime_min)
                    z_prime_min=z_prime;
                }
            }
      if ((y_prime_max-y_prime_min) > (z_prime_max-z_prime_min))
        x_eye=1.1*(y_prime_max-y_prime_min)+x_prime_max;
      else
        x_eye=1.1*(z_prime_max-z_prime_min)+x_prime_max;
      /* 1.1 for slight "fish-eye" */
      y_center=(y_prime_max+y_prime_min)/2.0;
      z_center=(z_prime_max+z_prime_min)/2.0;
      y_out_max=(double) (X_PIXEL_MAX-X_PIXEL_MIN);
      z_out_max=(double) (Y_PIXEL_MAX-Y_PIXEL_MIN);
      if (z_out_max*(y_prime_max-y_prime_min)
       > y_out_max*(z_prime_max-z_prime_min))
        {
          pixels_per_unit=y_out_max/(y_prime_max-y_prime_min);
          y_offset=0.0;
          z_offset=-(z_out_max-pixels_per_unit*(z_prime_max-z_prime_min))/2.0;
        }
      else
        if (z_out_max*(y_prime_max-y_prime_min)
         < y_out_max*(z_prime_max-z_prime_min))
          {
            pixels_per_unit=z_out_max/(z_prime_max-z_prime_min);
            y_offset=(y_out_max
             -pixels_per_unit*(y_prime_max-y_prime_min))/2.0;
            z_offset=0.0;
          }
        else
          {
            pixels_per_unit=1.0;
            y_offset=y_out_max/2.0;
            z_offset=-z_out_max/2.0;
          }
      for (i=0; i <= 1; i++)
        for (j=0; j <= 1; j++)
          for (k=0; k <= 1; k++)
            {
              x=x_base[k];
              y=y_base[j];
              z=z_base[i];
              y_prime=x;
              x_prime=y*cos_tilt+z*sin_tilt;
              z_prime=-y*sin_tilt+z*cos_tilt;
              x=x_prime;
              y=y_prime;
              z=z_prime;
              y_prime=y_center+(y-y_center)*(x_eye-x_prime_max)/(x_eye-x);
              z_prime=z_center+(z-z_center)*(x_eye-x_prime_max)/(x_eye-x);
              y=y_prime;
              z=z_prime;
              x_corner[k][j][i]=X_PIXEL_MIN
               +(int) (y_offset+pixels_per_unit*(y-y_prime_min));
              y_corner[k][j][i]=Y_PIXEL_MIN
               +(int) (z_offset+z_out_max-pixels_per_unit*(z-z_prime_min));
            }
      return;
    }

static int substitution_high [100] =
             { 4,1,2,8,8,9,9,6,5,7,2,1,2,9,8,8,6,3,5,1,9,5,4,4,9,8,6,0,8,0,
               6,0,2,4,1,9,2,0,7,4,7,3,0,0,2,6,8,9,4,0,8,3,2,3,2,5,2,4,6,9,
               7,9,1,3,5,7,1,1,4,5,8,1,6,0,5,7,8,2,3,3,7,3,5,1,7,5,4,0,3,6,
               3,7,7,1,9,4,0,5,6,6
             };
static int substitution_low [100] =
             { 1,2,2,1,5,5,4,6,4,6,4,4,5,6,6,3,0,9,6,5,7,2,0,9,3,4,2,3,9,1,
               9,9,9,3,8,9,3,4,1,5,0,5,2,7,0,8,8,0,4,5,0,3,6,8,1,7,8,8,7,1,
               3,2,7,7,1,8,0,3,7,5,2,6,4,0,9,9,7,7,4,6,2,0,0,1,7,3,6,6,1,1,
               2,4,5,9,8,2,8,8,3,5
             };
static void hash(
  int *counter_0,
  int *counter_1,
  int *counter_2,
  int *counter_3,
  int *counter_4,
  int *counter_5,
  int *counter_6,
  int *counter_7)
    {
      register int iteration;
      static   int seed_0;
      static   int seed_1;
      static   int seed_2;
      static   int seed_3;
      static   int seed_4;
      static   int seed_5;
      static   int seed_6;
      static   int seed_7;
      register int substitution_index;
      static   int tem_0;
      static   int tem_1;
      static   int tem_2;

      seed_0=(*counter_0);
      seed_1=(*counter_1);
      seed_2=(*counter_2);
      seed_3=(*counter_3);
      seed_4=(*counter_4);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -