Пример #1
0
void VectorNode::preRender(const VertexArrayPtr& pVA, bool bIsParentActive, 
        float parentEffectiveOpacity)
{
    Node::preRender(pVA, bIsParentActive, parentEffectiveOpacity);
    {
        ScopeTimer timer(PrerenderProfilingZone);
        VertexDataPtr pShapeVD = m_pShape->getVertexData();
        if (m_bDrawNeeded) {
            pShapeVD->reset();
            Pixel32 color = getColorVal();
            calcVertexes(pShapeVD, color);
            m_bDrawNeeded = false;
        }
        if (isVisible()) {
            m_pShape->setVertexArray(pVA);
        }
    }
}
Пример #2
0
//called on the drawingArea's expose event
gboolean drawingAreaExpose(GtkWidget *widgetDrawingArea, GdkEventExpose *event, gpointer data) {
	passToDrawingAreaExpose* passed = (passToDrawingAreaExpose*) data;
	bool* draw = passed->draw;

	if (*draw) {
		OwnRobot* ownRobotDraw = passed->ownRobotDraw;
		int myTeam = passed->myTeam;
		int numberOfRobots = passed->numberOfRobots;
		int *drawFactor = passed->drawFactor;
		int imageWidth = (VIEWDISTANCE+ROBOTDIAMETER) * (*drawFactor) * 2;
		int imageHeight = (VIEWDISTANCE+ROBOTDIAMETER) * (*drawFactor) * 2;

		//origin is the middle point where our viewed robot is located
		int origin[] = { imageWidth / 2, imageHeight / 2 };

		cairo_t *cr = gdk_cairo_create(GTK_DRAWING_AREA(widgetDrawingArea)->widget.window);
		cairo_set_line_width(cr, 2);

		ColorObject color = colorFromTeam(myTeam);

		//draw our home if it is nearby (FIRST so it goes underneath)
		if (ownRobotDraw->homeRelX - ((HOMEDIAMETER / 2) + (ROBOTDIAMETER / 2)) < VIEWDISTANCE &&
				ownRobotDraw->homeRelY - ((HOMEDIAMETER / 2) + (ROBOTDIAMETER / 2)) < VIEWDISTANCE) {
			cairo_set_source_rgb(cr, 0, 0, 0);
			cairo_arc(cr, origin[0] + ownRobotDraw->homeRelX * *drawFactor,
					origin[1] + ownRobotDraw->homeRelY * *drawFactor, HOMEDIAMETER * *drawFactor / 2, 0, 2 * M_PI);
			cairo_stroke_preserve(cr);
			cairo_set_source_rgb(cr, color.r, color.g, color.b);
			cairo_fill(cr);
		}

		for (unsigned int i = 0; i < ownRobotDraw->seenRobots.size(); i++) {
		  //robot Ids start at 1, team Ids start at 0. Must remember this. THIS is where the damn
		  //blue robot and off coloring has been coming from.
			color = colorFromTeam(((ownRobotDraw->seenRobots.at(i)->id)-1) / numberOfRobots);
			cairo_set_source_rgb(cr, 0, 0, 0);
			cairo_arc(cr, origin[0] + ownRobotDraw->seenRobots.at(i)->relx * *drawFactor,
					origin[1] + ownRobotDraw->seenRobots.at(i)->rely * *drawFactor, ROBOTDIAMETER * *drawFactor / 2, 0,
					2 * M_PI);
			cairo_stroke_preserve(cr);

			cairo_set_source_rgb(cr, color.r, color.g, color.b);
			cairo_fill(cr);
		}

		//draw seen pucks
		cairo_set_source_rgb(cr, 0, 0, 0);
		for (unsigned int i = 0; i < ownRobotDraw->seenPucks.size(); i++) {
			cairo_arc(cr, origin[0] + ownRobotDraw->seenPucks.at(i)->relx * *drawFactor,
					origin[1] + ownRobotDraw->seenPucks.at(i)->rely * *drawFactor, PUCKDIAMETER * *drawFactor / 2, 0,
					2 * M_PI);
			cairo_fill(cr);
		}

		//draw the currently viewed robot
		color = colorFromTeam(myTeam);
		cairo_set_source_rgb(cr, 0, 0, 0);
		cairo_arc(cr, origin[0], origin[1], ROBOTDIAMETER * *drawFactor / 2, 0, 2 * M_PI);
		cairo_stroke_preserve(cr);
		cairo_set_source_rgb(cr, color.r, color.g, color.b);
		cairo_fill(cr);


		//ownRobot->angle does not provide a valid angle ( it's always zero )!
		//draw the line showing the angle that the robot is moving at
		if( !(ownRobotDraw->vx == 0 && ownRobotDraw->vy == 0 ))
		{
			int endX=origin[0] + ownRobotDraw->vx * *drawFactor * 4, endY=origin[1] + ownRobotDraw->vy * *drawFactor * 4;

			double x1, y1, x2, y2;
			calcVertexes(origin[0], origin[1], endX, endY, *drawFactor, x1, y1, x2, y2);

			cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
			cairo_move_to(cr, origin[0], origin[1]);
			cairo_line_to(cr, endX, endY);
			cairo_line_to(cr, x1, y1);
			cairo_move_to(cr, x2, y2);
			cairo_line_to(cr, endX, endY);

			cairo_stroke(cr);
		}

		//if the robot has a puck then actually draw the puck in its center
		if (ownRobotDraw->hasPuck) {
			cairo_set_source_rgb(cr, 0, 0, 0);

			cairo_arc(cr, origin[0], origin[1], PUCKDIAMETER * *drawFactor, 0, 2 * M_PI);
			cairo_stroke(cr);
		}

		//draw the viewing area - cairo angles are stupid
		//bonus: not moving? 360 degree view
		cairo_set_source_rgba(cr, 0, 0, 0, 0.75);
		if(ownRobotDraw->vx == 0 && ownRobotDraw->vy == 0)
		{
		  //draw the circle
		  cairo_arc(cr, origin[0], origin[1], imageWidth/2, 0, 2 * M_PI);
		}else{
		  //draw the cone
		  cairo_move_to(cr, origin[0], origin[1]);
		  cairo_arc_negative(cr, origin[0], origin[1], imageWidth/2, (VIEWANGLE / 2.0) - ownRobotDraw->angle, (2 * M_PI) - (VIEWANGLE/2.0) - ownRobotDraw->angle);
		  cairo_line_to(cr, origin[0], origin[1]);
		}
		cairo_stroke(cr);

		cairo_destroy(cr);
		*draw = false;

		if (gtk_toggle_tool_button_get_active(passed->info))
			updateInfoWindow(ownRobotDraw, passed->builder);
	}

	return FALSE;
}