コード例 #1
0
ファイル: mappreview.cpp プロジェクト: borgified/Allegiance
	// this render the map preview like the in game minimap (mostly it's the same code)
	void RealRender(Context* pcontext)
    {

		// copied from CmissionIGC::UpdateSides .. this should be a global , one day, may be ;)
		static const float sideColors[c_cSidesMax][3] =
                            { {188.0f/255.0f, 160.0f/255.0f,   0.0f/255.0f}, //Gold
                              {  0.0f/255.0f, 138.0f/255.0f, 217.0f/255.0f}, //Blue
                              {156.0f/255.0f,  16.0f/255.0f, 102.0f/255.0f}, //Purple
                              { 50.0f/255.0f, 140.0f/255.0f,  20.0f/255.0f}, //icky yellow
                              {255.0f/255.0f, 145.0f/255.0f, 145.0f/255.0f}, //icky orange
                              { 50.0f/255.0f, 200.0f/255.0f, 125.0f/255.0f}};//icky magenta

		// draw the minimap background
        pcontext->SetShadeMode(ShadeModeFlat);
		pcontext->SetBlendMode(BlendModeSourceAlpha); //imago 7/17/09
		pcontext->DrawImage(m_pimageSectorBkgnd->GetSurface());

		if (m_missionpv.GetClusters()->n() == 0) return; // no cluster so no map preview

		Rect rectClip = m_bounds.GetRect();
		rectClip.Expand(-1);
		pcontext->Clip(rectClip);
		CalculateScreenMinAndMax();


		// draw all the connecting lines for warps
		{
			const WarpPVList* warps =  m_missionpv.GetWarps();
			TVector<VertexL>    vertices(warps->n(), 0);
			TVector<WORD>       indices(warps->n(), 0);

			for (WarpPVLink* warpLink = warps->first(); warpLink != NULL; warpLink = warpLink->next())
			{
				CwarpPV* pWarp = warpLink->data();
				CwarpPV* pwarpDestination = pWarp->GetDestination();
				assert (pwarpDestination != NULL);
				if (pWarp->GetObjectID() > pwarpDestination->GetObjectID())
				{
					Color colorWarp = 0.5f * Color::White(); // upped from 0.5f to 0.7f //imago put back to match sectormap.cpp 7/17/09
					WinPoint point1 = GetClusterPoint(pWarp->GetCluster());
					WinPoint point2 = GetClusterPoint(pwarpDestination->GetCluster());

					indices.PushEnd(vertices.GetCount());
					vertices.PushEnd(VertexL(Vector(point1.x, point1.y, 0), colorWarp));
					indices.PushEnd(vertices.GetCount());
					vertices.PushEnd(VertexL(Vector(point2.x, point2.y, 0), colorWarp));
				}
			}
            
			if (vertices.GetCount() != 0)
			{
				pcontext->SetLineWidth(1.0f);
				pcontext->DrawLines(vertices, indices);
			}
		}

		// draw the data for each sector
		const ClusterPVList* clusters = m_missionpv.GetClusters();
		for (ClusterPVLink* cLink = clusters->first(); cLink != NULL; cLink = cLink->next())
		{
			CMapPVCluster* pCluster = cLink->data();
			//if (pCluster->GetModels()->n() != 0)
			{
				Point    xy = Point::Cast(GetClusterPoint(pCluster));

				// draw the sector outline
				pcontext->DrawImage3D(m_pimageSectorEmpty->GetSurface(), Color::White(), true, xy);

				// color it by the owner(s), if any
				SideID sideOwner;
				SideID sideSecondaryOwner;
				GetClusterOwners(pCluster, sideOwner, sideSecondaryOwner);
				
				// highlight it if it is ours
				if (m_bShowSide)
                if (trekClient.GetSideID() >= 0 && sideOwner >= 0)
				{
					if (sideOwner == trekClient.GetSideID())
						pcontext->DrawImage3D(m_pimageSectorHighlight->GetSurface(), Color::White(), true, xy);
				}
				if (sideOwner != NA)
				{
					Color color;
					color.SetRGBA(sideColors[sideOwner][0], sideColors[sideOwner][1], sideColors[sideOwner][2]);
					pcontext->DrawImage3D(
						m_pimageOwnerHighlight->GetSurface(), 
						color,
						true, 
						xy
					);
				}
			    if (sideSecondaryOwner != NA)
				{
					Color color;
					color.SetRGBA(sideColors[sideSecondaryOwner][0], sideColors[sideSecondaryOwner][1], sideColors[sideSecondaryOwner][2]);
					pcontext->DrawImage3D(
						m_pimageSecondaryOwnerHighlight->GetSurface(), 
						color,
						true, 
						xy
					);
				}
			}
		}
    }
コード例 #2
0
void GadgetBeamWeapon::render( RenderContext &context, 
					const Matrix33 & frame, 
					const Vector3 & position )
{
	NounGadget::render( context, frame, position );

	// render the beam
	if ( useActive() && m_Target.valid() && m_Duration > 0 )
	{
		Vector3 positionVS( context.worldToView( position ) );
		float fLength = length() * calculateModifier( MT_BEAM_RANGE );
		if (! context.sphereVisible( positionVS, fLength ) )
			return;

		Noun * pTarget = m_Target;
		Vector3 position2( pTarget->worldPosition() );			
		
		if ( ( ( position2 - worldPosition() ).magnitude() - pTarget->radius() ) > fLength )
			return;		
		
		if ( !checkFacing( position2 ) )
			return;

		int tailAlpha = 32;

		if ( m_Hit.valid() )
			tailAlpha = 128;

		Vector3 direction( pTarget->worldPosition() - position );
		Vector3 head( position );
		Vector3 tail( head + direction );

		// calculate the material wrap
		float h = 0.05f;
		float w = 10.0f;

		Material * pTracerMaterial = tracerMaterial();
		if ( pTracerMaterial != NULL )
		{
			h = pTracerMaterial->height();
			w = pTracerMaterial->width();
			Material::push( context, pTracerMaterial );
		}
		else
			Material::push( context, Color(255,0,0), true, PrimitiveMaterial::ADDITIVE );

		float u = (head - tail).magnitude() / w;

		const Vector3	N( 0,0, 0);
		const Vector3	Y( 0, h, 0 );
		const Vector3	X( h, 0, 0 );
		const Color		HC( 255,255,255,255 );
		const Color		TC( 255,255,255,tailAlpha );

		VertexL beamY[4] = 
		{
			VertexL( head + Y, N, HC, u, 0.0f ),
			VertexL( tail + Y, N, TC, 0.0f, 0.0f ),
			VertexL( tail - Y, N, TC, 0.0f, 1.0f ),
			VertexL( head - Y, N, HC, u, 1.0f ),
		};
		VertexL beamX[4] = 
		{
			VertexL( head + X, N, HC, u, 0.0f ),
			VertexL( tail + X, N, TC, 0.0f, 0.0f ),
			VertexL( tail - X, N, TC, 0.0f, 1.0f ),
			VertexL( head - X, N, HC, u, 1.0f ),
		};
		
		DisplayDevice * pDisplay = context.device();
		ASSERT( pDisplay );

		context.pushIdentity();
		PrimitiveTriangleFanDL::push( pDisplay, 4, beamY );
		PrimitiveTriangleFanDL::push( pDisplay, 4, beamX );
	}
}