Ejemplo n.º 1
0
bool SPRITE2D::Load(
	SCENENODE & parent,
	const std::string & texturepath,
	const std::string & texturename,
	ContentManager & content,
	float draworder)
{
	Unload(parent);

	assert(!draw.valid());
	assert(!node.valid());

	TEXTUREINFO texinfo;
	texinfo.mipmap = false;
	texinfo.repeatu = false;
	texinfo.repeatv = false;
	texinfo.npot = false;
	std::tr1::shared_ptr<TEXTURE> texture;
	if (!content.load(texturepath, texturename, texinfo, texture)) return false;

	node = parent.AddNode();
	SCENENODE & noderef = parent.GetNode(node);
	draw = noderef.GetDrawlist().twodim.insert(DRAWABLE());
	DRAWABLE & drawref = GetDrawableFromNode(noderef);

	drawref.SetDiffuseMap(texture);
	drawref.SetVertArray(&varray);
	drawref.SetDrawOrder(draworder);
	drawref.SetCull(false, false);
	drawref.SetColor(r,g,b,a);

	//std::cout << "Sprite draworder: " << draworder << std::endl;

	return true;
}
Ejemplo n.º 2
0
void ROADPATCH::AddRacinglineScenenode(
	SCENENODE & node,
	const ROADPATCH & nextpatch,
	std::tr1::shared_ptr<TEXTURE> racingline_texture)
{
	//Create racing line scenenode
	keyed_container <DRAWABLE>::handle drawhandle = node.GetDrawlist().normal_blend.insert(DRAWABLE());
	DRAWABLE & draw = node.GetDrawlist().normal_blend.get(drawhandle);

	draw.SetDiffuseMap(racingline_texture);
	draw.SetDecal(true);
	draw.SetVertArray(&racingline_vertexarray);

	const MATHVECTOR <float, 3> & r0 = patch.GetRacingLine();
	const MATHVECTOR <float, 3> & r1 = nextpatch.patch.GetRacingLine();
	MATHVECTOR <float, 3> v0 = r0 + (patch.GetPoint(0,0) - r0).Normalize()*0.1;
	MATHVECTOR <float, 3> v1 = r0 + (patch.GetPoint(0,3) - r0).Normalize()*0.1;
	MATHVECTOR <float, 3> v2 = r1 + (nextpatch.GetPatch().GetPoint(0,3) - r1).Normalize()*0.1;
	MATHVECTOR <float, 3> v3 = r1 + (nextpatch.GetPatch().GetPoint(0,0) - r1).Normalize()*0.1;

	float trackoffset = 0.1;
	v0[2] += trackoffset;
	v1[2] += trackoffset;
	v2[2] += trackoffset;
	v3[2] += trackoffset;

	float vcorners[12];
	float uvs[8];
	int bfaces[6];

	vcorners[0] = v0[0]; vcorners[1] = v0[1]; vcorners[2] = v0[2];
	vcorners[3] = v1[0]; vcorners[4] = v1[1]; vcorners[5] = v1[2];
	vcorners[6] = v2[0]; vcorners[7] = v2[1]; vcorners[8] = v2[2];
	vcorners[9] = v3[0]; vcorners[10] = v3[1]; vcorners[11] = v3[2];

	uvs[0] = 0;
	uvs[1] = 0;
	uvs[2] = 1;
	uvs[3] = 0;
	uvs[4] = 1;
	uvs[5] = (v2-v1).Magnitude();
	uvs[6] = 0;
	uvs[7] = (v2-v1).Magnitude();

	bfaces[0] = 0;
	bfaces[1] = 2;
	bfaces[2] = 1;
	bfaces[3] = 0;
	bfaces[4] = 3;
	bfaces[5] = 2;

	racingline_vertexarray.SetFaces(bfaces, 6);
	racingline_vertexarray.SetVertices(vcorners, 12);
	racingline_vertexarray.SetTexCoordSets(1);
	racingline_vertexarray.SetTexCoords(0, uvs, 8);
}
Ejemplo n.º 3
0
Archivo: ai.cpp Proyecto: mutnig/vdrift
void ConfigureDrawable(keyed_container <DRAWABLE>::handle & ref, SCENENODE & topnode, float r, float g, float b)
{
	if (!ref.valid())
	{
		ref = topnode.GetDrawlist().normal_noblend.insert(DRAWABLE());
		DRAWABLE & d = topnode.GetDrawlist().normal_noblend.get(ref);
		d.SetColor(r,g,b,1);
		d.SetDecal(true);
	}
}
Ejemplo n.º 4
0
static keyed_container <DRAWABLE>::handle SetupText(
	SCENENODE & parent, FONT & font,
	TEXT_DRAW & textdraw, const std::string & str,
	float x, float y, float scalex, float scaley,
	float r, float g , float b, float zorder = 0)
{
	keyed_container<DRAWABLE>::handle draw = parent.GetDrawlist().text.insert(DRAWABLE());
	DRAWABLE & drawref = parent.GetDrawlist().text.get(draw);
	textdraw.Set(drawref, font, str, x, y, scalex, scaley, r, g, b);
	drawref.SetDrawOrder(zorder);
	return draw;
}
Ejemplo n.º 5
0
void GUILABEL::SetupDrawable(
	SCENENODE & scene,
	const FONT & font,
	int align,
	float scalex, float scaley,
	float x, float y,
	float w, float h, float z)
{
	m_font = &font;
	m_x = x;
	m_y = y;
	m_w = w;
	m_h = h;
	m_scalex = scalex;
	m_scaley = scaley;
	m_align = align;

	m_draw = scene.GetDrawlist().text.insert(DRAWABLE());
	DRAWABLE & drawref = GetDrawable(scene);
	drawref.SetDrawOrder(z);

	float textw = 0;
	if (align == -1) x -= w * 0.5;
	else if (align == 0) x -= textw * 0.5;
	else if (align == 1) x -= (textw - w * 0.5);
	m_text_draw.Set(drawref, font, m_text, x, y, scalex, scaley, m_r, m_g, m_b);
}
Ejemplo n.º 6
0
void WIDGET_LABEL::SetupDrawable(
	SCENENODE & scene,
	const FONT & font,
	const std::string & text,
	float x, float y,
	float scalex, float scaley,
	float nr, float ng, float nb,
	float z, bool centered)
{
	savedfont = &font;
	r = nr;
	b = nb;
	g = ng;
	saved_x = x;
	saved_y = y;
	saved_scalex = scalex;
	saved_scaley = scaley;
	saved_centered = centered;

	draw = scene.GetDrawlist().text.insert(DRAWABLE());
	DRAWABLE & drawref = GetDrawable(scene);
	drawref.SetDrawOrder(z);

	if (centered) x = x - savedfont->GetWidth(text) * saved_scalex * 0.5;
	text_draw.Set(drawref, font, text, x, y, scalex, scaley, r, g, b);
}
Ejemplo n.º 7
0
static void EraseTextDrawable(SCENENODE & node, keyed_container<DRAWABLE>::handle & drawhandle)
{
	if (drawhandle.valid())
	{
		node.GetDrawlist().twodim.erase(drawhandle);
		drawhandle.invalidate();
	}
}
Ejemplo n.º 8
0
void HUDBAR::Set(
	SCENENODE & parent,
	std::tr1::shared_ptr<TEXTURE> bartex,
	float x, float y, float w, float h,
	float opacity,
	bool flip)
{
	draw = parent.GetDrawlist().twodim.insert(DRAWABLE());
	DRAWABLE & drawref = parent.GetDrawlist().twodim.get(draw);

	drawref.SetDiffuseMap(bartex);
	drawref.SetVertArray(&verts);
	drawref.SetCull(false, false);
	drawref.SetColor(1,1,1,opacity);
	drawref.SetDrawOrder(1);

	verts.SetTo2DButton(x, y, w, h, h*0.75, flip);
}
Ejemplo n.º 9
0
void SPRITE2D::Unload(SCENENODE & parent)
{
	if (node.valid())
	{
		SCENENODE & noderef = GetNode(parent);
		noderef.GetDrawlist().twodim.erase(draw);
		parent.Delete(node);
	}
	node.invalidate();
	draw.invalidate();

	varray.Clear();
}
Ejemplo n.º 10
0
bool SPRITE2D::Load(
	SCENENODE & parent,
	std::tr1::shared_ptr<TEXTURE> texture2d,
	float draworder)
{
	Unload(parent);

	assert(!draw.valid());
	assert(!node.valid());

	node = parent.AddNode();
	SCENENODE & noderef = parent.GetNode(node);
	draw = noderef.GetDrawlist().twodim.insert(DRAWABLE());
	DRAWABLE & drawref = GetDrawableFromNode(noderef);

	drawref.SetDiffuseMap(texture2d);
	drawref.SetVertArray(&varray);
	drawref.SetDrawOrder(draworder);
	drawref.SetCull(false, false);
	drawref.SetColor(r,g,b,a);

	return true;
}
Ejemplo n.º 11
0
void GUIIMAGE::SetupDrawable(
	SCENENODE & scene,
	ContentManager & content,
	const std::string & imagepath,
	float x, float y, float w, float h, float z)
{
	m_content = &content;
	m_imagepath = imagepath;
	m_varray.SetToBillboard(x - w * 0.5f, y - h * 0.5f, x + w * 0.5f, y + h * 0.5f);

	m_draw = scene.GetDrawlist().twodim.insert(DRAWABLE());
	DRAWABLE & drawref = GetDrawable(scene);
	drawref.SetVertArray(&m_varray);
	drawref.SetCull(false, false);
	drawref.SetDrawOrder(z);
}
Ejemplo n.º 12
0
static keyed_container<DRAWABLE>::handle AddDrawable(SCENENODE & node)
{
	return node.GetDrawlist().twodim.insert(DRAWABLE());
}
Ejemplo n.º 13
0
static bool LoadWheel(
	const PTree & cfg_wheel,
	struct LoadDrawable & loadDrawable,
	SCENENODE & topnode,
	std::ostream & error_output)
{
	keyed_container<SCENENODE>::handle wheelnode = topnode.AddNode();
	ContentManager & content = loadDrawable.content;
	const std::string& path = loadDrawable.path;

	std::string meshname;
	std::vector<std::string> texname;
	if (!cfg_wheel.get("mesh", meshname, error_output)) return false;
	if (!cfg_wheel.get("texture", texname, error_output)) return false;

	std::string tiredim;
	const PTree * cfg_tire;
	if (!cfg_wheel.get("tire", cfg_tire, error_output)) return false;
	if (!cfg_tire->get("size", tiredim, error_output)) return false;

	MATHVECTOR<float, 3> size(0);
	cfg_tire->get("size", size);
	float width = size[0] * 0.001;
	float diameter = size[2] * 0.0254;

	// get wheel disk mesh
	std::tr1::shared_ptr<MODEL> mesh;
	if (!content.load(path, meshname, mesh)) return false;

	// gen wheel mesh
	if (!content.get(path, meshname+tiredim, mesh))
	{
		VERTEXARRAY rimva, diskva;
		MESHGEN::mg_rim(rimva, size[0], size[1], size[2], 10);
		diskva = mesh->GetVertexArray();
		diskva.Translate(-0.75 * 0.5, 0, 0);
		diskva.Scale(width, diameter, diameter);
		content.load(path, meshname+tiredim, rimva + diskva, mesh);
	}

	// load wheel
	if (!loadDrawable(meshname+tiredim, texname, cfg_wheel, topnode, &wheelnode))
	{
		return false;
	}

	// tire (optional)
	texname.clear();
	if (!cfg_tire->get("texture", texname, error_output)) return true;

	// gen tire mesh
	if (!content.get(path, "tire"+tiredim, mesh))
	{
		VERTEXARRAY tireva;
		MESHGEN::mg_tire(tireva, size[0], size[1], size[2]);
		content.load(path, "tire"+tiredim, tireva, mesh);
	}

	// load tire
	if (!loadDrawable("tire"+tiredim, texname, *cfg_tire, topnode.GetNode(wheelnode)))
	{
		return false;
	}

	// brake (optional)
	texname.clear();
	std::string brakename;
	const PTree * cfg_brake;
	if (!cfg_wheel.get("brake", cfg_brake, error_output)) return true;
	if (!cfg_brake->get("texture", texname)) return true;

	float radius;
	std::string radiusstr;
	cfg_brake->get("radius", radius);
	cfg_brake->get("radius", radiusstr);

	// gen brake disk mesh
	if (!content.get(path, "brake"+radiusstr, mesh))
	{
		float diameter_mm = radius * 2 * 1000;
		float thickness_mm = 0.025 * 1000;
		VERTEXARRAY brakeva;
		MESHGEN::mg_brake_rotor(brakeva, diameter_mm, thickness_mm);
		content.load(path, "brake"+radiusstr, brakeva, mesh);
	}

	// load brake disk
	if (!loadDrawable("brake"+radiusstr, texname, *cfg_brake, topnode.GetNode(wheelnode)))
	{
		return false;
	}

	return true;
}
Ejemplo n.º 14
0
void HUDBAR::SetVisible(SCENENODE & parent, bool newvis)
{
	DRAWABLE & drawref = parent.GetDrawlist().twodim.get(draw);
	drawref.SetDrawEnable(newvis);
}
Ejemplo n.º 15
0
inline void Erase(SCENENODE & node, keyed_container <DRAWABLE>::handle & drawhandle)
{
	if (drawhandle.valid()) node.GetDrawlist().twodim.erase(drawhandle);
}
Ejemplo n.º 16
0
void ROADPATCH::AddRacinglineScenenode(
	SCENENODE & node,
	const ROADPATCH & nextpatch,
	std::tr1::shared_ptr<TEXTURE> racingline_texture)
{
	//Create racing line scenenode
	keyed_container <DRAWABLE>::handle drawhandle = node.GetDrawlist().normal_blend.insert(DRAWABLE());
	DRAWABLE & draw = node.GetDrawlist().normal_blend.get(drawhandle);

	draw.SetDiffuseMap(racingline_texture);
	draw.SetDecal(true);
	draw.SetVertArray(&racingline_vertexarray);

	MATHVECTOR <float, 3> v0 = racing_line + (patch.GetPoint(0,0) - racing_line).Normalize()*0.1;
	MATHVECTOR <float, 3> v1 = racing_line + (patch.GetPoint(0,3) - racing_line).Normalize()*0.1;
	MATHVECTOR <float, 3> v2 = nextpatch.racing_line + (nextpatch.GetPatch().GetPoint(0,3) - nextpatch.racing_line).Normalize()*0.1;
	MATHVECTOR <float, 3> v3 = nextpatch.racing_line + (nextpatch.GetPatch().GetPoint(0,0) - nextpatch.racing_line).Normalize()*0.1;

	//transform from bezier space into world space
	v0.Set(v0[2],v0[0],v0[1]);
	v1.Set(v1[2],v1[0],v1[1]);
	v2.Set(v2[2],v2[0],v2[1]);
	v3.Set(v3[2],v3[0],v3[1]);

	float trackoffset = 0.1;
	v0[2] += trackoffset;
	v1[2] += trackoffset;
	v2[2] += trackoffset;
	v3[2] += trackoffset;

	float vcorners[12];
	float uvs[8];
	int bfaces[6];

	//std::cout << v0 << std::endl;

	vcorners[0] = v0[0]; vcorners[1] = v0[1]; vcorners[2] = v0[2];
	vcorners[3] = v1[0]; vcorners[4] = v1[1]; vcorners[5] = v1[2];
	vcorners[6] = v2[0]; vcorners[7] = v2[1]; vcorners[8] = v2[2];
	vcorners[9] = v3[0]; vcorners[10] = v3[1]; vcorners[11] = v3[2];

	//std::cout << v0 << endl;
	//std::cout << racing_line << endl;

	uvs[0] = 0;
	uvs[1] = 0;
	uvs[2] = 1;
	uvs[3] = 0;
	uvs[4] = 1;
	uvs[5] = (v2-v1).Magnitude();
	uvs[6] = 0;
	uvs[7] = (v2-v1).Magnitude();

	bfaces[0] = 0;
	bfaces[1] = 2;
	bfaces[2] = 1;
	bfaces[3] = 0;
	bfaces[4] = 3;
	bfaces[5] = 2;

	racingline_vertexarray.SetFaces(bfaces, 6);
	racingline_vertexarray.SetVertices(vcorners, 12);
	racingline_vertexarray.SetTexCoordSets(1);
	racingline_vertexarray.SetTexCoords(0, uvs, 8);
}