コード例 #1
0
ファイル: view_radar.cpp プロジェクト: AzyxWare/ryzom
// ----------------------------------------------------------------------------
void CViewRadar::draw ()
{
	CInterfaceManager *pIM = CInterfaceManager::getInstance();
	CViewRenderer &rVR = pIM->getViewRenderer();

	CEntityCL *user = EntitiesMngr.entity(0);
	if (user == NULL) return;

	CVectorD xyzRef = user->pos();
	const CVector dir = user->front();

	float angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0));
	CMatrix mat;
	mat.identity();
	// Scale to transform from world to interface screen
	mat.scale( CVector((float)(_WReal / _WorldSize), (float)(_HReal / _WorldSize), 1) );
	// local to user
	mat.rotateZ(-angle);
	xyzRef.z = 0;
	mat.translate(-xyzRef);

	float	maxSqrRadius= (float)sqr(_WorldSize/2);

	for (sint32 i = 1; i < 256; ++i)
	{
		CEntityCL *entity = EntitiesMngr.entity(i);
		if (entity == NULL) continue;

		// if the entity must not be shown in radar
		if(!entity->getDisplayInRadar())
			continue;

		// get entity pos
		CVectorD xyz = entity->pos();

		xyz.z = 0;
		// if the distance is too big so do not display the entity
		if ((sqr(xyz.x - xyzRef.x)+sqr(xyz.y - xyzRef.y)) > maxSqrRadius) continue;

		// Transform the dot
		xyz = mat * xyz;

		// Convert to screen
		sint32 x = OptFastFloor((float)xyz.x);
		sint32 y = OptFastFloor((float)xyz.y);

		CRGBA col = entity->getColor();

		if(getModulateGlobalColor())
			col.modulateFromColor (col, pIM->getGlobalColorForContent());
		else
			col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColorForContent().A+1))>>8);

		// Select the icon to display and draw it
		uint spotId = CNPCIconCache::getInstance().getNPCIcon(entity).getSpotId();
		CRadarSpotDesc spotDesc = _SpotDescriptions[spotId];

		if (!_MissionIconsObs._displayMissionSpots)
			spotDesc = _SpotDescriptions[0];

		if (spotDesc.isMissionSpot)
			col = CRGBA(255, 255, 255, 255);

		if (entity->isTarget())
			spotId = 4; // to make it over other spots

		// Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range)
		if (spotDesc.isMissionSpot && _MiniMissionSpotsObs._displayMiniMissionSpots)
			rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.MTxW/2)+(_WReal/2), _YReal+y-(spotDesc.MTxH/2)+(_HReal/2),
								spotDesc.MTxW, spotDesc.MTxH, 0, false, spotDesc.MiniTextureId, col );
		else
			rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.TxW/2)+(_WReal/2), _YReal+y-(spotDesc.TxH/2)+(_HReal/2),
							spotDesc.TxW, spotDesc.TxH, 0, false, spotDesc.TextureId, col );
	}
}