Exemple #1
0
  GameObjectTest(Context & context){
    Polygon pgon;
    pgon.Load(context.BoxShape,0);

    Texgon tgon;
    tgon.Load(context.StarColors,0);
    Tetragon tetra(TRSMatrix(vec(0.0f,0.0f,0.0f),
			     vec(0.0f,0.0f,0.0f),
			     vec(1.f,1.0f,1.0f)),
		   pgon,tgon);
    Tetragon * last = &tetra;
    Tetra = tetra;
    aabb = AABBMass(vec(0.0,0.0,0.0),vec(2.0,2.0,2.0),3.0);
  }
Exemple #2
0
  player(Context & context){
    Polygon pgon;
    pgon.Load(context.BoxShape,0);
    
    Texgon tgon;
    tgon.Load(context.StarColors,0);
    Tetragon tetra(TRSMatrix(vec(0.0f,0.0f,0.0f),
			     vec(0.0f,0.0f,0.0f),
			     vec(1.f,1.0f,1.0f)),
		   pgon,tgon);
    Tetragon * last = &tetra;
    Tetra = tetra;
    aabb.size = vec(2.0,2.0,2.0);
    aabb.mass = 100;
  }
Exemple #3
0
void divide_tetra( const vec3& a, const vec3& b, const vec3& c, const vec3& d, int count )
{
    if ( count > 0 ) {
        vec3 v0 = ( a + b ) / 2.0;
        vec3 v1 = ( a + c ) / 2.0;
        vec3 v2 = ( a + d ) / 2.0;
        vec3 v3 = ( b + c ) / 2.0;
        vec3 v4 = ( c + d ) / 2.0;
        vec3 v5 = ( b + d ) / 2.0;
        divide_tetra( a, v0, v1, v2, count - 1 );
        divide_tetra( v0, b, v3, v5, count - 1 );
        divide_tetra( v1, v3, c, v4, count - 1 );
        divide_tetra( v2, v5, v4, d, count - 1 );
    } else {
        tetra( a, b, c, d );    // draw tetrahedron at end of recursion
    }
}
Exemple #4
0
NpTetrahedron RandomTetrahedron(const NpVector& min, const NpVector& max)
{
    NpTetrahedron tetra(RandomVector(min, max),
                        RandomVector(min, max),
                        RandomVector(min, max),
                        RandomVector(min, max));

    double vol = (tetra.v[0]-tetra.v[1]) * 
                 ((tetra.v[0]-tetra.v[2]) ^ (tetra.v[0]-tetra.v[3]));
    if (vol < 0)  {
        NpVector tmp(tetra.v[2]);
        tetra.v[2] = tetra.v[3];
        tetra.v[3] = tmp;
    }

    return tetra;
}
Exemple #5
0
void divide_tetra(const point3& a, const point3& b, const point3& c, const point3& d, int m){
    if(m > 0){
        glm::vec3 mid[6];
        
        mid[0] = (a + b) / 2.0f;
        mid[1] = (a + c) / 2.0f;
        mid[2] = (a + d) / 2.0f;
        mid[3] = (b + c) / 2.0f;
        mid[4] = (c + d) / 2.0f;
        mid[5] = (b + d) / 2.0f;
        
        divide_tetra(a, mid[0], mid[1], mid[2], m-1);
        divide_tetra(mid[0], b, mid[3], mid[5], m-1);
        divide_tetra(mid[1], mid[3], c, mid[4], m-1);
        divide_tetra(mid[2], mid[5], mid[4], d, m-1);
    }
    
    else tetra(a, b, c, d);
}
Exemple #6
0
void divide_tetra(GLfloat *a,GLfloat *b,GLfloat *c,GLfloat *d,int m)
{
  GLfloat mid[6][3];
  int j;
  if(m>0)
  {
    for(j=0;j<3;j++) mid[0][j]=(a[j]+b[j])/2;
    for(j=0;j<3;j++) mid[1][j]=(a[j]+c[j])/2;
    for(j=0;j<3;j++) mid[2][j]=(a[j]+d[j])/2;
    for(j=0;j<3;j++) mid[3][j]=(b[j]+d[j])/2;
    for(j=0;j<3;j++) mid[4][j]=(d[j]+c[j])/2;
    for(j=0;j<3;j++) mid[5][j]=(b[j]+c[j])/2;

    divide_tetra(a,mid[0],mid[1],mid[2],m-1);
    divide_tetra(mid[0],b,mid[3],mid[5],m-1);
    divide_tetra(mid[1],mid[4],c,mid[5],m-1);
    divide_tetra(mid[2],mid[3],mid[4],d,m-1);
  }
  else
    tetra(a,b,c,d);
}
Exemple #7
0
// setter
int define::update(string& data) {
	const char* header = getHeader().c_str();
	
	// get the text
	vector<string> lines = BZWParser::getSectionsByHeader(header, data.c_str(), "enddef");
	
	if(lines[0] == BZW_NOT_FOUND)
		return 0;
	
	if(lines.size() > 1) {
		printf("define::update(): Error! Defined \"define\" %d times!\n", (int)lines.size());
		return 0;	
	}
	
	// get the name
	vector<string> names = BZWParser::getValuesByKey("define", header, lines[0].c_str());
	if(!hasOnlyOne(names, header))
		return 0;
			
	// get the data
	string::size_type sectionStart = lines[0].find("\n") + 1;
	string::size_type sectionLength = lines[0].find( "enddef", sectionStart ) - sectionStart;
	
	lines[0] = lines[0].substr( sectionStart, sectionLength );
	
	const char* defineData = lines[0].c_str();
	
	// get the chunks
	vector<string> chunks = BZWParser::getSections( defineData );
	
	// get all the supported objects from the lines, but don't commit them yet
	
	// arc
	vector<string> arcs = BZWParser::findSections("arc", chunks);
	vector<arc> arcData;
	if(arcs[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = arcs.begin(); i != arcs.end(); i++) {
			arc tmp = arc();
			if(!tmp.update(*i))
				return 0;
			arcData.push_back( tmp );	
		}	
	}
	
	// base
	vector<string> bases = BZWParser::findSections("base", chunks);
	vector<base> baseData;
	if(bases[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = bases.begin(); i != bases.end(); i++) {
			base tmp = base();
			if(!tmp.update(*i))
				return 0;
			baseData.push_back( tmp );	
		}	
	}
	
	// box
	vector<string> boxes = BZWParser::findSections("box", chunks);
	vector<box> boxData;
	if(boxes[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = boxes.begin(); i != boxes.end(); i++) {
			box tmp = box();
			if(!tmp.update(*i))
				return 0;
			boxData.push_back( tmp );	
		}	
	}
	
	// cone
	vector<string> cones = BZWParser::findSections("cone", chunks);
	vector<cone> coneData;
	if(cones[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = cones.begin(); i != cones.end(); i++) {
			cone tmp = cone();
			if(!tmp.update(*i))
				return 0;
			coneData.push_back( tmp );	
		}	
	}
	
	// group
	vector<string> groups = BZWParser::findSections("group", chunks);
	vector<group> groupData;
	if(groups[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = groups.begin(); i != groups.end(); i++) {
			group tmp = group();
			if(!tmp.update(*i))
				return 0;
			groupData.push_back( tmp );	
		}	
	}
	
	// mesh
	vector<string> meshes = BZWParser::findSections("mesh", chunks);
	vector<mesh> meshData;
	if(meshes[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = meshes.begin(); i != meshes.end(); i++) {
			mesh tmp = mesh();
			if(!tmp.update(*i))
				return 0;
			meshData.push_back( tmp );	
		}	
	}
	
	// meshbox
	vector<string> meshboxes = BZWParser::findSections("meshbox", chunks);
	vector<meshbox> meshboxData;
	if(meshboxes[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = meshboxes.begin(); i != meshboxes.end(); i++) {
			meshbox tmp = meshbox();
			if(!tmp.update(*i))
				return 0;
			meshboxData.push_back( tmp );	
		}	
	}
	
	// meshpyr
	vector<string> meshpyrs = BZWParser::findSections("meshpyr", chunks);
	vector<meshpyr> meshpyrData;
	if(meshpyrs[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = meshpyrs.begin(); i != meshpyrs.end(); i++) {
			meshpyr tmp = meshpyr();
			if(!tmp.update(*i))
				return 0;
			meshpyrData.push_back( tmp );	
		}	
	}
	
	// pyramid
	vector<string> pyramids = BZWParser::findSections("pyramid", chunks);
	vector<pyramid> pyramidData;
	if(pyramids[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = pyramids.begin(); i != pyramids.end(); i++) {
			pyramid tmp = pyramid();
			if(!tmp.update(*i))
				return 0;
			pyramidData.push_back( tmp );	
		}	
	}
	
	// sphere
	vector<string> spheres = BZWParser::findSections("sphere", chunks);
	vector<sphere> sphereData;
	if(spheres[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = spheres.begin(); i != spheres.end(); i++) {
			sphere tmp = sphere();
			if(!tmp.update(*i))
				return 0;
			sphereData.push_back( tmp );	
		}	
	}
	
	// teleporter
	vector<string> teleporters = BZWParser::findSections("teleporter", chunks);
	vector<teleporter> teleporterData;
	if(teleporters[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = teleporters.begin(); i != teleporters.end(); i++) {
			teleporter tmp = teleporter();
			if(!tmp.update(*i))
				return 0;
			teleporterData.push_back( tmp );	
		}	
	}
	
	// tetra
	vector<string> tetras = BZWParser::findSections("tetra", chunks);
	vector<tetra> tetraData;
	if(tetras[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = tetras.begin(); i != tetras.end(); i++) {
			tetra tmp = tetra();
			if(!tmp.update(*i))
				return 0;
			tetraData.push_back( tmp );	
		}	
	}
	
	
	// base-class update (must be done BEFORE commiting new objects)
	if(!DataEntry::update(data)) {
		return 0;
	}
	
	// commit name
	name = names[0];
	
	// free previous objects	
	objects.clear();
	
	// commit arcs
	if(arcData.size() > 0) {
		for(vector<arc>::iterator i = arcData.begin(); i != arcData.end(); i++) {
			objects.push_back( new arc(*i) );	
		}	
	}
	
	// commit bases
	if(baseData.size() > 0) {
		for(vector<base>::iterator i = baseData.begin(); i != baseData.end(); i++) {
			objects.push_back( new base(*i) );	
		}	
	}
	
	// commit boxes
	if(boxData.size() > 0) {
		for(vector<box>::iterator i = boxData.begin(); i != boxData.end(); i++) {
			objects.push_back( new box(*i) );	
		}	
	}
	
	// commit cones
	if(coneData.size() > 0) {
		for(vector<cone>::iterator i = coneData.begin(); i != coneData.end(); i++) {
			objects.push_back( new cone(*i) );	
		}	
	}
	
	// commit groups
	if(groupData.size() > 0) {
		for(vector<group>::iterator i = groupData.begin(); i != groupData.end(); i++) {
			objects.push_back( new group(*i) );	
		}	
	}
	
	// commit meshes
	if(meshData.size() > 0) {
		for(vector<mesh>::iterator i = meshData.begin(); i != meshData.end(); i++) {
			objects.push_back( new mesh(*i) );	
		}	
	}
	
	// commit meshboxes
	if(meshboxData.size() > 0) {
		for(vector<meshbox>::iterator i = meshboxData.begin(); i != meshboxData.end(); i++) {
			objects.push_back( new meshbox(*i) );	
		}	
	}
	
	// commit meshpyrs
	if(meshpyrData.size() > 0) {
		for(vector<meshpyr>::iterator i = meshpyrData.begin(); i != meshpyrData.end(); i++) {
			objects.push_back( new meshpyr(*i) );	
		}	
	}
	
	// commit pyramids
	if(pyramidData.size() > 0) {
		for(vector<pyramid>::iterator i = pyramidData.begin(); i != pyramidData.end(); i++) {
			objects.push_back( new pyramid(*i) );	
		}	
	}
	
	// commit spheres
	if(sphereData.size() > 0) {
		for(vector<sphere>::iterator i = sphereData.begin(); i != sphereData.end(); i++) {
			objects.push_back( new sphere(*i) );	
		}	
	}
	
	// commit teleporters
	if(teleporterData.size() > 0) {
		for(vector<teleporter>::iterator i = teleporterData.begin(); i != teleporterData.end(); i++) {
			objects.push_back( new teleporter(*i) );	
		}
	}
	
	// commit tetras
	if(tetraData.size() > 0) {
		for(vector<tetra>::iterator i = tetraData.begin(); i != tetraData.end(); i++) {
			objects.push_back( new tetra(*i) );	
		}	
	}
	
	return 1;
}
main(int argc, char *argv[])
{
  int i,j;
  char *s;
  char *progname;
  int solid = TETRA;

  progname = argv[0];

  while (--argc > 0 && (*++argv)[0]=='-') {
    for (s = argv[0]+1; *s; s++)
      switch (*s) {
        case 's':
          xscale = atof (*++argv);
          yscale = atof (*++argv);
          zscale = atof (*++argv);
          argc -= 3;
          break;
        case 't':
          solid = TETRA;
          break;
        case 'o':
          solid = OCTA;
          break;
        case 'c':
          solid = CUBE;
          break;
        case 'i':
          solid = ICOSA;
          break;
        case 'd':
          solid = DODECA;
          break;
        default:
          usage (progname);
          exit (-1);
          break;
      }
  }

  switch (solid) {
    case TETRA:
      tetra();
      break;
    case OCTA:
      octa();
      break;
    case CUBE:
      cube();
      break;
    case ICOSA:
      icosahedron();
      break;
    case DODECA:
      dodecahedron();
      break;
    default:
      exit (-1);
      break;
  }

  write_file();
}