Exemple #1
0
int main(int argc, char *argv[])
{
  if (argc != 2)
    {
      fprintf(stderr, "USAGE: %s <simulation-file>\n", argv[0]);
      exit(1);
    }

  if ( (fp = fopen(argv[1], "r")) == NULL )
    {
      fprintf(stderr, "%s: Error opening file %s\n", argv[0], argv[1]);
      exit(1);
    }
  
  //read in the geometry from input file.
  fscanf(fp, "%d", &num_of_polytopes);

  polytope = new Polytope*[num_of_polytopes];

  char name[10], filename[20];
  int color_index;
  
  int i;
  for (i=0; i<num_of_polytopes; i++)
    {
      fscanf(fp, "%s", name);
      fscanf(fp, "%s", filename);
      fscanf(fp, "%d", &color_index);

      cout<<"Reading in polytope from file "<<filename<<"\n";

      polytope[i] = new Polytope(filename);
    }


  //add the object to the library.
  for (i=0; i<num_of_polytopes; i++)
    {
      Polytope *p = polytope[i];

      vc.NewObject(&(p->id));
      
      int j;
      for (j=0; j<p->num_tris; j++)
	vc.AddTri(p->vertex[(p->tris[j])[0]].v, p->vertex[(p->tris[j])[1]].v, p->vertex[(p->tris[j])[2]].v );
      
      vc.EndObject();
    }
  
  //perform the simulation.
  simulation_loop(&argc, argv);

  return 0;
}
Exemple #2
0
void cart_pole_loop()
{

  int i;
  static int m = 0;

  static int    cycle = 0;            // counter
  //  static int    writeFrameCnt = 1200; // # of frames to write
  static int    writeFrameCnt = 500; // # of frames to write
  static int    writtenFrameCnt = 0;  // # of frames written so far
  //  static int    writePer = 110;       // period of writing
  static int    writePer = 2;       // period of writing //25Hz
  //  extern int    writeImg;

  glutPostRedisplay();

  simulation_loop();//------------------------------------------------------------- CALL CONTROLLER

  //#if 0
		/*************************************/
		/*  Wait for visualization   */       
		/*************************************/ 
		req.tv_sec = 0;
		req.tv_nsec = 1000;
                memcpy(&rem, &req,sizeof(req));
		memset(&req,0,sizeof(req));
		nanosleep(&req,&rem);
		//#endif


  if (writeImg){
    if (cycle % writePer == 0){
      WindowDump(0,0,Width,Height);
      writtenFrameCnt++;
      if (writtenFrameCnt == writeFrameCnt){
	writeImg = 0;
	printf("Written %d frames.\n", writtenFrameCnt);
      }
    }
    cycle ++;
  }

}
Exemple #3
0
int main(int argc, char *argv[])
{
    
  if (argc != 3)
    {
      fprintf(stderr, "USAGE: %s <bunny-file> <number-of-instances>\n", argv[0]);
      exit(1);
    }

  srand(32487723);
  
  polytope = new Polytope(argv[1]);

  int no_of_instances = atoi(argv[2]);
  
  WallDist = (int) pow(no_of_instances*100.0, 0.33) * 100; //maintains constant density.
  for (int i=0; i<no_of_instances; i++)
    {
      polyObject *t = new polyObject(polytope);
      
      vc.NewObject(&(t->id));

      Polytope *p = t->p;
      for (int j=0; j<p->num_tris; j++)
	vc.AddTri(p->vertex[(p->tris[j])[0]].v, p->vertex[(p->tris[j])[1]].v, p->vertex[(p->tris[j])[2]].v );

      vc.EndObject();

      std::cout<<"created polytope with id = "<<t->id<<"\n";

      t->next = list;
      list = t;
      num_of_polytopes++;
    }
  

  simulation_loop(&argc, argv);

  return 0;
}