Ejemplo n.º 1
0
void PolygonObject::prepareForDock(const Point &point, S32 teamIndex)
{
#ifndef ZAP_DEDICATED
   F32 h = 16;    // Entire height
   F32 w = 20;    // Half the width

   clearVerts();
   addVert(point + Point(-w, 0)); 
   addVert(point + Point( w, 0)); 
   addVert(point + Point( w, h)); 
   addVert(point + Point(-w, h)); 

   Parent::prepareForDock(point, teamIndex);
#endif
}
Ejemplo n.º 2
0
// Read and process NexusZone format used in Zap -- we need this for backwards compatibility
void NexusZone::processArguments_ArchaicZapFormat(S32 argc, const char **argv, F32 gridSize)
{
    Point pos;
    pos.read(argv);
    pos *= gridSize;

    Point ext(50, 50);

    if(argc == 4)
        ext.set(atoi(argv[2]), atoi(argv[3]));

    addVert(Point(pos.x - ext.x, pos.y - ext.y));   // UL corner
    addVert(Point(pos.x + ext.x, pos.y - ext.y));   // UR corner
    addVert(Point(pos.x + ext.x, pos.y + ext.y));   // LR corner
    addVert(Point(pos.x - ext.x, pos.y + ext.y));   // LL corner

    updateExtentInDatabase();
}
Ejemplo n.º 3
0
//prob 0 - 100
Bipart::Bipart(int nbNode, int prob)
{
    this->nbVerts = nbNode;
    partLeft.push_back(ListAdj((Node(0))));
    partRight.push_back(ListAdj((Node(1))));
    for(int i=2; i < nbVerts; i++){
        Node n(i);
        addVert(n);
    }
    for (std::list<ListAdj>::iterator it=this->partLeft.begin(); it != this->partLeft.end(); ++it)
    {
        for (std::list<ListAdj>::iterator it2=this->partRight.begin(); it2 != this->partRight.end(); ++it2)
        {
            if(it != it2){
                if((rand() % 100) < prob){
                    addEdge(&(*it), &(*it2));
                }
            }
        }
    }

}
Ejemplo n.º 4
0
	void PlayState::createPointCloud(bool cap)
	{
		// process depth data and create mesh....
		k_depth* data;
		byte* color;

		if(cap)
		{
			data = mDevice->getRawDepth();
			color = mDevice->getRawColor();
			memcpy(storedColor, color, sizeof(640*480*3));
			memcpy(storedDepth, data, sizeof(640*480*2));
		}
		else
		{
			data = storedDepth;
			color = storedColor;
		}

		MeshData d = MeshData();
		//d.addTexcoordSet();
	
		for(int i=0;i<640*480;++i)
		{
			if(data[i] > 2046)
				continue;

			/*int x = i % 640;
			int y = i / 640;

			if(x >= 1 && x <= 638 && y <= 478 && y >= 238)
			{
				// get two adjacent points
				Vector3 pos1 = Kinect::getApproxPos(i+1,data[i+1]);
				Vector3 pos2 = Kinect::getApproxPos(i+640,data[i+640]);
				Vector3 center = Kinect::getApproxPos(i,data[i]);
				
				// get vectors from the center to them
				Vector3 d1 = pos1 - center;
				Vector3 d2 = pos2 - center;

				// get a normal
				Vector3 normal = d1.crossProduct(d2);
				normal.normalize();
				normal.y = -normal.y;

				addVert(d,center);

				if(normal.angleBetween(Vector3::UNIT_Y) < 40.f)
				{
					d.diffuse.push_back(1.f);
					d.diffuse.push_back(0.f);
					d.diffuse.push_back(0.f);
					d.diffuse.push_back(1.f);
				}
				else
				{
					d.diffuse.push_back(color[i*3]/255.f);
					d.diffuse.push_back(color[i*3+1]/255.f);
					d.diffuse.push_back(color[i*3+2]/255.f);
					d.diffuse.push_back(1.f);
				//}
			}
			else
			{*/
				addVert(d,Kinect::getApproxPos(i,data[i]));
				d.diffuse.push_back(color[i*3]/255.f);
				d.diffuse.push_back(color[i*3+1]/255.f);
				d.diffuse.push_back(color[i*3+2]/255.f);
				d.diffuse.push_back(1.f);
			//}


			// Alternate: make an actual polygonal mesh
			/*int left = data[i];
			int right = data[i+1];
			int d_left = data[i+640];
			int d_right = data[i+641];

			if(left > 2046 || right > 2046 || d_left > 2046 || d_right > 2046)
				continue;

			Vector3 l_pos = Kinect::getApproxPos(i, left);
			Vector3 r_pos = Kinect::getApproxPos(i+1, right);
			Vector3 dl_pos = Kinect::getApproxPos(i+640, d_left);
			Vector3 dr_pos = Kinect::getApproxPos(i+641, d_right);

			if(l_pos.squaredDistance(r_pos) > 0.1f ||
				dl_pos.squaredDistance(dr_pos) > 0.1f ||
				dl_pos.squaredDistance(r_pos) > 0.1f ||
				dr_pos.squaredDistance(l_pos) > 0.1f)
				continue;

			// clockwise winding
			// tri 1
			addVert(d, l_pos);
			addVert(d, r_pos);
			addVert(d, dr_pos);
			// tri 2
			addVert(d, dr_pos);
			addVert(d, dl_pos); 
			addVert(d, l_pos);*/
			
			//for(int j = 0; j < 6; ++j)
			//{
				/*if(floor_)
				{
					d.diffuse.push_back(1.f);
					d.diffuse.push_back(0.f);
					d.diffuse.push_back(0.f);
					d.diffuse.push_back(1.f);
				}
				else
				{*/
				//	d.diffuse.push_back(color[i*3]/255.f);
				//	d.diffuse.push_back(color[i*3+1]/255.f);
				//	d.diffuse.push_back(color[i*3+2]/255.f);
			//		d.diffuse.push_back(1.f);
				//}
			//}
		}

		if(!mMesh)
		{
			mMesh = mOgre->createMesh(d);
			mOgre->getRootSceneNode()->addChild(mMesh);
			mMesh->setMaterialName("cloud");
		}
		else
		{
			mMesh->update(d);
		}
	}
Ejemplo n.º 5
0
Mesh::Mesh(const std::map<MElement*,GEntity*> &element2entity,
           const std::set<MElement*> &els, std::set<MVertex*> &toFix,
           bool fixBndNodes, bool fastJacEval) :
  _fastJacEval(fastJacEval)
{

  _dim = (*els.begin())->getDim();

  // Initialize elements, vertices, free vertices and element->vertices
  // connectivity
  const int nElements = els.size();
  _nPC = 0;
  _el.resize(nElements);
  _el2FV.resize(nElements);
  _el2V.resize(nElements);
  _nBezEl.resize(nElements);
  _nNodEl.resize(nElements);
  _indPCEl.resize(nElements);
  int iEl = 0;
  bool nonGeoMove = false;
  for(std::set<MElement*>::const_iterator it = els.begin();
      it != els.end(); ++it, ++iEl) {
    _el[iEl] = *it;
    const JacobianBasis *jac = _el[iEl]->getJacobianFuncSpace();
    _nBezEl[iEl] = _fastJacEval ? jac->getNumJacNodesFast() : jac->getNumJacNodes();
    _nNodEl[iEl] = jac->getNumMapNodes();
    for (int iVEl = 0; iVEl < jac->getNumMapNodes(); iVEl++) {
      MVertex *vert = _el[iEl]->getVertex(iVEl);
      GEntity *ge = vert->onWhat();
      const int vDim = ge->dim();
      const bool hasParam = ge->haveParametrization();
      int iV = addVert(vert);
      _el2V[iEl].push_back(iV);
      if ((vDim > 0) && (toFix.find(vert) == toFix.end()) && (!fixBndNodes || vDim == _dim)) {   // Free vertex?
        ParamCoord *param;
        if (vDim == 3) param = new ParamCoordPhys3D();
        else if (hasParam) param = new ParamCoordParent(vert);
        else {
          if (vDim == 2) param = new ParamCoordLocalSurf(vert);
          else param = new ParamCoordLocalLine(vert);
          nonGeoMove = true;
        }
        int iFV = addFreeVert(vert,iV,vDim,param,toFix);
        _el2FV[iEl].push_back(iFV);
        for (int i=_startPCFV[iFV]; i<_startPCFV[iFV]+vDim; i++) _indPCEl[iEl].push_back(i);
      }
      else _el2FV[iEl].push_back(-1);
    }
  }

  if (nonGeoMove) Msg::Info("WARNING: Some vertices will be moved along local lines "
                            "or planes, they may not remain on the exact geometry");

  // Initial coordinates
  _ixyz.resize(nVert());
  for (int iV = 0; iV < nVert(); iV++) _ixyz[iV] = _vert[iV]->point();
  _iuvw.resize(nFV());
  for (int iFV = 0; iFV < nFV(); iFV++) _iuvw[iFV] = _paramFV[iFV]->getUvw(_freeVert[iFV]);

  // Set current coordinates
  _xyz = _ixyz;
  _uvw = _iuvw;

  // Set normals to 2D elements (with magnitude of inverse Jacobian) or initial
  // Jacobians of 3D elements
  if (_dim == 2) {
    _scaledNormEl.resize(nEl());
    for (int iEl = 0; iEl < nEl(); iEl++) calcScaledNormalEl2D(element2entity,iEl);
  }
  else {
    _invStraightJac.resize(nEl(),1.);
    double dumJac[3][3];
    for (int iEl = 0; iEl < nEl(); iEl++)
      _invStraightJac[iEl] = 1. / fabs(_el[iEl]->getPrimaryJacobian(0.,0.,0.,dumJac));
  }

}
Ejemplo n.º 6
0
void MoleculaB::addVert (pto3D p, int ti, String e)
{
    int n = susatomos.size();
    addVert (p, ti);
    susatomos.get(n)->pers = e;
}
Ejemplo n.º 7
0
//Metodos para añadir etiquetas personalizadas
void MoleculaB::addVert (double x, double y, double z, int ti, String e)
{
    int n = susatomos.size();
    addVert (x, y, z, ti);
    susatomos.get(n)->pers = e;
}
Ejemplo n.º 8
0
/** Create a 3D model by parsing an input stream */
Model3D::Model3D (JInputStream *is) /*throws IOException, FileFormatException*/ {
  DEBUG_OUT<<"Model3D::Model3D(JInputStream)\n";
  init();
  if(!is) return;
  //this();
  JStreamTokenizer *st = new JStreamTokenizer(is);
  st->eolIsSignificant(true);
  st->commentChar('#');
scan:
  while (true) {
      switch (st->nextToken()) {
        default:
  	break;
        case JStreamTokenizer_TT_EOF:
  	  return;
  			break;
  	  case JStreamTokenizer_TT_EOL:
  	break;
        case JStreamTokenizer_TT_WORD:
  	if (!strcmp("v",st->sval)/*"v".equals(st->sval)*/) {
  	    double x = 0, y = 0, z = 0;
  	    if (st->nextToken() == JStreamTokenizer_TT_NUMBER) {
  		x = st->nval;
  		if (st->nextToken() == JStreamTokenizer_TT_NUMBER) {
  		    y = st->nval;
  		    if (st->nextToken() == JStreamTokenizer_TT_NUMBER)
  			z = st->nval;
  		}
  	    }
  	    addVert((float) x, (float) y, (float) z);
  	    while (st->ttype != JStreamTokenizer_TT_EOL &&
  		    st->ttype != JStreamTokenizer_TT_EOF)
  		st->nextToken();
  	} else if (!strcmp("f",st->sval)/*"f".equals(st->sval)*/ || !strcmp("fo",st->sval)/*"fo".equals(st->sval)*/ || !strcmp("l",st->sval)/*"l".equals(st->sval)*/) {
  	    int start = -1;
  	    int prev = -1;
  	    int n = -1;
  	    while (true)
  		if (st->nextToken() == JStreamTokenizer_TT_NUMBER) {
  		    n = (int) st->nval;
  		    if (prev >= 0)
  			add(prev - 1, n - 1);
  		    if (start < 0)
  			start = n;
  		    prev = n;
  		} else if (st->ttype == '/')
  		    st->nextToken();
  		else
  		    break;
  	    if (start >= 0)
  		add(start - 1, prev - 1);
  	    if (st->ttype != JStreamTokenizer_TT_EOL)
  		break;
  	} else {
  	    while (st->nextToken() != JStreamTokenizer_TT_EOL
  		    && st->ttype != JStreamTokenizer_TT_EOF);
  	}
      }
  }
  is->close();
  //if (st->ttype != JStreamTokenizer_TT_EOF)
      //throw new FileFormatException(st->toString());
}
Ejemplo n.º 9
0
void Mesh::addVert(float x, float y, float z, float nx, float ny, float nz, float u, float v)
{
	Vertex vert = Vertex(x, y, z, nx, ny, nz, u, v);
	addVert(vert);
}
Ejemplo n.º 10
0
void Mesh::addVert(float x, float y, float z)
{
	Vertex vert = Vertex(x, y, z);
	addVert(vert);
}