Exemple #1
0
void CMapGridPainter::Paint (CG16bitImage &Dest, CMapViewportCtx &PaintCtx, const TArray<SLine> &Lines)

//	Paint
//
//	Paint the array of lines

	{
	int i;

	for (i = 0; i < Lines.GetCount(); i++)
		{
		int xFrom, yFrom;
		PaintCtx.Transform(Lines[i].vFrom, &xFrom, &yFrom);

		int xTo, yTo;
		PaintCtx.Transform(Lines[i].vTo, &xTo, &yTo);

		Dest.DrawLine(xFrom, yFrom, xTo, yTo, 1, RGB_GRID_LINE);
		}
	}
Exemple #2
0
void COrbit::Paint (CMapViewportCtx &Ctx, CG16bitImage &Dest, COLORREF rgbColor)

//	Paint
//
//	Paint the orbit

	{
	DWORD redValue = GetRValue(rgbColor);
	DWORD greenValue = GetGValue(rgbColor);
	DWORD blueValue = GetBValue(rgbColor);

	//	Paint circular orbits in a single color; eccentric orbits change color
	//	since they are not equidistant from the sun

	if (m_rEccentricity == 0.0)
		{
		Metric rAngle;
		const Metric rIncrement = g_Pi / 90.0;
		int xPrev, yPrev;
		WORD wColor;

		//	The orbit color fades depending on the distance from the sun

		Metric rFade = 0.25 + (LIGHT_SECOND * 180.0 / m_rSemiMajorAxis);
		if (rFade < 1.0)
			wColor = CG16bitImage::RGBValue((int)(redValue * rFade), (int)(greenValue * rFade), (int)(blueValue * rFade));
		else
			wColor = CG16bitImage::RGBValue((WORD)redValue, (WORD)greenValue, (WORD)blueValue);

		//	Compute the position of the starting point

		Ctx.Transform(GetPointCircular(0.0), &xPrev, &yPrev);

		//	Paint the orbit in multiple segments

		for (rAngle = rIncrement; rAngle < g_Pi * 2.0; rAngle += rIncrement)
			{
			//	Compute the end point

			int x, y;
			Ctx.Transform(GetPointCircular(rAngle), &x, &y);

			//	Draw a line segment

			Dest.DrawLine(xPrev, yPrev, x, y, 1, wColor);

			//	Next point

			xPrev = x;
			yPrev = y;
			}
		}
	else
		{
		Metric rAngle;
		const Metric rIncrement = g_Pi / 90.0;
		int xPrev, yPrev;

		//	Compute the position of the starting point

		Ctx.Transform(GetPoint(0.0), &xPrev, &yPrev);

		//	Paint the orbit in multiple segments

		for (rAngle = rIncrement; rAngle < g_Pi * 2.0; rAngle += rIncrement)
			{
			Metric rRadius;
			CVector vPos = GetPointAndRadius(rAngle, &rRadius);
			WORD wColor;

			//	Compute the end point

			int x, y;
			Ctx.Transform(vPos, &x, &y);

			//	The orbit color fades depending on the distance from the sun

			Metric rFade = 0.25 + (LIGHT_SECOND * 180.0 / rRadius);
			if (rFade < 1.0)
				wColor = CG16bitImage::RGBValue((int)(redValue * rFade), (int)(greenValue * rFade), (int)(blueValue * rFade));
			else
				wColor = CG16bitImage::RGBValue((WORD)redValue, (WORD)greenValue, (WORD)blueValue);

			//	Draw a line segment

			Dest.DrawLine(xPrev, yPrev, x, y, 1, wColor);

			//	Next point

			xPrev = x;
			yPrev = y;
			}
		}
	}
Exemple #3
0
void CEnvironmentGrid::PaintMap (CMapViewportCtx &Ctx, CG16bitImage &Dest)

//	PaintMap
//
//	Paint the environment on the map

	{
	int cxHalfTileCount = m_iTileCount / 2;
	int cyHalfTileCount = m_iTileCount / 2;

	//	Compute the size of each tile.

	int cxOrigin;
	int cyOrigin;
	Ctx.Transform(Ctx.GetCenterPos(), &cxOrigin, &cyOrigin);

	int cxTile;
	int cyTile;
	CVector vTile(m_iTileSize * g_KlicksPerPixel, m_iTileSize * g_KlicksPerPixel);
	Ctx.Transform(Ctx.GetCenterPos() + vTile, &cxTile, &cyTile);

	//	+1 because the floating-point conversion is sometimes off.

	cxTile = AlignUp(Absolute(cxTile - cxOrigin), 2) + 1;
	cyTile = AlignUp(Absolute(cyTile - cyOrigin), 2) + 1;

	int cxHalfTile = cxTile / 2;
	int cyHalfTile = cyTile / 2;

	//	Paint all tiles

	STileMapEnumerator k;
	while (HasMoreTiles(k))
		{
		//	Get the tile

		int xTile;
		int yTile;
		CSpaceEnvironmentType *pEnv;
		DWORD dwEdgeMask;

		GetNextTileType(k, &xTile, &yTile, &pEnv, &dwEdgeMask);
		if (pEnv == NULL)
			continue;

		//	Get the position of the tile

		CVector vPos = TileToVector(xTile, yTile);

		//	Fade out based on distance

		int iDist = Max(Absolute(xTile - cxHalfTileCount), Absolute(yTile - cyHalfTileCount));
		DWORD dwFade = (iDist > 5 ? Min(8 * (iDist - 5), 0xC0) : 0);

		//	Transform to map coords

		int x;
		int y;
		Ctx.Transform(vPos, &x, &y);

		//	Paint the tile

		pEnv->PaintMap(Dest, x, y, cxTile, cyTile, dwFade, dwEdgeMask);
		}
	}