コード例 #1
0
//! Fill with black around viewport disc shape.
static void drawViewportShape(StelRenderer* renderer, StelProjectorP projector)
{
	if (projector->getMaskType() != StelProjector::MaskDisk)
	{
		return;
	}

	renderer->setBlendMode(BlendMode_None);
	renderer->setGlobalColor(0.0f, 0.0f, 0.0f);

	const float innerRadius = 0.5 * projector->getViewportFovDiameter();
	const float outerRadius = projector->getViewportWidth() + projector->getViewportHeight();
	Q_ASSERT_X(innerRadius >= 0.0f && outerRadius > innerRadius,
	           Q_FUNC_INFO, "Inner radius must be at least zero and outer radius must be greater");

	const float sweepAngle = 360.0f;

	static const int resolution = 192;

	float sinCache[resolution];
	float cosCache[resolution];

	const float deltaRadius = outerRadius - innerRadius;
	const int slices = resolution - 1;
	// Cache is the vertex locations cache
	for (int s = 0; s <= slices; s++)
	{
		const float angle = (M_PI * sweepAngle) / 180.0f * s / slices;
		sinCache[s] = std::sin(angle);
		cosCache[s] = std::cos(angle);
	}
	sinCache[slices] = sinCache[0];
	cosCache[slices] = cosCache[0];

	const float radiusHigh = outerRadius - deltaRadius;

	StelVertexBuffer<VertexP2>* vertices = 
		renderer->createVertexBuffer<VertexP2>(PrimitiveType_TriangleStrip);

	const Vec2f center = projector->getViewportCenterAbsolute();
	for (int i = 0; i <= slices; i++)
	{
		vertices->addVertex(VertexP2(center[0] + outerRadius * sinCache[i],
		                             center[1] + outerRadius * cosCache[i]));
		vertices->addVertex(VertexP2(center[0] + radiusHigh * sinCache[i],
		                             center[1] + radiusHigh * cosCache[i]));
	}

	vertices->lock();
	renderer->setCulledFaces(CullFace_None);
	renderer->drawVertexBuffer(vertices);
	delete vertices;
}
コード例 #2
0
void StelQGLRenderer::drawTextGravityHelper
	(const TextParams& params, QPainter& painter, const int baseX, const int baseY, StelProjectorP projector)
{
	const Vec2f viewportCenter = projector->getViewportCenterAbsolute();

	const float dx = baseX - viewportCenter[0];
	const float dy = baseY - viewportCenter[1];
	const float d  = std::sqrt(dx * dx + dy * dy);
	
	// Cull the text if it's too far away to be visible in the screen.
	if (d > qMax(projector->getViewportXywh()[3], projector->getViewportXywh()[2]) * 2)
	{
		return;
	}

	const QString string  = params.string_;
	const int charCount   = string.length();
	const float charWidth = painter.fontMetrics().width(string) / charCount;
	float theta           = std::atan2(dy - 1, dx);
	const float psi       = qMin(5.0, std::atan2(charWidth, d + 1) * 180.0f / M_PI);
	const float xVc       = viewportCenter[0] + params.xShift_;
	const float yVc       = viewportCenter[1] + params.yShift_;
	const QString lang    = StelApp::getInstance().getLocaleMgr().getAppLanguage();

	const bool leftToRight = !QString("ar fa ur he yi ckb").contains(lang);
	// Draw each character separately
	for (int i = 0; i < charCount; ++i)
	{
		const int charIndex = leftToRight ? i : charCount - 1 - i;
		const float x       = d * std::cos(theta) + xVc;
		const float y       = d * std::sin(theta) + yVc;
		const float angle   = 90.0f + theta * 180.0f / M_PI;

		drawText(TextParams(x, y, string[charIndex]).angleDegrees(angle));
	
		// Compute how much the character contributes to the angle 
		const float width = painter.fontMetrics().width(string[charIndex]);
		theta += psi * M_PI / 180.0 * (1 + (width - charWidth) / charWidth);
	}
}