Esempio n. 1
0
void drawLoadingBitmap (float progress)
{
	if (!LoadingMaterial.empty() && !LoadingMaterialFull.empty())
	{
		Driver->setMatrixMode2D11();
		LoadingMaterialFull.setAlphaTestThreshold (1.f-progress);

		CQuadUV		quad;
		quad.V0.set (0,0,0);
		quad.V1.set (1,0,0);
		quad.V2.set (1,1,0);
		quad.V3.set (0,1,0);
		quad.Uv0.U= 0;
		quad.Uv0.V= 0.75f;
		quad.Uv1.U= 1;
		quad.Uv1.V= 0.75f;
		quad.Uv2.U= 1;
		quad.Uv2.V= 0;
		quad.Uv3.U= 0;
		quad.Uv3.V= 0;

		Driver->drawQuad(quad, LoadingMaterial);
		Driver->drawQuad(quad, LoadingMaterialFull);
	}
}
Esempio n. 2
0
void drawLoadingBitmap (float progress)
{
	if (!LoadingMaterial.empty() && !LoadingMaterialFull.empty())
	{
		Driver->setMatrixMode2D11();
		LoadingMaterialFull.setAlphaTestThreshold (1.f-progress);

		CQuadUV		quad;
		uint wh =  Driver->getWindowHeight();
		uint ww = Driver->getWindowWidth();
		float x1 = 0;
		float y1 = 0;
		float x2 = 1;
		float y2 = 1;

		if ((ww > 1024) || (wh > 768))
		{
			if ((ww - 1024) > (wh - 768))
				x1 = ((ww - (wh * 1024.f) / 768.f) / 2.f) / ww;
			else
				y1 = ((wh - (ww * 768.f) / 1024.f) / 2.f) / wh;
		}

		if (x1 != 0)
			x2 = 1 - x1;
		if (y1 != 0)
			y2 = 1 - y1;

		quad.V0.set (x1,y1,0);
		quad.V1.set (x2,y1,0);
		quad.V2.set (x2,y2,0);
		quad.V3.set (x1,y2,0);

		quad.Uv0.U= 0;
		quad.Uv0.V= 0.75f;
		quad.Uv1.U= 1;
		quad.Uv1.V= 0.75f;
		quad.Uv2.U= 1;
		quad.Uv2.V= 0;
		quad.Uv3.U= 0;
		quad.Uv3.V= 0;

		Driver->drawQuad(0, 0, 1, 1, CRGBA(0, 0, 0, 255));
		Driver->drawQuad(quad, LoadingMaterial);
		Driver->drawQuad(quad, LoadingMaterialFull);
	}
}
Esempio n. 3
0
void initCompass ()
{
	CompassMaterial = Driver->createMaterial ();
	CompassMaterial.initUnlit ();
	CompassMaterial.setBlendFunc (UMaterial::srcalpha, UMaterial::invsrcalpha);
	CompassMaterial.setBlend(true);

	ConfigFile->setCallback ("CompassPosX", cbUpdateCompass);
	ConfigFile->setCallback ("CompassPosY", cbUpdateCompass);
	ConfigFile->setCallback ("CompassRadius", cbUpdateCompass);
	ConfigFile->setCallback ("CompassColor", cbUpdateCompass);

	cbUpdateCompass (ConfigFile->getVar ("CompassPosX"));
	cbUpdateCompass (ConfigFile->getVar ("CompassPosY"));
	cbUpdateCompass (ConfigFile->getVar ("CompassRadius"));
	cbUpdateCompass (ConfigFile->getVar ("CompassColor"));
}
Esempio n. 4
0
// *************************************************************************************************
void setDiffuse(NL3D::UInstance instance, bool onOff, const NLMISC::CRGBA &color)
{
	if (instance.empty()) return;
	for(uint k = 0; k < instance.getNumMaterials(); ++k)
	{
		NL3D::UInstanceMaterial mat = instance.getMaterial(k);
		if (mat.isLighted())
		{
			CRGBA src;
			if (onOff)
			{
				src = mat.getDiffuse();
				src.R = color.R;
				src.G = color.G;
				src.B = color.B;
			}
			else
			{
				NL3D::UMaterial			matShape = instance.getShape().getMaterial(k);
				src = matShape.getDiffuse();
				src.A = mat.getDiffuse().A;
			}
			mat.setDiffuse(src);
		}
		else
		{
			CRGBA src;
			if (onOff)
			{
				src = mat.getColor();
				src.R = color.R;
				src.G = color.G;
				src.B = color.B;
			}
			else
			{
				NL3D::UMaterial			matShape = instance.getShape().getMaterial(k);
				src = matShape.getColor();
				src.A = mat.getColor().A;
			}
			mat.setColor(src);
		}
	}
}
Esempio n. 5
0
void cbUpdateCompass (CConfigFile::CVar &var)
{
	if (var.Name == "CompassPosX") CompassPosX = var.asFloat ();
	else if (var.Name == "CompassPosY") CompassPosY = var.asFloat ();
	else if (var.Name == "CompassRadius") CompassRadius = var.asFloat ();
	else if (var.Name == "CompassColor") 
	{
		CompassColor.set(var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
		CompassMaterial.setColor(CompassColor);
	}
	else nlwarning ("Unknown variable update %s", var.Name.c_str());
}
// *********************************************************************************************************
void CDisplayerVisualEntity::drawBBox(const NLMISC::CMatrix &modelMatrix, const NLMISC::CAABBox &bbox, NLMISC::CRGBA colOverZ, NLMISC::CRGBA colUnderZ)
{
	//H_AUTO(R2_CDisplayerVisualEntity_drawBBox)
	//nlwarning("bbox = (%f, %f, %f) - (%f, %f, %f), color = (%d, %d, %d, %d)", bbox.getMin().x, bbox.getMin().y, bbox.getMin().z,
	//												bbox.getMax().x, bbox.getMax().y, bbox.getMax().z, (int) colOverZ.R, (int) colOverZ.G, (int) colOverZ.B, (int) colOverZ.A);
	// for z-precision, work with camera at (0, 0, 0)
	static volatile bool fixMatrixPos = false;
	CMatrix oldViewMatrix = Driver->getViewMatrix();
	Driver->setModelMatrix(modelMatrix);
	CMatrix viewMat = oldViewMatrix;
	if (fixMatrixPos)
	{
		viewMat.setPos(CVector::Null);
	}
	Driver->setViewMatrix(viewMat);
	// draw below zbuffer
	UMaterial::ZFunc oldZfunc = GenericMat.getZFunc();
	bool oldZWrite = GenericMat.getZWrite();
	GenericMat.setZFunc(UMaterial::greater);
	GenericMat.setZWrite(false);
	::drawBox(bbox.getMin(),   bbox.getMax(), colUnderZ );
	GenericMat.setZFunc(oldZfunc);
	GenericMat.setZWrite(oldZWrite);
	::drawBox(bbox.getMin(),   bbox.getMax(), colOverZ);
	Driver->setViewMatrix(oldViewMatrix);
}
Esempio n. 7
0
namespace SBCLIENT {

//
// Variables
//

static NL3D::UMaterial CompassMaterial = NULL;

// These variables are automatically set with the config file

static	float	CompassPosX, CompassPosY, CompassRadius;
static	CRGBA	CompassColor;

//
// Functions
//

void cbUpdateCompass (CConfigFile::CVar &var)
{
	if (var.Name == "CompassPosX") CompassPosX = var.asFloat ();
	else if (var.Name == "CompassPosY") CompassPosY = var.asFloat ();
	else if (var.Name == "CompassRadius") CompassRadius = var.asFloat ();
	else if (var.Name == "CompassColor") 
	{
		CompassColor.set(var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
		CompassMaterial.setColor(CompassColor);
	}
	else nlwarning ("Unknown variable update %s", var.Name.c_str());
}

void initCompass ()
{
	CompassMaterial = Driver->createMaterial ();
	CompassMaterial.initUnlit ();
	CompassMaterial.setBlendFunc (UMaterial::srcalpha, UMaterial::invsrcalpha);
	CompassMaterial.setBlend(true);

	ConfigFile->setCallback ("CompassPosX", cbUpdateCompass);
	ConfigFile->setCallback ("CompassPosY", cbUpdateCompass);
	ConfigFile->setCallback ("CompassRadius", cbUpdateCompass);
	ConfigFile->setCallback ("CompassColor", cbUpdateCompass);

	cbUpdateCompass (ConfigFile->getVar ("CompassPosX"));
	cbUpdateCompass (ConfigFile->getVar ("CompassPosY"));
	cbUpdateCompass (ConfigFile->getVar ("CompassRadius"));
	cbUpdateCompass (ConfigFile->getVar ("CompassColor"));
}

void updateCompass ()
{
	float x = CompassPosX;
	float y = CompassPosY;
	float radius = CompassRadius;

	// tri
	CTriangle tri;
	tri.V0.set (-radius, 0, 0);
	tri.V1.set (radius, 0, 0);
	tri.V2.set (0, 3*radius, 0);

	CQuad quad;
	// quad
	quad.V0.set (-radius, -radius, 0);
	quad.V1.set ( radius, -radius, 0);
	quad.V2.set ( radius,  radius, 0);
	quad.V3.set (-radius,  radius, 0);

	Driver->setMatrixMode2D43 ();

	CMatrix mtx;

	// up
	mtx.identity();
	mtx.translate(CVector(x,y,0));
	mtx.rotateZ(MouseListener->getOrientation() - (float)Pi/2);
	mtx.translate(CVector(0,radius,0));
	Driver->setModelMatrix (mtx);
	Driver->drawTriangle (tri,  CompassMaterial);

	// down
	mtx.identity();
	mtx.translate(CVector(x,y,0));
	mtx.rotateZ(MouseListener->getOrientation() + (float)Pi/2);
	mtx.translate(CVector(0,radius,0));
	Driver->setModelMatrix (mtx);
	Driver->drawTriangle (tri,  CompassMaterial);

	// left
	mtx.identity();
	mtx.translate(CVector(x,y,0));
	mtx.rotateZ(MouseListener->getOrientation());
	mtx.translate(CVector(0,radius,0));
	Driver->setModelMatrix (mtx);
	Driver->drawTriangle (tri,  CompassMaterial);

	// right
	mtx.identity();
	mtx.translate(CVector(x,y,0));
	mtx.rotateZ(MouseListener->getOrientation() - (float)Pi);
	mtx.translate(CVector(0,radius,0));
	Driver->setModelMatrix (mtx);
	Driver->drawTriangle (tri,  CompassMaterial);

	// center
	mtx.identity();
	mtx.translate(CVector(x,y,0));
	mtx.rotateZ(MouseListener->getOrientation());
	Driver->setModelMatrix (mtx);
	Driver->drawQuad (quad,  CompassMaterial);

	x *= 3.0/4.0f;

	// Print position
	TextContext->setHotSpot(UTextContext::MiddleTop);
	TextContext->setColor(CompassColor);
	TextContext->setFontSize(14);
	if (Self != NULL)
		TextContext->printfAt(x, y-4.0f*radius, "%.2f %.2f %.2f", Self->Position.x, Self->Position.y, Self->Position.z);
	else
		TextContext->printfAt(x, y-4.0f*radius, "%.2f %.2f %.2f", MouseListener->getPosition().x, MouseListener->getPosition().y, MouseListener->getPosition().z);
}

void releaseCompass ()
{
	ConfigFile->setCallback("CompassPosX", NULL);
	ConfigFile->setCallback("CompassPosY", NULL);
	ConfigFile->setCallback("CompassRadius", NULL);
	ConfigFile->setCallback("CompassColor", NULL);

	Driver->deleteMaterial (CompassMaterial);
	CompassMaterial = NULL;
}

} /* namespace SBCLIENT */