コード例 #1
0
ファイル: SectorView.cpp プロジェクト: Luomu/pioneer
void SectorView::PutFactionLabels(const vector3f &origin)
{
    PROFILE_SCOPED()
    glDepthRange(0,1);
    Gui::Screen::EnterOrtho();
    for (std::set<Faction*>::iterator it = m_visibleFactions.begin(); it != m_visibleFactions.end(); ++it) {
        if ((*it)->hasHomeworld && m_hiddenFactions.find((*it)) == m_hiddenFactions.end()) {

            Sector::System sys = GetCached((*it)->homeworld)->m_systems[(*it)->homeworld.systemIndex];
            if ((m_pos*Sector::SIZE - sys.FullPosition()).Length() > (m_zoomClamped/FAR_THRESHOLD )*OUTER_RADIUS) continue;

            vector3d pos;
            if (Gui::Screen::Project(vector3d(sys.FullPosition() - origin), pos)) {

                std::string labelText    = sys.name + "\n" + (*it)->name;
                Color       labelColor  = (*it)->colour;
                float       labelHeight = 0;
                float       labelWidth  = 0;

                Gui::Screen::MeasureString(labelText, labelWidth, labelHeight);

                if (!m_material) m_material.Reset(m_renderer->CreateMaterial(Graphics::MaterialDescriptor()));

                {
                    Graphics::VertexArray va(Graphics::ATTRIB_POSITION);
                    va.Add(vector3f(pos.x - 5.f,              pos.y - 5.f,               0));
                    va.Add(vector3f(pos.x - 5.f,              pos.y - 5.f + labelHeight, 0));
                    va.Add(vector3f(pos.x + labelWidth + 5.f, pos.y - 5.f,               0));
                    va.Add(vector3f(pos.x + labelWidth + 5.f, pos.y - 5.f + labelHeight, 0));
                    m_material->diffuse = Color(13, 13, 31, 166);
                    m_renderer->DrawTriangles(&va, m_material.Get(), Graphics::TRIANGLE_STRIP);
                }

                {
                    Graphics::VertexArray va(Graphics::ATTRIB_POSITION);
                    va.Add(vector3f(pos.x - 8.f, pos.y,       0));
                    va.Add(vector3f(pos.x      , pos.y + 8.f, 0));
                    va.Add(vector3f(pos.x,       pos.y - 8.f, 0));
                    va.Add(vector3f(pos.x + 8.f, pos.y,       0));
                    m_material->diffuse = labelColor;
                    m_renderer->DrawTriangles(&va, m_material.Get(), Graphics::TRIANGLE_STRIP);
                }

                if (labelColor.GetLuminance() > 191) labelColor.a = 204;    // luminance is sometimes a bit overly
                m_clickableLabels->Add(labelText, sigc::bind(sigc::mem_fun(this, &SectorView::OnClickSystem), (*it)->homeworld), pos.x, pos.y, labelColor);
            }
        }
    }
    Gui::Screen::LeaveOrtho();
}
コード例 #2
0
ファイル: Factions.cpp プロジェクト: Mike-Cowley/pioneer
void FactionOctsapling::Add(Faction* faction)
{
	/*  The general principle here is to put the faction in every octbox cell that a system
	    that is a member of that faction could be in. This should let us cut the number
		of factions that have to be checked by GetNearestFaction, by eliminating right off
		all the those Factions that aren't in the same cell.

		As I'm just going for the quick performance win, I'm being very sloppy and
		treating a Faction as if it was a cube rather than a sphere. I'm also not even
		attempting to work out real faction boundaries for this.

		Obviously this all could be improved even without this Octsapling growing into
		a full Octree.

		This part happens at faction generation time so shouldn't be too performance
		critical
	*/
	Sector sec = Sector(faction->homeworld.sectorX, faction->homeworld.sectorY, faction->homeworld.sectorZ);

	/* only factions with homeworlds that are available at faction generation time can
	   be added to specific cells...
	*/
	if (faction->hasHomeworld && (faction->homeworld.systemIndex < sec.m_systems.size())) {
		/* calculate potential indexes for the octbox cells the faction needs to go into
		*/
		Sector::System sys = sec.m_systems[faction->homeworld.systemIndex];

		int xmin = BoxIndex(Sint32(sys.FullPosition().x - float((faction->Radius()))));
		int xmax = BoxIndex(Sint32(sys.FullPosition().x + float((faction->Radius()))));
		int ymin = BoxIndex(Sint32(sys.FullPosition().y - float((faction->Radius()))));
		int ymax = BoxIndex(Sint32(sys.FullPosition().y + float((faction->Radius()))));
		int zmin = BoxIndex(Sint32(sys.FullPosition().z - float((faction->Radius()))));
		int zmax = BoxIndex(Sint32(sys.FullPosition().z + float((faction->Radius()))));

		/* put the faction in all the octbox cells needed in a hideously inexact way that
		   will generate duplicates in each cell in many cases
		*/
		octbox[xmin][ymin][zmin].push_back(faction);  // 0,0,0
		octbox[xmax][ymin][zmin].push_back(faction);  // 1,0,0
		octbox[xmax][ymax][zmin].push_back(faction);  // 1,1,0
		octbox[xmax][ymax][zmax].push_back(faction);  // 1,1,1

		octbox[xmin][ymax][zmin].push_back(faction);  // 0,1,0
		octbox[xmin][ymax][zmax].push_back(faction);  // 0,1,1
		octbox[xmin][ymin][zmax].push_back(faction);  // 0,0,1
		octbox[xmax][ymin][zmax].push_back(faction);  // 1,0,1

		/* prune any duplicates from the octbox cells making things slightly saner
		*/
		PruneDuplicates(0,0,0);
		PruneDuplicates(1,0,0);
		PruneDuplicates(1,1,0);
		PruneDuplicates(1,1,1);

		PruneDuplicates(0,1,0);
		PruneDuplicates(0,1,1);
		PruneDuplicates(0,0,1);
		PruneDuplicates(1,0,1);

	} else {
	/* ...other factions, such as ones with no homeworlds, and more annoyingly ones
	   whose homeworlds don't exist yet because they're custom systems have to go in
	   *every* octbox cell
	*/
		octbox[0][0][0].push_back(faction);
		octbox[1][0][0].push_back(faction);
		octbox[1][1][0].push_back(faction);
		octbox[1][1][1].push_back(faction);

		octbox[0][1][0].push_back(faction);
		octbox[0][1][1].push_back(faction);
		octbox[0][0][1].push_back(faction);
		octbox[1][0][1].push_back(faction);
	}
}