void ExperimentCheckpoints::init(Simulation *simulation, Experiment::Parameters &parameters)
{
    ExperimentController::init(simulation, parameters);

    announcedCheckpoint = -1;
    currentCheckpoint = 0;
    maxStep = parameters.get("dx");
    maxTurn = parameters.get("maxTurn");
    kT = parameters.get("kt");

    checkpoints.push_back(FPoint2(500, 0.0));
    checkpoints.push_back(FPoint2(500, 500));
    checkpoints.push_back(FPoint2(800, 500));
    checkpoints.push_back(FPoint2(0, 0));
    controlT = 0;
}
Exemple #2
0
vtMesh *NodeGeom::GenerateGeometry(const VirtualTexture &vt)
{
	if (NumLinks() < 3)
		return NULL;

	FPoint2 uv;

	const FPoint3 upvector(0.0f, 1.0f, 0.0f);

	vtMesh *pMesh = new vtMesh(osg::PrimitiveSet::TRIANGLE_FAN, VT_TexCoords | VT_Normals, NumLinks()*2 + 1);
	int verts = 0;

	vt.Adapt(FPoint2(0.5f, 0.5f), uv);

	pMesh->SetVtxPUV(verts, m_p3, uv.x, uv.y);
	pMesh->SetVtxNormal(verts, upvector);
	verts++;

	for (int j = 0; j < NumLinks(); j++)
	{
		vt.Adapt(FPoint2(0.0f, 1.0f), uv);
		pMesh->SetVtxPUV(verts, m_v[j*2+1], uv.x, uv.y);

		vt.Adapt(FPoint2(1.0f, 1.0f), uv);
		pMesh->SetVtxPUV(verts+1, m_v[j*2], uv.x, uv.y);

		pMesh->SetVtxNormal(verts, upvector);
		pMesh->SetVtxNormal(verts+1, upvector);
		verts += 2;
	}

	// create triangles
	verts = 0;
	int idx[100];
	idx[verts++] = 0;
	for (int j = 0; j < NumLinks(); j++)
	{
		idx[verts++] = (j*2+1);
		idx[verts++] = (j*2+2);
	}
	idx[verts++] = 1;	// close it
	pMesh->AddFan(idx, verts);
	return pMesh;
}
Exemple #3
0
void LinkGeom::AddRoadStrip(vtMesh *pMesh, RoadBuildInfo &bi,
							float offset_left, float offset_right,
							float height_left, float height_right,
							VirtualTexture &vt,
							float u1, float u2, float uv_scale,
							normal_direction nd)
{
	FPoint3 local0, local1, normal;
	float texture_v;
	FPoint2 uv;

	for (uint j = 0; j < GetSize(); j++)
	{
		texture_v = bi.fvLength[j] * uv_scale;

		local0 = bi.center[j] + (bi.crossvector[j] * offset_left);
		local1 = bi.center[j] + (bi.crossvector[j] * offset_right);
		local0.y += height_left;
		local1.y += height_right;

		if (nd == ND_UP)
			normal.Set(0.0f, 1.0f, 0.0f);	// up
		else if (nd == ND_LEFT)
			normal = (bi.crossvector[j] * -1.0f);	// left
		else
			normal = bi.crossvector[j];		// right

		vt.Adapt(FPoint2(u2, texture_v), uv);
		pMesh->AddVertexUV(local1, uv);

		vt.Adapt(FPoint2(u1, texture_v), uv);
		pMesh->AddVertexUV(local0, uv);

		pMesh->SetVtxNormal(bi.verts, normal);
		pMesh->SetVtxNormal(bi.verts+1, normal);
		bi.verts += 2;
	}
	// create tristrip
	pMesh->AddStrip2(GetSize() * 2, bi.vert_index);
	bi.vert_index += (GetSize() * 2);
}
Exemple #4
0
/**
 * Create a vtImageSprite.
 *
 * \param pImage A texture image.
 * \param bBlending Set to true for alpha-blending, which produces smooth
 *		edges on transparent textures.
 */
bool vtImageSprite::Create(osg::Image *pImage, bool bBlending)
{
	m_Size.x = GetWidth(pImage);
	m_Size.y = GetHeight(pImage);

	// set up material and geometry container
	m_pMats = new vtMaterialArray;
	m_pGeode = new vtGeode;
	m_pGeode->SetMaterials(m_pMats);

	m_pMats->AddTextureMaterial(pImage, false, false, bBlending);

	// default position of the mesh is just 0,0-1,1
	m_pMesh = new vtMesh(osg::PrimitiveSet::QUADS, VT_TexCoords, 4);
	m_pMesh->AddVertexUV(FPoint3(0,0,0), FPoint2(0,0));
	m_pMesh->AddVertexUV(FPoint3(1,0,0), FPoint2(1,0));
	m_pMesh->AddVertexUV(FPoint3(1,1,0), FPoint2(1,1));
	m_pMesh->AddVertexUV(FPoint3(0,1,0), FPoint2(0,1));
	m_pMesh->AddQuad(0, 1, 2, 3);
	m_pGeode->AddMesh(m_pMesh, 0);
	return true;
}
Exemple #5
0
void vtFence3d::AddProfileConnectionMesh(const FLine3 &p3)
{
	uint i, j, npoints = p3.GetSize(), prof_points = m_Profile.GetSize();

	// Must have at least 2 points in the profile
	if (prof_points < 2)
		return;

	// Each segment of the profile becomes a long triangle strip.
	// If there are no shared vertices between segments, the number of
	//  vertices is, for a profile of N points and a line of P points:
	//   P * (N-1) * 2, for the sides
	//   N*2, for the end caps (or more if we have to tessellate)
	//
	int iEstimateVerts = npoints * (prof_points-1) * 2 + (prof_points * 2);
	vtMesh *pMesh = new vtMesh(osg::PrimitiveSet::TRIANGLE_STRIP,
		VT_TexCoords | VT_Normals, iEstimateVerts);

	vtMaterialDescriptor *desc = GetMatDescriptor(m_Params.m_ConnectMaterial);
	if (!desc)
	{
		VTLOG1("Warning: could not find material: ");
		VTLOG1(m_Params.m_ConnectMaterial);
		VTLOG1("\n");
		return;
	}
	FPoint2 uvscale = desc->GetUVScale();

	// determine side-pointing vector
	vtArray<float> ExtraElevation(npoints);
	FLine3 sideways(npoints);
	for (j = 0; j < npoints; j++)
	{
		// determine side-pointing vector
		if (j == 0)
			sideways[j] = SidewaysVector(p3[j], p3[j+1]);
		else if (j > 0 && j < npoints-1)
		{
			AngleSideVector(p3[j-1], p3[j], p3[j+1], sideways[j]);
			sideways[j] = -sideways[j];	// We want a vector pointing left, not right
		}
		else if (j == npoints-1)
			sideways[j] = SidewaysVector(p3[j-1], p3[j]);

		ExtraElevation[j] = 0.0f;
		if (m_Params.m_bConstantTop)
			ExtraElevation[j] = m_fMaxGroundY - p3[j].y;
	}

	float u;
	float v1, v2;
	for (i = 0; i < prof_points-1; i++)
	{
		float y1, y2;
		float z1, z2;
		FPoint3 pos, normal;

		// determine v texture coordinate
		float seg_length = m_Profile.SegmentLength(i);
		if (uvscale.y == -1)
		{
			v1 = 0.0f;
			v2 = 1.0f;
		}
		else
		{
			if (i == 0)
			{
				v1 = 0.0f;
				v2 = seg_length / uvscale.y;
			}
			else
			{
				v1 = v2;
				v2 += seg_length / uvscale.y;
			}
		}

		// determine Y and Z values
		y1 = m_Profile[i].y;
		y2 = m_Profile[i+1].y;
		z1 = m_Profile[i].x;
		z2 = m_Profile[i+1].x;

		u = 0.0f;
		int start = pMesh->NumVertices();
		for (j = 0; j < npoints; j++)
		{
			// determine vertex normal (for shading)
			float diffy = y2-y1;
			float diffz = z2-z1;
			float dy = -diffz;
			float dz = diffy;

			FPoint3 n1, n2;
			n1.Set(0, y1, 0);
			n1 += (sideways[j] * z1);
			n2.Set(0, y1 + dy, 0);
			n2 += (sideways[j] * (z1 + dz));

			normal = n2 - n1;
			normal.Normalize();

			// determine the two points of this segment edge, and add them
			pos = p3[j];
			pos.y += y2;
			pos.y += ExtraElevation[j];
			pos += (sideways[j] * z2);
			pMesh->AddVertexNUV(pos, normal, FPoint2(u, v2));

			pos = p3[j];
			pos.y += y1;
			pos.y += ExtraElevation[j];
			pos += (sideways[j] * z1);
			pMesh->AddVertexNUV(pos, normal, FPoint2(u, v1));

			if (j < npoints-1)
			{
				// increment u based on the length of each fence segment
				float length_meters = (p3[j+1] - p3[j]).Length();
				u += (length_meters / uvscale.x);
			}
		}
		pMesh->AddStrip2(npoints * 2, start);
	}

	// We must assume the profile is interpreted as a closed polygon, which
	//  may not be convex.  Hence it must be triangulated.
	FLine2 result;
	Triangulate_f::Process(m_Profile, result);
	uint tcount = result.GetSize()/3;

	int ind[3];
	int line_point;
	FPoint3 normal;

	// add cap at beginning
	line_point = 0;
	normal = p3[0] - p3[1];
	normal.Normalize();
	for (i=0; i<tcount; i++)
	{
		for (j = 0; j < 3; j++)
		{
			FPoint2 p2 = result[i*3+j];

			FPoint3 pos = p3[line_point];
			pos.y += p2.y;
			pos.y += ExtraElevation[line_point];
			pos += (sideways[line_point] * p2.x);

			FPoint2 uv = p2;
			if (uvscale.y != -1)
				uv.Div(uvscale);	// divide meters by [meters/uv] to get uv

			ind[j] = pMesh->AddVertexNUV(pos, normal, uv);
		}
		pMesh->AddTri(ind[0], ind[1], ind[2]);
	}

	// add cap at end
	line_point = npoints-1;
	normal = p3[npoints-1] - p3[npoints-2];
	normal.Normalize();
	for (i=0; i<tcount; i++)
	{
		for (j = 0; j < 3; j++)
		{
			FPoint2 p2 = result[i*3+j];

			FPoint3 pos = p3[line_point];
			pos.y += p2.y;
			pos.y += ExtraElevation[line_point];
			pos += (sideways[line_point] * p2.x);

			FPoint2 uv = p2;
			if (uvscale.y != -1)
				uv.Div(uvscale);	// divide meters by [meters/uv] to get uv

			ind[j] = pMesh->AddVertexNUV(pos, normal, uv);
		}
		pMesh->AddTri(ind[0], ind[2], ind[1]);
	}

	m_pFenceGeom->AddMesh(pMesh, GetMatIndex(desc));
}
Exemple #6
0
void vtFence3d::AddThickConnectionMesh(const FLine3 &p3)
{
	vtMesh *pMesh = new vtMesh(osg::PrimitiveSet::TRIANGLE_STRIP, VT_TexCoords | VT_Normals, 100);

	// a solid block, with top/left/right sides, made of 3 strips
	vtMaterialDescriptor *desc = GetMatDescriptor(m_Params.m_ConnectMaterial);
	if (!desc)
	{
		VTLOG1("Warning: could not find material: ");
		VTLOG1(m_Params.m_ConnectMaterial);
		VTLOG1("\n");
		return;
	}
	FPoint2 uvscale = desc->GetUVScale();
	float vertical_meters = m_Params.m_fConnectTop - m_Params.m_fConnectBottom;

	float fWidthTop = m_Params.m_fConnectWidth / 2;
	float slope = m_Params.m_iConnectSlope / 180.0f * PIf;

	uint i, j, npoints = p3.GetSize();
	float u = 0.0f;
	float v1, v2;
	for (i = 0; i < 3; i++)
	{
		float y1, y2;
		float z1, z2;
		FPoint3 pos, sideways, normal;

		int start = pMesh->NumVertices();
		for (j = 0; j < npoints; j++)
		{
			// determine side-pointing vector
			if (j == 0)
				sideways = SidewaysVector(p3[j], p3[j+1]);
			else if (j > 0 && j < npoints-1)
			{
				AngleSideVector(p3[j-1], p3[j], p3[j+1], sideways);
				sideways = -sideways;	// We want a vector pointing left, not right
			}
			else if (j == npoints-1)
				sideways = SidewaysVector(p3[j-1], p3[j]);

			// 'extra' elevation is added to maintain a constant top
			float fExtraElevation = 0.0f;
			if (m_Params.m_bConstantTop)
				fExtraElevation = m_fMaxGroundY - p3[j].y;

			float fVertical = vertical_meters + fExtraElevation;
			float fWidthBottom = fWidthTop + fVertical / tan(slope);

			// determine v texture coordinate
			switch (i)
			{
			case 0:		// right side
				v1 = 0.0f;
				if (uvscale.y == -1)
					v2 = 1.0f;
				else
					v2 = fVertical / uvscale.y;
				break;
			case 1:		// top
				v1 = 0.0f;
				if (uvscale.y == -1)
					v2 = 1.0f;
				else
					v2 = m_Params.m_fConnectWidth / uvscale.y;
				break;
			case 2:		// left side
				v2 = 0.0f;
				if (uvscale.y == -1)
					v1 = 1.0f;
				else
					v1 = fVertical / uvscale.y;
				break;
			}

			// determine Y and Z values
			switch (i)
			{
			case 0:	// right side
				y1 = m_Params.m_fConnectBottom;
				y2 = m_Params.m_fConnectTop + fExtraElevation;
				z1 = fWidthBottom;
				z2 = fWidthTop;
				break;
			case 1:	// top
				y1 = m_Params.m_fConnectTop + fExtraElevation;
				y2 = m_Params.m_fConnectTop + fExtraElevation;
				z1 = fWidthTop;
				z2 = -fWidthTop;
				break;
			case 2:	// left side
				y1 = m_Params.m_fConnectTop + fExtraElevation;
				y2 = m_Params.m_fConnectBottom;
				z1 = -fWidthTop;
				z2 = -fWidthBottom;
				break;
			}

			// determine vertex normal (used for shading and thickness)
			switch (i)
			{
			case 0: normal = sideways; break;	// right
			case 1: normal.Set(0,1,0); break;	// top: up
			case 2: normal = -sideways; break;	// left
			}

			pos = p3[j];
			pos.y += y2;
			pos += (sideways * z2);
			pMesh->AddVertexNUV(pos, normal, FPoint2(u, v2));

			pos = p3[j];
			pos.y += y1;
			pos += (sideways * z1);
			pMesh->AddVertexNUV(pos, normal, FPoint2(u, v1));

			if (j < npoints-1)
			{
				// increment u based on the length of each fence segment
				float length_meters = (p3[j+1] - p3[j]).Length();
				u += (length_meters / uvscale.x);
			}
		}
		pMesh->AddStrip2(npoints * 2, start);
	}

	// add cap at beginning
	u = m_Params.m_fConnectWidth / desc->GetUVScale().x;
	v2 = vertical_meters / uvscale.y;

	int start =
	pMesh->AddVertex(pMesh->GetVtxPos(npoints*2*2+1));
	pMesh->AddVertex(pMesh->GetVtxPos(npoints*2*2));
	pMesh->AddVertex(pMesh->GetVtxPos(0));
	pMesh->AddVertex(pMesh->GetVtxPos(1));
	pMesh->SetVtxNormal(start+0, p3[0] - p3[1]);
	pMesh->SetVtxNormal(start+1, p3[0] - p3[1]);
	pMesh->SetVtxNormal(start+2, p3[0] - p3[1]);
	pMesh->SetVtxNormal(start+3, p3[0] - p3[1]);
	pMesh->SetVtxTexCoord(start+0, FPoint2(u, 0.0f));
	pMesh->SetVtxTexCoord(start+1, FPoint2(u, v2));
	pMesh->SetVtxTexCoord(start+2, FPoint2(0.0f, 0.0f));
	pMesh->SetVtxTexCoord(start+3, FPoint2(0.0f, v2));
	pMesh->AddStrip2(4, start);

	// add cap at end
	start =
	pMesh->AddVertex(pMesh->GetVtxPos(npoints*2-2));
	pMesh->AddVertex(pMesh->GetVtxPos(npoints*2-1));
	pMesh->AddVertex(pMesh->GetVtxPos(npoints*3*2-1));
	pMesh->AddVertex(pMesh->GetVtxPos(npoints*3*2-2));
	pMesh->SetVtxNormal(start+0, p3[npoints-1] - p3[npoints-2]);
	pMesh->SetVtxNormal(start+1, p3[npoints-1] - p3[npoints-2]);
	pMesh->SetVtxNormal(start+2, p3[npoints-1] - p3[npoints-2]);
	pMesh->SetVtxNormal(start+3, p3[npoints-1] - p3[npoints-2]);
	pMesh->SetVtxTexCoord(start+0, FPoint2(0.0f, 0.0f));
	pMesh->SetVtxTexCoord(start+1, FPoint2(0.0f, v2));
	pMesh->SetVtxTexCoord(start+2, FPoint2(u, 0.0f));
	pMesh->SetVtxTexCoord(start+3, FPoint2(u, v2));
	pMesh->AddStrip2(4, start);

	m_pFenceGeom->AddMesh(pMesh, GetMatIndex(desc));
}
Exemple #7
0
FPoint2 vtHeightFieldGrid3d::GetWorldSpacing() const
{
	return FPoint2(m_fXStep, m_fZStep);
}