예제 #1
0
bool LoadDrawable::operator()(
	const std::string & meshname,
	const std::vector<std::string> & texname,
	const PTree & cfg,
	SCENENODE & topnode,
	keyed_container<SCENENODE>::handle * nodeptr,
	keyed_container<DRAWABLE>::handle * drawptr)
{
	DRAWABLE drawable;

	// set textures
	TEXTUREINFO texinfo;
	texinfo.mipmap = true;
	texinfo.anisotropy = anisotropy;
	std::tr1::shared_ptr<TEXTURE> tex;
	if (texname.size() == 0)
	{
		error << "No texture defined" << std::endl;
		return false;
	}
	if (texname.size() > 0)
	{
		if (!content.load(path, texname[0], texinfo, tex)) return false;
		drawable.SetDiffuseMap(tex);
	}
	if (texname.size() > 1)
	{
		if (!content.load(path, texname[1], texinfo, tex)) return false;
		drawable.SetMiscMap1(tex);
	}
	if (texname.size() > 2)
	{
		if (!content.load(path, texname[2], texinfo, tex)) return false;
		drawable.SetMiscMap2(tex);
	}

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

	std::string scalestr;
	if (cfg.get("scale", scalestr) &&
		!content.get(path, meshname + scalestr, mesh))
	{
		MATHVECTOR<float, 3> scale;
		std::stringstream s(scalestr);
		s >> scale;

		VERTEXARRAY meshva = mesh->GetVertexArray();
		meshva.Scale(scale[0], scale[1], scale[2]);
		content.load(path, meshname + scalestr, meshva, mesh);
	}
void AI_Car_Experimental::AddLinePoint(VERTEXARRAY & va, const MATHVECTOR<float, 3> & p)
{
	int vsize;
	const float* vbase;
	va.GetVertices(vbase, vsize);

	if (vsize == 0)
	{
		int vcount = 3;
		float verts[3] = {p[0], p[1], p[2]};
		va.SetVertices(verts, vcount, vsize);
	}
	else
	{
		int vcount = 6;
		float verts[6] = {p[0], p[1], p[2], p[0], p[1], p[2]};
		va.SetVertices(verts, vcount, vsize);
	}
}
예제 #3
0
파일: car.cpp 프로젝트: newleon/vdrift
bool CAR::LoadLight(
	const PTree & cfg,
	ContentManager & content,
	std::ostream & error_output)
{
	float radius;
	std::string radiusstr;
	MATHVECTOR<float, 3> pos(0), col(0);
	if (!cfg.get("position", pos, error_output)) return false;
	if (!cfg.get("color", col, error_output)) return false;
	if (!cfg.get("radius", radius, error_output)) return false;
	cfg.get("radius", radiusstr);

	lights.push_back(LIGHT());

	SCENENODE & bodynoderef = topnode.GetNode(bodynode);
	lights.back().node = bodynoderef.AddNode();

	SCENENODE & node = bodynoderef.GetNode(lights.back().node);
	node.GetTransform().SetTranslation(MATHVECTOR<float,3>(pos[0], pos[1], pos[2]));

	std::tr1::shared_ptr<MODEL> mesh;
	if (!content.get("", "cube"+radiusstr, mesh))
	{
		VERTEXARRAY varray;
		varray.SetToUnitCube();
		varray.Scale(radius, radius, radius);
		content.load("", "cube"+radiusstr, varray, mesh);
	}
    models.push_back(mesh);

	keyed_container <DRAWABLE> & dlist = GetDrawlist(node, OMNI);
	lights.back().draw = dlist.insert(DRAWABLE());

	DRAWABLE & draw = dlist.get(lights.back().draw);
	draw.SetColor(col[0], col[1], col[2]);
	draw.SetModel(*mesh);
	draw.SetCull(true, true);
	draw.SetDrawEnable(false);

	return true;
}
예제 #4
0
float TEXT_DRAW::RenderText(
	const FONT & font, const std::string & text,
	float x, float y, float scalex, float scaley,
	VERTEXARRAY & output_array)
{
	output_array.Clear();
	float cursorx = x;
	float cursory = y  + scaley / 4;
	for (unsigned int i = 0; i < text.size(); ++i)
	{
		if (text[i] == '\n')
		{
			cursorx = x;
			cursory += scaley;
		}
		else
		{
			cursorx += RenderCharacter(font, text[i], cursorx, cursory, scalex, scaley, output_array);
		}
	}
	return cursorx;
}
예제 #5
0
float TEXT_DRAW::RenderCharacter(
	const FONT & font, char c,
	float x, float y, float scalex, float scaley,
	VERTEXARRAY & output_array)
{
	const FONT::CHARINFO * ci = 0;
	if (!font.GetCharInfo(c, ci)) return 0;

	float invsize = font.GetInvSize();
	float x1 = x + ci->xoffset * invsize * scalex;
	float x2 = x1 + ci->width * invsize * scalex;
	float y1 = y - ci->yoffset * invsize * scaley;
	float y2 = y1 + ci->height * invsize * scaley;

	float u1 = ci->x;
	float u2 = u1 + ci->width;
	float v1 = ci->y;
	float v2 = v1 + ci->height;

	float v[] = {x1, y1, 0, x2, y1, 0, x2, y2, 0, x1, y2, 0};
	float t[] = {u1, v1, u2, v1, u2, v2, u1, v2};
	unsigned f[] = {0, 1, 2, 0, 2, 3};

	if (output_array.GetTexCoordSets() == 0)
	{
		output_array.SetFaces(f, 6);
		output_array.SetVertices(v, 12);
		output_array.SetTexCoordSets(1);
		output_array.SetTexCoords(0, t, 8);
	}
	else
	{
		float * n = 0;
		output_array.Add(n, 0, v, 12, f, 6, t, 8);
	}

	return ci->xadvance * invsize * scalex;
}
예제 #6
0
파일: hudgauge.cpp 프로젝트: Bengt/vdrift
void HUDGAUGE::Set(
	SCENENODE & parent,
	const FONT & font,
	const std::string & name,
	float hwratio,
	float centerx,
	float centery,
	float radius,
	float startangle,
	float endangle,
	float startvalue,
	float endvalue,
	float valuedelta)
{
	// calculate number of segments (max 9)
	float segments = (endvalue - startvalue) / valuedelta;
	float factor = ceil(segments / 9.0f);
	segments = ceil(segments / factor);
	valuedelta = valuedelta * factor;
	endvalue = startvalue + segments * valuedelta;

	this->centerx = centerx;
	this->centery = centery;
	this->scalex = radius * hwratio;
	this->scaley = radius;
	this->offset = startangle;
	this->scale = (endangle - startangle) / (endvalue - startvalue);

	// reset
	Erase(parent, pointer_draw);
	Erase(parent, dialnum_draw);
	Erase(parent, dial_draw);
	pointer_rotated.Clear();
	pointer.Clear();
	dial_label.Clear();
	dial_marks.Clear();

	// dial marks
	{
		// big marker
		float pb[] = {-0.02, 1, 0, 0.02, 1, 0, 0.02, 0.92, 0, -0.02, 0.92, 0};
		float t[] = {0, 0, 1, 0, 1, 1, 0, 1};
		int f[] = {0, 2, 1, 0, 3, 2};
		VERTEXARRAY bm;
		bm.SetVertices(pb, 12);
		bm.SetTexCoordSets(1);
		bm.SetTexCoords(0, t, 8);
		bm.SetFaces(f, 6);

		// small marker
		float ps[] = {-0.01, 1, 0, 0.01, 1, 0, 0.01, 0.95, 0, -0.01, 0.95, 0};
		VERTEXARRAY sm;
		sm.SetVertices(ps, 12);
		sm.SetTexCoordSets(1);
		sm.SetTexCoords(0, t, 8);
		sm.SetFaces(f, 6);

		float delta = (endangle - startangle) / (3 * segments);
		float angle = startangle;
		for (int i = 0; i <= 3 * segments; ++i)
		{
			VERTEXARRAY temp = (i % 3) ? sm : bm;
			temp.Rotate(angle, 0, 0, -1);
			dial_marks = dial_marks + temp;
			angle = angle + delta;
		}
		dial_marks.Scale(radius * hwratio, radius, 1);
		dial_marks.Translate(centerx, centery, 0.0);

		dial_draw = AddDrawable(parent);
		DRAWABLE & drawref = GetDrawable(parent, dial_draw);
		drawref.SetVertArray(&dial_marks);
		drawref.SetCull(false, false);
		drawref.SetColor(1, 1, 1, 0.5);
		drawref.SetDrawOrder(1);
	}

	// dial label
	{
		VERTEXARRAY temp;
		float w = 0.25 * radius * hwratio;
		float h = 0.25 * radius;
		float x = centerx;
		float y = centery - 0.5 * radius;
		float xn = TEXT_DRAW::RenderText(font, name, x, y, w, h, temp);
		temp.Translate((x - xn) * 0.5, 0, 0);
		dial_label = dial_label + temp;

		float angle = startangle;
		float angle_delta = (endangle - startangle) / segments;
		float value = startvalue;
		float value_delta = (endvalue - startvalue) / segments;
		for (int i = 0; i <= segments; ++i)
		{
			std::stringstream sstr;
			std::string text;
			sstr << value;
			sstr >> text;
			x = centerx + 0.75 * sin(angle) * radius * hwratio;
			y = centery + 0.75 * cos(angle) * radius;
			xn = TEXT_DRAW::RenderText(font, text, x, y, w, h, temp);
			temp.Translate((x - xn) * 0.5, 0, 0);
			dial_label = dial_label + temp;
			angle += angle_delta;
			value += value_delta;
		}

		dialnum_draw = AddDrawable(parent);
		DRAWABLE & drawref = GetDrawable(parent, dialnum_draw);
		drawref.SetDiffuseMap(font.GetFontTexture());
		drawref.SetVertArray(&dial_label);
		drawref.SetCull(false, false);
		drawref.SetColor(1, 1, 1, 0.5);
		drawref.SetDrawOrder(1);
	}

	// pointer
	{
		float p[] = {-0.015, 0.92, 0, 0.015, 0.92, 0, 0.025, -0.1, 0, -0.025, -0.1, 0};
		float t[] = {0, 0, 1, 0, 1, 1, 0, 1};
		int f[] = {0, 2, 1, 0, 3, 2};
		pointer.SetVertices(p, 12);
		pointer.SetTexCoordSets(1);
		pointer.SetTexCoords(0, t, 8);
		pointer.SetFaces(f, 6);
/*		pointer.Scale(radius, radius, 1);

		pointer_node = parent.AddNode();
		SCENENODE & noderef = parent.GetNode(pointer_node);
		QUATERNION<float> rot(startangle, 0, 0, 1);
		MATHVECTOR<float,3> pos(centerx, centery, 0);
		noderef.GetTransform().SetRotation(rot);
		noderef.GetTransform().SetTranslation(pos);
*/
		pointer_draw = AddDrawable(parent);//noderef);
		DRAWABLE & drawref = GetDrawable(parent, pointer_draw);//noderef, pointer_draw);
		drawref.SetVertArray(&pointer_rotated);//pointer);
		drawref.SetCull(false, false);
		drawref.SetColor(1, 1, 1, 0.5);
		drawref.SetDrawOrder(2);
	}
}