void ColDetect::addPolygon(std::vector<Triangle3D> triangles, VCollide& vc)
{
	int id;
	double v1[3], v2[3], v3[3];
	vc.NewObject(&id);
	for (int j = 0; j < triangles.size(); j++) {
		auto tri = triangles[j];
		auto p1 = tri.getPoint1();
		v1[0] = p1.getX();
		v1[1] = p1.getY();
		v1[2] = p1.getZ();

		auto p2 = tri.getPoint2();
		v2[0] = p2.getX();
		v2[1] = p2.getY();
		v2[2] = p2.getZ();

		auto p3 = tri.getPoint3();
		v3[0] = p3.getX();
		v3[1] = p3.getY();
		v3[2] = p3.getZ();
		vc.AddTri(v1, v2, v3, j);
	}
	vc.EndObject();
}
Beispiel #2
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;
}
void addTris(double *tris, int n, VCollide &vc) {
    int id;
    double v1[3], v2[3], v3[3];
    vc.NewObject(&id);
    for (int j(0); j < n; j++) {
        v1[0] = tris[j + 0 * n];
        v1[1] = tris[j + 1 * n];
        v1[2] = tris[j + 2 * n];

        v2[0] = tris[j + 3 * n];
        v2[1] = tris[j + 4 * n];
        v2[2] = tris[j + 5 * n];

        v3[0] = tris[j + 6 * n];
        v3[1] = tris[j + 7 * n];
        v3[2] = tris[j + 8 * n];    
        vc.AddTri(v1, v2, v3);
    }
    vc.EndObject();
}
Beispiel #4
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;
}
Beispiel #5
0
int main(int argc, char *argv[])
{

  if (argc != 3)
    {
		std::cerr<<argv[0]<<": USAGE: "<<argv[0]<<" <input-file> <transformation-file>\n";
      exit(1);
    }
  
  int num_tri;
  VCollide vc;
  int id[NO_OF_OBJECTS];
  
  int i;
  for (i=0; i<NO_OF_OBJECTS; i++)  //add the objects to the library.
    {
      std::cout<<"Reading object "<<i<<"\n";
      vc.NewObject(&(id[i]));
      std::cout<<"Adding triangles\n";
      FILE *fp = fopen(argv[1], "r");
      fscanf(fp, "%d", &num_tri);
      
      for (int j=1; j<=num_tri; j++)
	{
	  double v1[3], v2[3], v3[3];
	  fscanf(fp, "%lf %lf %lf", &(v1[0]), &(v1[1]), &(v1[2]));
	  fscanf(fp, "%lf %lf %lf", &(v2[0]), &(v2[1]), &(v2[2]));
	  fscanf(fp, "%lf %lf %lf", &(v3[0]), &(v3[1]), &(v3[2]));
	  
	  vc.AddTri(v1, v2, v3, j);  // Each triangle has an id
	}
      
      fclose(fp);
      
      std::cout<<"Calling finish_object\n";
      vc.EndObject();
      
      
      std::cout<<"Inserted object "<<i<<"\n";
    }
  
  
  FILE *fp = fopen(argv[2], "r");
  
  for (i=1; i<=SIMULATION_STEPS; i++)  //perform the simulation.
    {
      std::cout<<"Simulation step : "<<i<<"\n";
      int j;
      for (j=0; j<NO_OF_OBJECTS; j++)
	{
	  double trans[4][4];
	  
	  //read in the transformation matrix.
	  fscanf(fp, "%lf", &(trans[0][0]));
	  fscanf(fp, "%lf", &(trans[0][1]));
	  fscanf(fp, "%lf", &(trans[0][2]));
	  fscanf(fp, "%lf", &(trans[0][3]));
	  
	  fscanf(fp, "%lf", &(trans[1][0]));
	  fscanf(fp, "%lf", &(trans[1][1]));
	  fscanf(fp, "%lf", &(trans[1][2]));
	  fscanf(fp, "%lf", &(trans[1][3]));
	  
	  fscanf(fp, "%lf", &(trans[2][0]));
	  fscanf(fp, "%lf", &(trans[2][1]));
	  fscanf(fp, "%lf", &(trans[2][2]));
	  fscanf(fp, "%lf", &(trans[2][3]));
	  
	  fscanf(fp, "%lf", &(trans[3][0]));
	  fscanf(fp, "%lf", &(trans[3][1]));
	  fscanf(fp, "%lf", &(trans[3][2]));
	  fscanf(fp, "%lf", &(trans[3][3]));
	  
	  //update the object's transformation.
	  vc.UpdateTrans(id[j], trans);
	}


      VCReport report;
            
      vc.Collide( &report, VC_ALL_CONTACTS);  //perform collision test.
                                              //default is VC_FIRST_CONTACT
      
      
      for (j = 0; j < report.numObjPairs(); j++)
      {
	std::cout << "Detected collision between objects "
             << report.obj1ID(j) << " and " << report.obj2ID(j) << "\n";

	std::cout << "\tNumber of contacts = " << report.numTriPairs(j) << "\n";
        std::cout << "\tColliding triangle-pairs: ";
	
        int k;
        for ( k = 0; k < report.numTriPairs(j); k++ )
          std::cout << "[" << report.tri1ID(j, k) << "," << report.tri2ID(j, k) << "] ";

        std::cout << "\n";
      }

    }

  return 0;
}
Beispiel #6
0
//removes bunnies which have crossed/collided with the y=YMAX wall.
//for each bunny removed, one is added at the y=YMIN wall.
void SinkAndSource(void)
{
  polyObject *current;
  
  while (list != NULL)
    {
      if (list->position[1] >= WallDist)
	{
	  current = list;
	  list = list->next;
	  vc.DeleteObject(current->id);
	  std::cout<<"deleting id = "<<current->id<<"\n";
	  delete current;
	  
          polyObject *t = new polyObject(polytope);
          t->position[1] = -WallDist + 0.5;
	  vc.NewObject(&(t->id));

	  Polytope *p = t->p;
	  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();

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

	  t->next = list;
	  list = t;
	  num_of_polytopes++;
	}
      else
	{
	  break;
	}
    }
  
  current = list;
  
  if (current != NULL)
    {
      while (current->next != NULL)
	{
	  if (current->next->position[1] >= WallDist)
	    {
	      polyObject *t = current->next;
	      current->next = current->next->next;
	      vc.DeleteObject(t->id);
	      std::cout<<"deleting id = "<<t->id<<"\n";
	      delete t;
	      
              t = new polyObject(polytope);
	      t->position[1] = -WallDist + 0.5;
	      
	      vc.NewObject(&(t->id));
	      
	      Polytope *p = t->p;
	      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();
	      
	      std::cout<<"created polytope with id = "<<t->id<<"\n";
	      
	      t->next = list;
	      list = t;
	      num_of_polytopes++;
	      
	    }
	  else
	    {
	      current = current->next;
	    }
	}
    }
  
}