예제 #1
0
		//when we call this, we must be sure the object is 2d
		PtrLineList Draw2DQuads(){
			Coordinate::iterator Di = Dimensions.begin();
			Coordinate::iterator Li = Location.begin();

			glVertex3f(Li[0],Li[1],Li[2]);


		}
예제 #2
0
Coordinate
Dimensions::getCoordinate(const size_t index) const
{
  Coordinate coordinate;
  size_t x = index;

  size_t product = 1;
  for(size_type i = 0; i < size(); i++)
  {
    product *= at(i);
  }

  for(size_type i = size()-1; i != (size_type)-1; i--)
  {
    product/=at(i);
    coordinate.insert(coordinate.begin(), x/product);
    x%=product;
  }

  return coordinate;
}
예제 #3
0
		//This will return a list of polygons that can be used to explicitly 
		//outline the bounding structure. This is being created for collision
		//debugging, and may not be appropriate for rendering complex arbitrary 
		//hulls due to many redundant shared verticies.
		PtrLineList GetShape(){
			//Create a wireframe for our AABB

			//Store the wires we've found
			PtrLineList result(new LineList);

			//We are finished when we run out of verticies to consider
			set<Coordinate> WorkingVerticies;
			set<Coordinate> WorkingVerticiesSwapBuffer;

			//add our first vertex as a seed

			WorkingVerticies.insert(Location);

			Coordinate CurrentV;
			Coordinate::iterator CVi;
			Coordinate PreviousV;

			//to iterate over our location and dimensions
			Coordinate::iterator Li;
			Coordinate::iterator Di;

			Line L;

			//When both vertex buffers are empty, we exit
			while(WorkingVerticies.size() > 0){

				//When one vertex buffer is empty, we swap the new one in its place
				while(WorkingVerticies.size() > 0){
					//(re)set our iterators
					Di = Dimensions.begin();
					Li = Location.begin();

					//begin processing the first vertex.
					CurrentV = PreviousV = *WorkingVerticies.begin();
					CVi = CurrentV.begin();

					//Go through our location dimension by dimension.
					while(CVi!=CurrentV.end()){
						//if this dimension has not been incremented to its extreme
						if(*CVi == *Li){
							//increment it to it's extreme
							*CVi = (*Li) + (*Di);
							//verticies in the swap buffer will be processed
							//in the next iterative pass.
							WorkingVerticiesSwapBuffer.insert(CurrentV);
							//Add our new line segment
							L.first = PreviousV;
							L.second = CurrentV;
							result->push_back(L);

							if(debug){
								Coordinate::iterator Ci = PreviousV.begin();
								while(Ci != PreviousV.end()){
									++Ci;
								}
								Ci = CurrentV.begin();
								while(Ci != CurrentV.end()){
									++Ci;
								}
							}

							//Undo our increment and move on
							*CVi = *Li;
						}
						++CVi;
						++Li;
						++Di;
					}

					//We are done processing this vertex. Remove it.
					WorkingVerticies.erase(WorkingVerticies.begin());
				}

				//Dump swap buffer into WorkingVerticies. if swap.size()>0, we iterate.
				WorkingVerticies = WorkingVerticiesSwapBuffer;
				WorkingVerticiesSwapBuffer.clear();
			}
			return result;
		}
예제 #4
0
		//when we call this, we must be sure the object is 3d
		void Draw3DQuads(){
			Coordinate::iterator Di = Dimensions.begin();
			Coordinate::iterator Li = Location.begin();

			glBegin(GL_QUADS);
			//front
			glTexCoord2f(0.0,0.0);
			glVertex3f(Li[0]+Di[0],Li[1],Li[2]);
			glTexCoord2f(0.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1]+Di[1],Li[2]);
			glTexCoord2f(1.0,1.0);
			glVertex3f(Li[0],Li[1]+Di[1],Li[2]);
			glTexCoord2f(1.0,0.0);
			glVertex3f(Li[0],Li[1],Li[2]);
			//top
			glTexCoord2f(0.0,0.0);
			glVertex3f(Li[0],Li[1],Li[2]);
			glTexCoord2f(0.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1],Li[2]);
			glTexCoord2f(1.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1],Li[2]+Di[2]);
			glTexCoord2f(1.0,0.0);
			glVertex3f(Li[0],Li[1],Li[2]+Di[2]);
			//bottom
			glTexCoord2f(0.0,0.0);
			glVertex3f(Li[0],Li[1]+Di[1],Li[2]);
			glTexCoord2f(0.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1]+Di[1],Li[2]);
			glTexCoord2f(1.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1]+Di[1],Li[2]+Di[2]);
			glTexCoord2f(1.0,0.0);
			glVertex3f(Li[0],Li[1]+Di[1],Li[2]+Di[2]);
			//back
			glTexCoord2f(0.0,0.0);
			glVertex3f(Li[0],Li[1],Li[2]+Di[2]);
			glTexCoord2f(0.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1],Li[2]+Di[2]);
			glTexCoord2f(1.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1]+Di[1],Li[2]+Di[2]);
			glTexCoord2f(1.0,0.0);
			glVertex3f(Li[0],Li[1]+Di[1],Li[2]+Di[2]);
			//left
			glTexCoord2f(0.0,0.0);
			glVertex3f(Li[0],Li[1],Li[2]+Di[2]);
			glTexCoord2f(0.0,1.0);
			glVertex3f(Li[0],Li[1]+Di[1],Li[2]+Di[2]);
			glTexCoord2f(1.0,1.0);
			glVertex3f(Li[0],Li[1]+Di[1],Li[2]);
			glTexCoord2f(1.0,0.0);
			glVertex3f(Li[0],Li[1],Li[2]);
			//right
			glTexCoord2f(0.0,0.0);
			glVertex3f(Li[0]+Di[0],Li[1],Li[2]);
			glTexCoord2f(0.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1]+Di[1],Li[2]);
			glTexCoord2f(1.0,1.0);
			glVertex3f(Li[0]+Di[0],Li[1]+Di[1],Li[2]+Di[2]);
			glTexCoord2f(1.0,0.0);
			glVertex3f(Li[0]+Di[0],Li[1],Li[2]+Di[2]);
			glEnd();
		}
예제 #5
0
	bool MapBuilder::load(const string& filename)
	{
		const string strLocation = "location";
		const string strBoundary = "boundary";
		const string strWind = "wind";
		const string strBuilding = "building";
		const string strUnit = "unit";
		const string strPotential = "potential";
		const string strOrigin = "origin";
		const string strIndex = "index";
		const string strCoord = "coordinate";

		using boost::property_tree::ptree;
		using boost::lexical_cast;

		ptree pt;
		read_json(filename, pt);

		unit_ = pt.get<unit_t>(strUnit);

		auto potentialNode = pt.get_optional<coord_item_t>(strPotential);
		if (potentialNode)
		{
			setLocalPotential(*potentialNode);
		}

		auto node_boundary = pt.get_child(strBoundary);
		transform(node_boundary.begin(), node_boundary.end(), boundary_.begin(), [](ptree::value_type& v)
		          {
			          return lexical_cast<coord_item_t>(v.second.data());
		          });

		auto node_location = pt.get_child_optional(strLocation);
		if (node_location)
		{
			setStartIndex(Coordinate());
			transform(node_location->begin(), node_location->end(), (*startIndex_).begin(), [](ptree::value_type& v)
			          {
				          return lexical_cast<coord_item_t>(v.second.data());
			          });
		}

		auto node_wind = pt.get_child_optional(strWind);
		if (node_wind)
		{
			setWind(WindVector());
			transform(node_wind->begin(), node_wind->end(), wind_->begin(), [](ptree::value_type& v)
			          {
				          return lexical_cast<wv_item_t>(v.second.data());
			          });
		}

		auto node_origin = pt.get_child_optional(strOrigin);
		if (node_origin)
		{
			auto node_index = node_origin->get_child(strIndex);
			Coordinate index;
			transform(node_index.begin(), node_index.end(), index.begin(), [](ptree::value_type& v)
			          {
				          return lexical_cast<coord_item_t>(v.second.data());
			          });

			auto node_coord = node_origin->get_child(strCoord);
			WindVector coord;
			transform(node_coord.begin(), node_coord.end(), coord.begin(), [](ptree::value_type& v)
			          {
				          return lexical_cast<wv_item_t>(v.second.data());
			          });

			setOrigin(make_pair(index, coord));
		}

		auto node_buildings = pt.get_child_optional(strBuilding);
		if (node_buildings)
		{
			for (auto node_building : *node_buildings)
			{
				auto node_bld_tree = node_building.second;

				stBuilding building;
				auto node_location = node_bld_tree.get_child(strLocation);
				transform(node_location.begin(), node_location.end(), building.location_.begin(), [](ptree::value_type& v)
				          {
					          return lexical_cast<coord_item_t>(v.second.data());
				          });

				auto node_boudnary = node_bld_tree.get_child(strBoundary);
				transform(node_boudnary.begin(), node_boudnary.end(), building.boundary_.begin(), [](ptree::value_type& v)
				          {
					          return lexical_cast<coord_item_t>(v.second.data());
				          });

				buildings_.push_back(building);
			}
		}

		return true;
	}