コード例 #1
0
ファイル: Map.cpp プロジェクト: sp-alex-osou/Ants
void Map::draw(float elapsed)
{
	CL_Vec2<float> fieldSize;
	CL_Pointf p;

	CL_Rect viewport = window.get_viewport();
	
	fieldSize.x = (float)viewport.get_width() / size.width;
	fieldSize.y = (float)viewport.get_height() / size.height;

	for (int row = 0; row < size.height; row++)
		for (int col = 0; col < size.width; col++)
		{
			p = CL_Pointf(col * fieldSize.x, row * fieldSize.y) + fieldSize / 2;	

			if (row < size.height - 1)
			{
				CL_Colorf color(getEdge(CL_Point(col, row), CL_Point(col, row + 1)).pheromone / 10, 0, 0);
				CL_Draw::line(window.get_gc(), p, p + CL_Vec2<float>(0, fieldSize.y), color);
			}

			if (col < size.width - 1)
			{
				CL_Colorf color(getEdge(CL_Point(col, row), CL_Point(col + 1, row)).pheromone / 10, 0, 0);
				CL_Draw::line(window.get_gc(), p, p + CL_Vec2<float>(fieldSize.x, 0), color);
			}
		}

	p = CL_Pointf(start.x * fieldSize.x, start.y * fieldSize.y);
	CL_Draw::fill(window.get_gc(), p, p + fieldSize, CL_Colorf::red);

	p = CL_Pointf(target.x * fieldSize.x, target.y * fieldSize.y);
	CL_Draw::fill(window.get_gc(), p, p + fieldSize, CL_Colorf::green);
}
コード例 #2
0
void CL_PointSetMath::minimum_disc_with_3points(
	CL_Circlef &smalldisc,
	const std::vector<CL_Pointf> &points,
	unsigned int i,
	unsigned int j,
	unsigned int k)
{
	// There is only one circle with all three points on its boundary.

	// Find center:
	// http://astronomy.swin.edu.au/~pbourke/geometry/circlefrom3/
	// 
	CL_Pointf ji_mid  = CL_LineMath::midpoint(points[i],points[j]);
	CL_Pointf ji_norm = ji_mid + CL_Pointf(points[i].y - ji_mid.y, -(points[i].x - ji_mid.x));
	CL_Pointf ki_mid  = CL_LineMath::midpoint(points[k],points[i]);
	CL_Pointf ki_norm = ki_mid + CL_Pointf(points[k].y - ki_mid.y, -(points[k].x - ki_mid.x));

	CL_LineSegment2f line_segment_a( ji_mid, ji_norm );
	CL_LineSegment2f line_segment_b( ki_mid, ki_norm );

	bool did_intersect;
	smalldisc.position = line_segment_a.get_intersection( line_segment_b, did_intersect );

	// Since (i,j,k) are all on the circle, just get distance to one of them
	smalldisc.radius = smalldisc.position.distance(points[i]);
}
コード例 #3
0
ファイル: Graphics.cpp プロジェクト: ermachkov/Balance_GUI
void Graphics::setClipRect(float x1, float y1, float x2, float y2)
{
	// (0, 0) is the lower left corner, since we use our custom projection matrix, not ClanLib standard one
	CL_Point topLeft = virtualToScreen(CL_Pointf(x1, y1));
	CL_Point bottomRight = virtualToScreen(CL_Pointf(x2, y2));
	int height = mWindow.get_viewport().get_height();
	mWindow.get_gc().set_cliprect(CL_Rect(topLeft.x, height - bottomRight.y, bottomRight.x, height - topLeft.y));
}
コード例 #4
0
ファイル: EditorPoint.cpp プロジェクト: bercik/gear
	void EditorPoint::setDefaultPoints()
	{
		m_track.clear();

		m_track.addPoint(CL_Pointf(150.0f, 150.0f), DEFAULT_RADIUS, DEFAULT_SHIFT);
		m_track.addPoint(CL_Pointf(1200.0f, 120.0f), DEFAULT_RADIUS, DEFAULT_SHIFT);
		m_track.addPoint(CL_Pointf(1300.0f, 800.0f), DEFAULT_RADIUS, DEFAULT_SHIFT);
		m_track.addPoint(CL_Pointf(200.0f, 950.0f), DEFAULT_RADIUS, DEFAULT_SHIFT);

		m_gfxLevel.getTrackTriangulator().triangulate(m_track);
	}
コード例 #5
0
ファイル: Firework.cpp プロジェクト: sp-alex-osou/Firework
void Firework::draw(float elapsed)
{
	for (unsigned i = 0; i < particles.size(); ++i)
	{
		CL_Pointf position = scale(particles[i].getPosition());
		CL_Draw::fill(window.get_gc(), position, position - CL_Pointf(3, 3), CL_Colorf::white);
	}

	for (std::list<Line>::iterator it = lines.begin(); it != lines.end(); ++it)
		CL_Draw::line(window.get_gc(), CL_LineSegment2f(scale(it->line.p), scale(it->line.q)), CL_Colorf::white);

	CL_Draw::fill(window.get_gc(), scale(spring.position), scale(spring.position) - CL_Pointf(5, 5), CL_Colorf::red);
}
コード例 #6
0
WorkspaceMoveTool::WorkspaceMoveTool()
  : impl(new WorkspaceMoveToolImpl())
{
  impl->scrolling = false;
  impl->click_pos = CL_Point(0, 0);
  impl->old_trans_offset = CL_Pointf(0,0);
}
コード例 #7
0
ファイル: Sandpit.cpp プロジェクト: genail/gear
void Sandpit::build()
{
	CL_Rect bounds = calculateCircleBounds();

	setPosition(CL_Pointf(bounds.left, bounds.top));

	const float MAX_WIDTH = 512;
	const float MAX_HEIGHT = 512;

	// prepare image data
	const int width = bounds.get_width() + 1;
	const int height = bounds.get_height() + 1;

	assert(width <= MAX_WIDTH && width > 0);
	assert(height <= MAX_HEIGHT && height > 0);

	// prepare pixel data
	m_pixelData = CL_SharedPtr<CL_PixelBuffer>(new CL_PixelBuffer(width, height, width * 4, CL_PixelFormat::rgba8888));

	fillCircles(width, height, bounds);

	// unset the texture to create is at the next draw
	m_texture.disconnect();

	m_built = true;
}
コード例 #8
0
CL_Pointf CL_LineMath::get_intersection( float *lineA, float *lineB )
{
	const float &Ax = lineA[0];
	const float &Ay = lineA[1];
	const float &Bx = lineA[2];
	const float &By = lineA[3];

	const float &Cx = lineB[0];
	const float &Cy = lineB[1];
	const float &Dx = lineB[2];
	const float &Dy = lineB[3];

	float denominator = ((Bx-Ax)*(Dy-Cy)-(By-Ay)*(Dx-Cx));

	if( denominator == 0 )
		return CL_Pointf(Ax,Ay); 
	
	float r = ((Ay-Cy)*(Dx-Cx)-(Ax-Cx)*(Dy-Cy)) / denominator;
	
	CL_Pointf P;
	P.x=Ax+r*(Bx-Ax);
	P.y=Ay+r*(By-Ay);
	
	return P;
}
コード例 #9
0
CL_Circlef CL_PointSetMath::minimum_enclosing_disc( const std::vector<CL_Pointf> &points )
{
	CL_Circlef smalldisc;

	if(points.size() == 0)
	{
		// ERROR !!!!
		smalldisc.position = CL_Pointf(0.0, 0.0);
		smalldisc.radius = 0.0;
	}
	else if(points.size() == 1)
	{
		smalldisc.position = points[0];
		smalldisc.radius = 0.0;
	}
	else
	{
		int start = 0;
		int end = points.size() - 1;
		//TODO: random permutation of the vector...

		// Calculate the disc
		calculate_minimum_enclosing_disc(smalldisc, points, start, end);
	}

	return smalldisc;
}
コード例 #10
0
ファイル: MathUtils.cpp プロジェクト: SadSido/Tower
CL_Pointf getRandomVec(const Range &direction, const Range &amplitude)
{
	const float dir = direction.random();
	const float amp = amplitude.random();

	// it is more comfortable to have 90 degrees as "upwards":
	return CL_Pointf(cos(degToRad(dir)), -1.0f * sin(degToRad(dir))) * amp;
}
コード例 #11
0
ファイル: objmap_object.cpp プロジェクト: Flexlay/flexlay
CL_Pointf
ObjMapObject::get_pos() const
{
  if (impl.get())
    return impl->pos;
  else
    return CL_Pointf();
}
コード例 #12
0
ファイル: Car.cpp プロジェクト: genail/gear
void CarImpl::init()
{
	// build car contour for collision check
	CL_Contour contour;

	const int halfWidth = CAR_WIDTH / 2;
	const int halfHeight = CAR_HEIGHT / 2;
	contour.get_points().push_back(CL_Pointf(-halfWidth, halfHeight));
	contour.get_points().push_back(CL_Pointf(halfWidth, halfHeight));
	contour.get_points().push_back(CL_Pointf(halfWidth, -halfHeight));
	contour.get_points().push_back(CL_Pointf(-halfWidth, -halfHeight));

	m_phyCollisionOutline.get_contours().push_back(contour);

	m_phyCollisionOutline.set_inside_test(true);

	m_phyCollisionOutline.calculate_radius();
	m_phyCollisionOutline.calculate_smallest_enclosing_discs();
}
コード例 #13
0
ファイル: Shadow.cpp プロジェクト: steinbergerbernd/Pac-Man
Shadow::Shadow(World *world) : Ghost(world)
{
    CL_Sizef fieldSize = world->getLevel()->getFieldSize();
    //Startposition ist die rechte, obere Ecke
    position = CL_Pointf(26 * fieldSize.width + fieldSize.width / 2, 1 * fieldSize.height + fieldSize.height / 2);
    currentField = getIndices(position);

    setBody("Shadow");

    onFieldCenter();
}
コード例 #14
0
ファイル: Level.cpp プロジェクト: ryba616/ryba.racer
CL_Pointf Level::getStartPosition(int p_num) const {

	std::map<int, CL_Pointf>::const_iterator startPositionItor = m_startPositions.find(p_num);

	if (startPositionItor != m_startPositions.end()) {
		return startPositionItor->second;
	} else {
		return CL_Pointf(200, 200);
	}

}
コード例 #15
0
std::vector<CL_Pointf> CL_EarClipTriangulator_Impl::get_vertices()
{
	std::vector<CL_Pointf> points;

	for (unsigned int cnt = 0; cnt < vertices.size(); cnt++)
	{
		points.push_back( CL_Pointf(vertices[cnt]->x, vertices[cnt]->y));
	}

	return points;
}
コード例 #16
0
bool CL_EarClipTriangulator_Impl::is_ear(const LinkedVertice &v)
{
	if( is_reflex(v) ) return false;

	CL_Trianglef triangle( CL_Pointf(v.x, v.y), CL_Pointf(v.next->x, v.next->y), CL_Pointf(v.previous->x, v.previous->y) );

	LinkedVertice *v_check = v.next->next;

	while( v_check != v.previous )
	{
		if( v_check == v.next || v_check == v.previous )
		{
			v_check = v_check->next;
			continue;
		}

		if( triangle.point_inside( CL_Pointf(v_check->x, v_check->y) ) )
			return false;

		v_check = v_check->next;
	}

	return true;
}
コード例 #17
0
void
WorkspaceMoveToolImpl::update(const CL_InputEvent& event)
{
  GraphicContextState& gc_state = EditorMapComponent::current()->get_gc_state();

  float sa = sin(-gc_state.get_rotation()/180.0f*M_PI);
  float ca = cos(-gc_state.get_rotation()/180.0f*M_PI);

  float dx = ca * (click_pos.x - event.mouse_pos.x) - sa * (click_pos.y - event.mouse_pos.y);
  float dy = sa * (click_pos.x - event.mouse_pos.x) + ca * (click_pos.y - event.mouse_pos.y);

  gc_state.set_pos(CL_Pointf(old_trans_offset.x
                             + dx / EditorMapComponent::current()->get_gc_state().get_zoom(),
                             old_trans_offset.y
                             + dy / EditorMapComponent::current()->get_gc_state().get_zoom()));
}
コード例 #18
0
ファイル: Level.cpp プロジェクト: ryba616/ryba.racer
void Level::loadSandElement(const CL_DomNode &p_sandNode)
{
	const CL_DomNodeList sandChildren = p_sandNode.get_child_nodes();
	const int sandChildrenCount = sandChildren.get_length();

	CL_DomNode sandChildNode, groupChildNode;

	for (int i = 0; i < sandChildrenCount; ++i) {
		sandChildNode = sandChildren.item(i);

		if (sandChildNode.get_node_name() == "group") {
			const CL_DomNodeList groupChildren = sandChildNode.get_child_nodes();
			const int groupChildrenCount = groupChildren.get_length();

			// create new sandpit
			m_sandpits.push_back(Sandpit());
			Sandpit &sandpit = m_sandpits.back();

			for (int j = 0; j < groupChildrenCount; ++j) {
				groupChildNode = groupChildren.item(j);

				if (groupChildNode.get_node_name() == "circle") {

					CL_DomNamedNodeMap attrs = groupChildNode.get_attributes();

					const float x = CL_StringHelp::local8_to_float(attrs.get_named_item("x").get_node_value());
					const float y = CL_StringHelp::local8_to_float(attrs.get_named_item("y").get_node_value());
					const float radius = CL_StringHelp::local8_to_float(attrs.get_named_item("radius").get_node_value());

					// add to sandpit

					// must save as integer
					const CL_Pointf centerFloat = real(CL_Pointf(x, y));
					const CL_Point centerInt = CL_Point((int) floor(centerFloat.x), (int) floor(centerFloat.y));

					sandpit.addCircle(centerInt, real(radius));

//					m_resistanceMap.addGeometry(geom, 0.8f);
				} else {
					cl_log_event("error", "unknown element in <sand><group></group></sand>: <%1>", sandChildNode.get_node_name());
				}
			}
		} else {
			cl_log_event("error", "unknown element in <sand></sand>: <%1>", sandChildNode.get_node_name());
		}
	}
}
コード例 #19
0
ファイル: Server.cpp プロジェクト: genail/gear
void ServerImpl::onClientConnected(CL_NetGameConnection *p_conn)
{
    cl_log_event(LOG_EVENT, "player %1 is connected", (unsigned) p_conn);

    Player player;

    // set default car state
    CL_NetGameEvent data("");

    player.m_car->setPosition(CL_Pointf(-50.0f, -50.0f));
    player.m_car->serialize(&data);
    player.m_lastCarState.setSerializedData(data);

    m_connections[p_conn] = player;

    sendGameMode(p_conn);
}
コード例 #20
0
ファイル: DialogScene.cpp プロジェクト: SadSido/Tower
void DialogScene::render()
{
	Renderer::Ref renderer = m_manager->getRenderer();
	CL_Sizef window = renderer->getGCSize();

	// render underlying scene:
	m_topScene->render();

	// fade out a little:
	CL_Rectf rcShadow = m_rcBub; rcShadow.translate(CL_Pointf(5.0f, 5.0f));
	CL_Colorf bubColor = blendColors(getPhraseColor(m_newtype), getPhraseColor(m_oldtype), m_percent);

	CL_Draw::fill(renderer->getGC(), rcShadow, CL_Colorf::black);
	CL_Draw::fill(renderer->getGC(), m_rcBub, bubColor);

	m_layout.draw_layout(renderer->getGC());
}
コード例 #21
0
//Zeichnen
void HexMap::draw()
{
	CL_GraphicContext gc = world->get_gc();
	CL_Pointf positions[6];
	CL_Pointf center;
	float xPosition, yPosition;
	CL_Colorf fieldColor;

	//Höhe für Zeilen durchlaufen
	for(int i = 0; i < mapHeight; ++i)
	{
		//Breite für Spalten durchlaufen
		for(int j = 0; j < mapWidth; ++j)
		{
			xPosition = (float)(j * (hexagonWidth - indenting));

			yPosition = (float)(hexagonHeight * i);

			//Bei jeder zweiten Spalte muss das Hexagon um ein halbes Hexagon nach unten verschoben werden
			if(j % 2 == 1)
				yPosition += hexagonHeight / 2.0f;

			//Eckpunkte des Hexagons setzen
			positions[0] = CL_Pointf(xPosition + indenting, yPosition);
			positions[1] = CL_Pointf(xPosition + hexagonWidth - indenting, yPosition);
			positions[2] = CL_Pointf(xPosition + hexagonWidth, yPosition + hexagonHeight / 2.0f);
			positions[3] = CL_Pointf(xPosition + hexagonWidth - indenting, yPosition + hexagonHeight);
			positions[4] = CL_Pointf(xPosition + indenting, yPosition + hexagonHeight);
			positions[5] = CL_Pointf(xPosition, yPosition + hexagonHeight / 2.0f);

			//Mittelpunkt des Hexagons
			center = CL_Pointf(xPosition + hexagonWidth / 2.0f, yPosition + hexagonHeight / 2.0f);
			fieldColor = getColorOfFieldType(fields[i][j]);

			//Eckpunkte durchlaufen und Linien und gefüllte Dreiecke zum Mittelpunkt hin zeichnen
			for(int k = 0; k < 6; ++k)
			{
				CL_Draw::triangle(gc, positions[k], positions[(k+1)%6], center, fieldColor);
				CL_Draw::line(gc, positions[k], positions[(k+1)%6], CL_Colorf::white);
			}
		}
	}
}
コード例 #22
0
CL_Pointf CL_BezierCurve_Impl::get_point_relative(float pos) const
{
	// Perform deCasteljau iterations:
	// (linear interpolate between the control points)
	std::vector<CL_Pointf>::size_type j, N, i;
	float a = pos;
	float b = 1.0f - pos;
	P = control_points;
	N = control_points.size();
	if (N == 0)
		return CL_Pointf();
	for (j = N-1; j > 0; j--)
	{
		for (i = 0; i < j; i++)
		{
			P[i].x = b*P[i].x + a*P[i+1].x;
			P[i].y = b*P[i].y + a*P[i+1].y;
		}
	}
	return P[0];
}
コード例 #23
0
ファイル: PlayerList.cpp プロジェクト: bercik/gear
void PlayerList::draw(CL_GraphicContext &p_gc)
{
	const Race::Level &level = m_impl->m_logic->getLevel();
	const int carCount = level.getCarCount();

	float h = 0.0f;

	p_gc.mult_translate(m_impl->m_position.x, m_impl->m_position.y);

	for (int i = 0; i < carCount; ++i) {
		const Race::Car &car = level.getCar(i);

		m_impl->m_label.setPosition(CL_Pointf(0, h));
		m_impl->m_label.setText(cl_format("%1. %2", i + 1, m_impl->m_logic->getPlayer(car).getName())); // FIXME: not optimal

		m_impl->m_label.draw(p_gc);

		h += m_impl->m_labelHeight;
	}

	p_gc.pop_modelview();
}
コード例 #24
0
ファイル: Level.cpp プロジェクト: ryba616/ryba.racer
float Level::getResistance(float p_realX, float p_realY)
{
	return m_resistanceMap.resistance(CL_Pointf(p_realX, p_realY));
}
コード例 #25
0
// return the midpoint on the line from A to B
CL_Pointf CL_LineMath::midpoint( const CL_Pointf &A, const CL_Pointf &B )
{
	return CL_Pointf( (A.x+B.x)/2.0f, (A.y+B.y)/2.0f );
}
コード例 #26
0
void CL_BezierCurve::add_control_point(float x, float y)
{
	impl->control_points.push_back(CL_Pointf(x, y));
}
コード例 #27
0
ファイル: Checkpoint.cpp プロジェクト: bercik/gear
Checkpoint::Checkpoint() :
	m_impl(new CheckpointImpl(0, CL_Pointf()))
{
	// empty
}
コード例 #28
0
DrawingContext::DrawingContext()
{
  translate_stack.push_back(CL_Pointf(0, 0));
}
コード例 #29
0
void
DrawingContext::reset_modelview()
{
  translate_stack.clear();
  translate_stack.push_back(CL_Pointf(0, 0));
}
コード例 #30
0
void CL_EarClipTriangulator_Impl::end_hole()
{
	create_lists(false);

	target_array = &vertices;

	// To be able to triangulate holes the inner and outer vertice arrays are connected
	// so that there isn't actually any hole, just a single polygon with a small gap
	// eliminating the hole.
	//
	// 1. find point on inner contour closest to a vertice on the outer contour.
	//
	// 2. Create bridge start and end points by offsetting the new vertices a bit along the edges to the next and prev vertices.
	// 

	LinkedVertice *outer_vertice = 0;
	LinkedVertice *segment_start;
	LinkedVertice *segment_end;
	CL_Pointf inner_point;
	float inner_point_rel;
	float distance = FLT_MAX;

	for (unsigned int vertex_cnt = 0; vertex_cnt < vertices.size(); vertex_cnt++)
	{
		CL_Pointf tmp_outer_point = CL_Pointf(vertices[vertex_cnt]->x,vertices[vertex_cnt]->y);

		for (unsigned int hole_cnt = 0; hole_cnt < hole.size(); hole_cnt++)
		{

			CL_Pointf tmp_line_start(hole[hole_cnt]->x, hole[hole_cnt]->y);
			CL_Pointf tmp_line_end(hole[hole_cnt]->next->x, hole[hole_cnt]->next->y);
			
			CL_Pointf tmp_inner_point = CL_LineMath::closest_point(tmp_outer_point, tmp_line_start, tmp_line_end);
			
			float tmp_distance = tmp_inner_point.distance(tmp_outer_point);
			
			if( tmp_distance < distance  )
			{
				inner_point_rel = CL_LineMath::closest_point_relative(tmp_outer_point, tmp_line_start, tmp_line_end);
				distance = tmp_distance;
				outer_vertice = vertices[vertex_cnt];
				inner_point = tmp_inner_point;
				segment_start = hole[hole_cnt];
				segment_end = hole[hole_cnt]->next;
			}
		}
	}

	LinkedVertice *outer_bridge_start = new LinkedVertice();
	LinkedVertice *outer_bridge_end = new LinkedVertice();
	LinkedVertice *inner_bridge_start = new LinkedVertice();
	LinkedVertice *inner_bridge_end = new LinkedVertice();

	//  offset new points along old edges
	CL_Pointf outer_point(outer_vertice->x, outer_vertice->y);

	set_bridge_vertice_offset( outer_bridge_start, outer_point, 0.0,             outer_vertice, outer_vertice->previous, 1 );
	set_bridge_vertice_offset( outer_bridge_end,   outer_point, 0.0,             outer_vertice, outer_vertice->next, 1 );
	set_bridge_vertice_offset( inner_bridge_start, inner_point, inner_point_rel, segment_start, segment_end, 1 );
	set_bridge_vertice_offset( inner_bridge_end,   inner_point, inner_point_rel, segment_start, segment_end, -1 );

	// update next pointers to ignore old vertices

	// connections between inner and outer contours
	outer_bridge_start->next = inner_bridge_start;
	inner_bridge_end->next = outer_bridge_end;

	// connections between new and old vertices: outer contour
	outer_bridge_end->next = outer_vertice->next;
	outer_vertice->previous->next = outer_bridge_start;

	// connections between new and old vertices: inner contour
	inner_bridge_start->next = segment_end;
	segment_start->next = inner_bridge_end;

	delete outer_vertice;
	outer_vertice = 0;

	if( inner_point_rel == 0.0 ) // if split point is at line end, remove inner vertex
	{
		segment_start->previous->next = inner_bridge_end;
		delete segment_start;
		segment_start = 0;
	}
	if( inner_point_rel == 1.0 ) // if split point is at line end, remove inner vertex
	{
		inner_bridge_start->next = segment_end->next;
		delete segment_end;
		segment_end = 0;
	}

	hole.clear();

	// rebuild the vector...
	vertices.clear();

	LinkedVertice *test = inner_bridge_start;
	do
	{
		vertices.push_back(test);
		test = test->next;
	} while( test != inner_bridge_start );

	// print the bridge start and end points:
/*	cl_write_console_line("outer_point: %1 %2", outer_point.x, outer_point.y );
	cl_write_console_line("inner_point: %1 %2", inner_point.x, inner_point.y );
	cl_write_console_line("inner_bridge_end: %1 %2", inner_bridge_end->x, inner_bridge_end->y );
	cl_write_console_line("outer_bridge_end: %1 %2", outer_bridge_end->x, outer_bridge_end->y );
	cl_write_console_line("inner_bridge_start: %1 %2", inner_bridge_start->x, inner_bridge_start->y );
	cl_write_console_line("outer_bridge_start: %1 %2", outer_bridge_start->x, outer_bridge_start->y );
*/
}