Exemplo n.º 1
0
void main(){
	double x, y;
	int index;
	cout << "Please enter the section (1 or 2) you want " << endl;
	cin >> index;
	if (index == 1){
		Point pt;//constructor occurs here
		Point pt1;//constructor occurs here
		cout << "Please enter the value of x: " << endl;
		cin >> x;
		cout << "Please enter the value of y: " << endl;
		cin >> y;
		pt.X(x);
		pt.Y(y);
		cout << pt.ToString();
		cout << "Please enter the value of x: " << endl;
		cin >> x;
		cout << "Please enter the value of y: " << endl;
		cin >> y;
		pt1.X(x);
		pt1.Y(y);
		cout << pt1.ToString();
		cout << "The distance between point 1 to origin is " << pt.Distance() << endl;
		cout << "The distance between point 2 to point 1 is " << pt.Distance(pt1) << endl;
		/*the number of constructors (2) and deconstructors(2) are the same since we pass the point by reference*/
		//two deconstructors occurs here
	}
Exemplo n.º 2
0
void main(){
	double x, y;
	int index;
	cout << "Please enter the section (1 or 2) you want " << endl;
	cin >> index;
	if (index == 1){
		Point pt;//constructor occurs here
		Point pt1;//constructor occurs here
		cout << "Please enter the value of x: " << endl;
		cin >> x;
		cout << "Please enter the value of y: " << endl;
		cin >> y;
		pt.SetX(x);
		pt.SetY(y);
		cout << pt.ToString();
		cout << "Please enter the value of x: " << endl;
		cin >> x;
		cout << "Please enter the value of y: " << endl;
		cin >> y;
		pt1.SetX(x);
		pt1.SetY(y);
		cout << pt1.ToString();
		//one deconstructor occurs before printing
		cout << "The distance between point 2 to point 1 is " << pt.Distance(pt1) << endl;
		/*before  copy constructor added, the number of constructors (2) and deconstructors(3) are not the same */
		//two deconstructors occurs here
	}
Exemplo n.º 3
0
	double Distance(const Point &p1, const Point &p2,
			const bool &isSegment) const {
		double dist = ((p2 - p1) ^ (*this - p1)) / p2.Distance(p1);
		if (isSegment) {
			double dot1 = (*this - p2) * (p2 - p1);
			if (::cmp(dot1) > 0)
				return sqrt((p2 - *this) * (p2 - *this));
			double dot2 = (*this - p1) * (p1 - p2);
			if (::cmp(dot2) > 0)
				return sqrt((p1 - *this) * (p1 - *this));
		}
		return abs(dist);
	}
Exemplo n.º 4
0
bool MapPanel::Click(int x, int y)
{
	// Figure out if a system was clicked on.
	Point click = Point(x, y) - center;
	for(const auto &it : GameData::Systems())
		if(click.Distance(it.second.Position()) < 10.
				&& (player.HasSeen(&it.second) || &it.second == specialSystem))
		{
			Select(&it.second);
			break;
		}
	
	return true;
}
float IndexedTriangle::ComputeOcclusionPotential(const Point* verts, const Point& view)	const
{
	if(!verts)	return 0.0f;
	// Occlusion potential: -(A * (N|V) / d^2)
	// A = polygon area
	// N = polygon normal
	// V = view vector
	// d = distance viewpoint-center of polygon

	float A = Area(verts);
	Point N;	Normal(verts, N);
	Point C;	Center(verts, C);
	float d = view.Distance(C);
	return -(A*(N|view))/(d*d);
}
void main()
{
	using namespace std;

	const Point cp(1.5, 3.9);           //creates a constant Point variable called cp
	
	 cp.ToString();      // output onto screen the ToString() function of cp

     cout<<"The distance between this point and the origin is :"<<cp.Distance()<<endl;
	 //prints the distance of Point cp and origin onto screen
	 
	 
	 cout<<"For the source code cp.X(0.3):, the x coordinate is : "<<cp.X(0.3)<<endl;
	 //output the x-coordinate of cp as 0.3
	 system("PAUSE");


}
bool MissionPanel::Click(int x, int y)
{
	dragSide = 0;
	
	// Handle clicks on the interface buttons.
	{
		const Interface *interface = GameData::Interfaces().Get("mission");
		char key = interface->OnClick(Point(x, y));
		if(key)
			return DoKey(key);
	}
	{
		const Interface *interface = GameData::Interfaces().Get("map buttons");
		char key = interface->OnClick(Point(x, y));
		if(key)
			return DoKey(key);
	}
	
	if(x > Screen::Right() - 80 && y > Screen::Bottom() - 50)
		return DoKey('p');
	
	if(x < Screen::Left() + SIDE_WIDTH)
	{
		unsigned index = max(0, (y + static_cast<int>(availableScroll) - 36 - Screen::Top()) / 20);
		if(index < available.size())
		{
			availableIt = available.begin();
			while(index--)
				++availableIt;
			acceptedIt = accepted.end();
			dragSide = -1;
			selectedSystem = availableIt->Destination()->GetSystem();
			center = Point(0., -80.) - selectedSystem->Position();
			return true;
		}
	}
	else if(x >= Screen::Right() - SIDE_WIDTH)
	{
		int index = max(0, (y + static_cast<int>(acceptedScroll) - 36 - Screen::Top()) / 20);
		if(index < AcceptedVisible())
		{
			acceptedIt = accepted.begin();
			while(index || !acceptedIt->IsVisible())
			{
				index -= acceptedIt->IsVisible();
				++acceptedIt;
			}
			availableIt = available.end();
			dragSide = 1;
			selectedSystem = acceptedIt->Destination()->GetSystem();
			center = Point(0., -80.) - selectedSystem->Position();
			return true;
		}
	}
	
	// Figure out if a system was clicked on.
	Point click = Point(x, y) / Zoom() - center;
	const System *system = nullptr;
	for(const auto &it : GameData::Systems())
		if(click.Distance(it.second.Position()) < 10.
				&& (player.HasSeen(&it.second) || &it.second == specialSystem))
		{
			system = &it.second;
			break;
		}
	if(system)
	{
		Select(system);
		int options = available.size() + accepted.size();
		// If you just aborted your last mission, it is possible that neither
		// iterator is valid. In that case, start over from the beginning.
		if(availableIt == available.end() && acceptedIt == accepted.end())
		{
			if(!available.empty())
				availableIt = available.begin();
			else
				acceptedIt = accepted.begin();
		}
		while(options--)
		{
			if(availableIt != available.end())
			{
				++availableIt;
				if(availableIt == available.end())
				{
					if(!accepted.empty())
						acceptedIt = accepted.begin();
					else
						availableIt = available.begin();
				}
			}
			else if(acceptedIt != accepted.end())
			{
				++acceptedIt;
				if(acceptedIt == accepted.end())
				{
					if(!available.empty())
						availableIt = available.begin();
					else
						acceptedIt = accepted.begin();
				}
			}
			if(acceptedIt != accepted.end() && !acceptedIt->IsVisible())
				continue;
			
			if(availableIt != available.end() && availableIt->Destination()->GetSystem() == system)
				break;
			if(acceptedIt != accepted.end() && acceptedIt->Destination()->GetSystem() == system)
				break;
		}
	}
	
	return true;
}
Exemplo n.º 8
0
bool MapDetailPanel::Click(int x, int y)
{
	{
		const Interface *interface = GameData::Interfaces().Get("map buttons");
		char key = interface->OnClick(Point(x + 250, y));
		// In the mission panel, the "Done" button in the button bar should be
		// ignored (and is not shown).
		if(key)
			return DoKey(key);
	}
	if(x < Screen::Left() + 160)
	{
		if(y >= tradeY && y < tradeY + 200)
		{
			commodity = (y - tradeY) / 20;
			return true;
		}
		else if(y < governmentY)
			commodity = SHOW_REPUTATION;
		else if(y >= governmentY && y < governmentY + 20)
			commodity = SHOW_GOVERNMENT;
		else
		{
			for(const auto &it : planetY)
				if(y >= it.second && y < it.second + 110)
				{
					selectedPlanet = it.first;
					if(y >= it.second + 50 && y < it.second + 70)
					{
						if(commodity == SHOW_SHIPYARD && selectedPlanet->HasShipyard())
							ListShips();
						commodity = SHOW_SHIPYARD;
					}
					else if(y >= it.second + 70 && y < it.second + 90)
					{
						if(commodity == SHOW_OUTFITTER && selectedPlanet->HasOutfitter())
							ListOutfits();
						commodity = SHOW_OUTFITTER;
					}
					else if(y >= it.second + 90 && y < it.second + 110)
						commodity = SHOW_VISITED;
					return true;
				}
		}
	}
	else if(x >= Screen::Right() - 240 && y >= Screen::Bottom() - 240)
	{
		Point click = Point(x, y);
		selectedPlanet = nullptr;
		double distance = numeric_limits<double>::infinity();
		for(const auto &it : planets)
		{
			double d = click.Distance(it.second);
			if(d < distance)
			{
				distance = d;
				selectedPlanet = it.first;
			}
		}
		return true;
	}
	else if(y >= Screen::Bottom() - 40 && x >= Screen::Right() - 335 && x < Screen::Right() - 265)
	{
		// The user clicked the "done" button.
		return DoKey(SDLK_d);
	}
	else if(y >= Screen::Bottom() - 40 && x >= Screen::Right() - 415 && x < Screen::Right() - 345)
	{
		// The user clicked the "missions" button.
		return DoKey(SDLK_PAGEDOWN);
	}
	
	MapPanel::Click(x, y);
	if(selectedPlanet && selectedPlanet->GetSystem() != selectedSystem)
		selectedPlanet = nullptr;
	return true;
}
Exemplo n.º 9
0
bool MapDetailPanel::Click(int x, int y)
{
	if(x < Screen::Left() + 160)
	{
		if(y >= tradeY && y < tradeY + 200)
		{
			commodity = (y - tradeY) / 20;
			return true;
		}
		else if(y < governmentY)
			commodity = SHOW_REPUTATION;
		else if(y >= governmentY && y < governmentY + 20)
			commodity = SHOW_GOVERNMENT;
		else
		{
			for(const auto &it : planetY)
				if(y >= it.second && y < it.second + 110)
				{
					selectedPlanet = it.first;
					if(y >= it.second + 50 && y < it.second + 70)
					{
						if(commodity == SHOW_SHIPYARD && selectedPlanet->HasShipyard())
							ListShips();
						commodity = SHOW_SHIPYARD;
					}
					else if(y >= it.second + 70 && y < it.second + 90)
					{
						if(commodity == SHOW_OUTFITTER && selectedPlanet->HasOutfitter())
							ListOutfits();
						commodity = SHOW_OUTFITTER;
					}
					else if(y >= it.second + 90 && y < it.second + 110)
						commodity = SHOW_VISITED;
					return true;
				}
		}
	}
	else if(x >= Screen::Right() - 240 && y >= Screen::Top() + 280 && y <= Screen::Top() + 520)
	{
		Point click = Point(x, y);
		selectedPlanet = nullptr;
		double distance = numeric_limits<double>::infinity();
		for(const auto &it : planets)
		{
			double d = click.Distance(it.second);
			if(d < distance)
			{
				distance = d;
				selectedPlanet = it.first;
			}
		}
		return true;
	}
	else if(y >= Screen::Bottom() - 40 && x >= Screen::Right() - 335 && x < Screen::Right() - 265)
	{
		// The user clicked the "done" button.
		return DoKey(SDLK_d);
	}
	else if(y >= Screen::Bottom() - 40 && x >= Screen::Right() - 415 && x < Screen::Right() - 345)
	{
		// The user clicked the "missions" button.
		return DoKey(SDLK_PAGEDOWN);
	}
	
	MapPanel::Click(x, y);
	if(selectedPlanet && selectedPlanet->GetSystem() != selectedSystem)
		selectedPlanet = nullptr;
	return true;
}