示例#1
0
	//constructor
	Bullit :: Bullit(float xx, float yy,int dir,int ww, int hh){
		setHealth(1);
		setDirectionGoing(dir);
		setSpeed(30);
		setNumOfVertices(3);
		setDistance(0);
		width = 50;
		height = 50;
		setXPos((xx+ww/2-width/2)-(xx+ww/2));
		setYPos((yy+hh+height+10)-(yy+hh/2));
		float dist=sqrt(pow(getXPos(),2)+pow(getYPos(),2));
		setXPos(xx+ww/2-width/2+dist*cos(getDirectionGoing()*PI/180));
		setYPos(yy+hh/2-height/2+dist*sin(getDirectionGoing()*PI/180));
		x=xx;
		y=yy;
		w=ww;
		h=hh;
		setNumOfVertices(3);

		//define the bullit
		vertices[0] = getXPos();	//left x
		vertices[1] = getYPos();	//left y
		
		vertices[2] = getXPos()+width;		//right x
		vertices[3] = getYPos();		//right y
		
		vertices[4] = getXPos()+width/2;	//top x
		vertices[5] = getYPos()+height;		//top y
	}
void Hypergraph::loadLayout(const QString &fileName)
{
	ifstream layoutFile (fileName.toStdString().c_str(), ios::binary);
	layoutFile.read((char*)&_layoutDim, sizeof(int));
	layoutFile.read((char*)&_nVertices, sizeof(int));
	setNumOfVertices(_nVertices);
	int nEdges;
	layoutFile.read((char*)&nEdges, sizeof(int));
	_edges.clear();
	for (int i=0; i<nEdges; ++i)
	{
		int edgeSize;
		layoutFile.read((char*)&edgeSize, sizeof(int));
		HyperEdge e (edgeSize);
		for (int j=0; j<edgeSize; ++j)
		{
			layoutFile.read((char*)&(e[j]), sizeof(int));
		}
		_edges.push_back(e);
	}
	_layout.resize(_nVertices+nEdges);
	for(int i=0; i<_nVertices+nEdges; ++i)
	{
		_layout[i] = fvec(_layoutDim);
		layoutFile.read((char*)_layout[i].memptr(), _layoutDim*sizeof(float));
	}
	layoutFile.close();
}
void Hypergraph::loadHypergraph(const QString &fileName)
{
	ifstream graphFile (fileName.toStdString().c_str());
	graphFile >>_nVertices;
	setNumOfVertices(_nVertices);
	string line;
	_edges.clear();
	while(getline(graphFile,line))
	{
		stringstream strLine(line);
		HyperEdge e(0);
		int fibIdx;
		while (strLine >>fibIdx)
		{
			e.push_back(fibIdx);
		}
		if (!e.empty())
		{
			_edges.push_back(e);
		}
	}
	graphFile.close();
}