コード例 #1
0
ファイル: Icosa.cpp プロジェクト: kamalsirsa/vtp
void DymaxIcosa::AddFlatTri(DLine2Array &polys, int a, int b, int c, int d)
{
	DLine2 poly;
	poly.Append(m_flatverts[a]);
	poly.Append(m_flatverts[b]);
	poly.Append(m_flatverts[c]);
	if (d != -1)
		poly.Append(m_flatverts[d]);
	polys.push_back(poly);
}
コード例 #2
0
ファイル: Building.cpp プロジェクト: kalwalt/ofxVTerrain
/**
 * Sets the base footprint of the building to be a circle.  A circle
 * is represented by a 20-sided polygonal footprint.
 *
 * \param center The location of the building's center.
 * \param fRad The radius of the building.
 */
void vtBuilding::SetCircle(const DPoint2 &center, float fRad)
{
	DLine2 fp;
	int i;
	for (i = 0; i < 20; i++)
	{
		double angle = i * PI2d / 20;
		DPoint2 vec(cos(angle) * fRad, sin(angle) * fRad);
		fp.Append(center + vec);
	}
	SetFootprint(0, fp);
}
コード例 #3
0
ファイル: Building.cpp プロジェクト: kalwalt/ofxVTerrain
void vtBuilding::SetRectangle(const DPoint2 &center, float fWidth,
							  float fDepth, float fRotation)
{
	vtLevel *pLev;

	// this function requires at least one level to exist
	if (m_Levels.GetSize() == 0)
	{
		pLev = new vtLevel;
		pLev->m_iStories = 1;
		m_Levels.Append(pLev);
	}
	else
		pLev = m_Levels[0];

	// if rotation is unset, default to none
	if (fRotation == -1.0f)
		fRotation = 0.0f;

	DPoint2 pt(fWidth / 2.0, fDepth / 2.0);
	DPoint2 corner[4];
	corner[0].Set(-pt.x, -pt.y);
	corner[1].Set(pt.x, -pt.y);
	corner[2].Set(pt.x, pt.y);
	corner[3].Set(-pt.x, pt.y);
	corner[0].Rotate(fRotation);
	corner[1].Rotate(fRotation);
	corner[2].Rotate(fRotation);
	corner[3].Rotate(fRotation);

	DLine2 dl;
	dl.Append(center + corner[0]);
	dl.Append(center + corner[1]);
	dl.Append(center + corner[2]);
	dl.Append(center + corner[3]);

	pLev->SetFootprint(dl);
}
コード例 #4
0
ファイル: StructArray.cpp プロジェクト: kalwalt/ofxVTerrain
void DLine2FromString(const char *data, DLine2 &line)
{
	// Speed/memory optimization: quick check of how many vertices
	//  there are, then preallocate that many
	uint verts = 0;
	for (size_t i = 0; i < strlen(data); i++)
		if (data[i] == ',')
			verts++;
	line.Empty();
	line.SetMaxSize(verts);

	double x, y;
	while (sscanf(data, "%lf,%lf", &x, &y) == 2)
	{
		line.Append(DPoint2(x,y));
		data = strchr(data, ' ');
		if (!data)
			break;
		data++;
	}
}
コード例 #5
0
ファイル: StructArray.cpp プロジェクト: kalwalt/ofxVTerrain
void StructureVisitor::startElement (const char * name, const XMLAttributes &atts)
{
	int i;

	if (_level == 0)
	{
		if (string(name) != (string)"structures-file")
		{
			string message = "Root element name is ";
			message += name;
			message += "; expected structures-file";
			throw xh_io_exception(message, "XML Reader");
		}
		push_state(NULL, "top");
		return;
	}

	if (_level == 1)
	{
		if (string(name) == (string)"coordinates")
		{
			const char *type  = atts.getValue("type");
			const char *value = atts.getValue("value");
			m_pSA->m_proj.SetTextDescription(type, value);
			g_Conv.Setup(m_pSA->m_proj.GetUnits(), DRECT(0,1,1,0));
		}
		else if (string(name) == (string)"structures")
		{
			push_state(NULL, "structures");
		}
		else
		{
			// Unknown element: ignore
			push_state(NULL, "dummy");
		}
		return;
	}

	const char *attval;

	if (_level == 2)
	{
		vtStructure *pStruct = NULL;
		if (string(name) == (string)"structure")
		{
			// Get the name.
			attval = atts.getValue("type");
			if (attval != NULL)
			{
				if (string(attval) == (string)"building")
				{
					vtBuilding *bld = m_pSA->NewBuilding();
					pStruct = bld;
				}
				if (string(attval) == (string)"linear")
				{
					vtFence *fen = m_pSA->NewFence();
					pStruct = fen;
				}
				if (string(attval) == (string)"instance")
				{
					vtStructInstance *inst = m_pSA->NewInstance();
					pStruct = inst;
				}
			}
			push_state(pStruct, "structure");
		}
		else
		{
			// Unknown field, ignore.
			pStruct = NULL;
			push_state(pStruct, "dummy");
		}
		return;
	}

	State &st = state();
	vtStructure *pStruct = st.item;
	if (!pStruct)
		return;
	vtFence *fen = pStruct->GetFence();
	vtBuilding *bld = pStruct->GetBuilding();
	vtStructInstance *inst = pStruct->GetInstance();

	if (_level == 3 && bld != NULL)
	{
		if (string(name) == (string)"height")
		{
			attval = atts.getValue("stories");
			if (attval)
			{
				// height in stories ("floors")
				int stories = atoi(attval);
				if (bld)
					bld->SetStories(stories);
			}
		}
		if (string(name) == (string)"walls")
		{
			attval = atts.getValue("color");
			if (bld && attval)
				st.wall_color = ParseRGB(attval);
		}
		if (string(name) == (string)"shapes")
		{
			push_state(pStruct, "shapes");
			return;
		}
		if (string(name) == (string)"roof")
		{
			// hack to postpone setting building color until now
			bld->SetColor(BLD_BASIC, st.wall_color);

			const char *type = atts.getValue("type");
			if (bld && (string)type == (string)"flat")
				bld->SetRoofType(ROOF_FLAT);
			if (bld && (string)type == (string)"shed")
				bld->SetRoofType(ROOF_SHED);
			if (bld && (string)type == (string)"gable")
				bld->SetRoofType(ROOF_GABLE);
			if (bld && (string)type == (string)"hip")
				bld->SetRoofType(ROOF_HIP);
			attval = atts.getValue("color");
			if (bld && attval)
				bld->SetColor(BLD_ROOF, ParseRGB(attval));
		}
		if (string(name) == (string)"points")
		{
			attval = atts.getValue("num");
		}
		return;
	}
	if (_level == 3 && fen != NULL)
	{
		if (string(name) == (string)"points")
		{
			int points;
			const char *num = atts.getValue("num");
			points = atoi(num);

			DLine2 &fencepts = fen->GetFencePoints();

			DPoint2 loc;
			const char *coords = atts.getValue("coords");
			const char *cp = coords;
			for (i = 0; i < points; i++)
			{
				sscanf(cp, "%lf %lf", &loc.x, &loc.y);
				fencepts.Append(loc);
				cp = strchr(cp, ' ');
				cp++;
				cp = strchr(cp, ' ');
				cp++;
			}
		}
		if (string(name) == (string)"height")
		{
			// absolute height in meters
			const char *abs_str = atts.getValue("abs");
			if (abs_str)
				fen->GetParams().m_fPostHeight = (float)atof(abs_str);
		}
		if (string(name) == (string)"posts")
		{
			// this linear structure has posts
			const char *type = atts.getValue("type");
			if (0 == strcmp(type, "wood"))
				fen->ApplyStyle(FS_WOOD_POSTS_WIRE);
			else if (0 == strcmp(type, "steel"))
				fen->ApplyStyle(FS_CHAINLINK);
			else
				fen->ApplyStyle(FS_METAL_POSTS_WIRE);

			const char *size = atts.getValue("size");
			FPoint3 postsize;
			postsize.y = fen->GetParams().m_fPostHeight;
			sscanf(size, "%f, %f", &postsize.x, &postsize.z);
			fen->GetParams().m_fPostWidth = postsize.x;
			fen->GetParams().m_fPostDepth = postsize.z;

			const char *spacing = atts.getValue("spacing");
			if (spacing)
				fen->GetParams().m_fPostSpacing = (float)atof(spacing);
		}
		if (string(name) == (string)"connect")
		{
			attval = atts.getValue("type");
			// not supported here
		}
		return;
	}
	if (_level == 3 && inst != NULL)
	{
		if (string(name) == (string)"placement")
		{
			const char *loc = atts.getValue("location");
			if (loc)
			{
				DPoint2 p;
				sscanf(loc, "%lf %lf", &p.x, &p.y);
				inst->SetPoint(p);
			}
			const char *rot = atts.getValue("rotation");
			if (rot)
			{
				float fRot;
				sscanf(rot, "%f", &fRot);
				inst->SetRotation(fRot);
			}
		}
		else
			_data = "";
	}
	if (_level == 4 && bld != NULL)
	{
		if (string(name) == (string)"rect")
		{
			DPoint2 loc;
			FPoint2 size2;
			const char *ref_point = atts.getValue("ref_point");
			if (ref_point)
			{
				sscanf(ref_point, "%lf %lf", &loc.x, &loc.y);
				bld->SetRectangle(loc, 10, 10);
			}
			float fRotation = 0.0f;
			const char *rot = atts.getValue("rot");
			if (rot)
			{
				fRotation = (float)atof(rot);
			}
			const char *size = atts.getValue("size");
			if (size)
			{
				sscanf(size, "%f, %f", &size2.x, &size2.y);
				bld->SetRectangle(loc, size2.x, size2.y, fRotation);
			}
		}
		if (string(name) == (string)"circle")
		{
			DPoint2 loc;
			const char *ref_point = atts.getValue("ref_point");
			if (ref_point)
			{
				sscanf(ref_point, "%lf %lf", &loc.x, &loc.y);
				bld->SetCircle(loc, 10);
			}
			const char *radius = atts.getValue("radius");
			if (radius)
			{
				bld->SetCircle(loc, (float)atof(radius));
			}
		}
		if (string(name) == (string)"poly")
		{
			int points;
			const char *num = atts.getValue("num");
			points = atoi(num);

			DLine2 foot;
			DPoint2 loc;
			const char *coords = atts.getValue("coords");
			const char *cp = coords;
			for (i = 0; i < points; i++)
			{
				sscanf(cp, "%lf %lf", &loc.x, &loc.y);
				foot.Append(loc);
				cp = strchr(cp, ' ');
				cp++;
				cp = strchr(cp, ' ');
				cp++;
			}
			bld->SetFootprint(0, foot);
		}
	}
}