Exemplo n.º 1
0
void patrolUnit::OpenGLDraw(const MapProvider *mp, const SimulationInfo *) const
{
    GLdouble xx, yy, zz, rad;
    Map *map = mp->GetMap();
    int posx = x, posy = y;
    map->GetOpenGLCoord(posx, posy, xx, yy, zz, rad);
    glColor3f(r, g, b);
    glBegin(GL_LINE_STRIP);
//	glVertex3f(xx, yy+rad/2, zz);
    glVertex3f(xx, yy, zz-rad/2);
    for (int t = moves.size()-1; t >= 0; t--)
    {
        posx += ((moves[t]&kE)?1:0) - ((moves[t]&kW)?1:0);
        posy += ((moves[t]&kS)?1:0) - ((moves[t]&kN)?1:0);

        map->GetOpenGLCoord(posx, posy, xx, yy, zz, rad);

//		glVertex3f(xx, yy+rad/2, zz);
        glVertex3f(xx, yy, zz-rad/2);
    }
    glEnd();

    map->GetOpenGLCoord(x, y, xx, yy, zz, rad);
    glColor3f(r, g, b);
    drawSphere(xx, yy, zz, rad);
}
Exemplo n.º 2
0
void TrailMaxUnit<xyLoc,tDirection,MapEnvironment>::OpenGLDraw( int, MapEnvironment *env, SimulationInfo<xyLoc,tDirection,MapEnvironment>* ) {
	GLdouble xx, yy, zz, rad;
	Map *m = env->GetMap();
	if( current_pos.x >= m->GetMapWidth() || current_pos.y >= m->GetMapHeight() ) {
		fprintf( stderr, "Warning: TrailMaxUnit is out of bounds. Could not draw it.\n" );
		return;
	}
	m->GetOpenGLCoord( current_pos.x, current_pos.y, xx, yy, zz, rad );
	if( done )
		glColor3d( 0., 1., 0. ); // turn green when done
	else
		glColor3f( r, g, b );
	DrawSphere( xx, yy, zz, rad );

	// draw the path in front of us
	if( pathcache.size() > 0 && !done) {
		glBegin(GL_LINE_STRIP);
		glVertex3f( xx, yy, zz-rad/2 );
		for( unsigned int i = 0; i < pathcache.size(); i++ ) {
			m->GetOpenGLCoord( pathcache[i].x, pathcache[i].y, xx, yy, zz, rad );
			glVertex3f( xx, yy, zz-rad/2 );
		}
		glEnd();
	}

	return;
};
Exemplo n.º 3
0
void MySearchUnit::OpenGLDraw(int , AbsMapEnvironment *ame, AbsMapSimulationInfo *si)
{
    GLdouble xx, yy, zz, rad;
    Map *map = ame->GetMap();

    int posx = loc.x, posy = loc.y;
    map->GetOpenGLCoord(posx, posy, xx, yy, zz, rad);
    glColor3f(r, g, b);
    glBegin(GL_LINE_STRIP);
    glVertex3f(xx, yy, zz-rad/2);
    for (int t = moves.size()-1; t >= 0; t--)
    {
        posx += ((moves[t]&kE)?1:0) - ((moves[t]&kW)?1:0);
        posy += ((moves[t]&kS)?1:0) - ((moves[t]&kN)?1:0);

        map->GetOpenGLCoord(posx, posy, xx, yy, zz, rad);

        glVertex3f(xx, yy, zz-rad/2);
    }
    glEnd();

    // draw object
    map->GetOpenGLCoord(loc.x, loc.y, xx, yy, zz, rad);
    if (onTarget)
    {
        double perc = (1.0-sqrt(sqrt(abs(sin(targetTime+0.25*si->GetSimulationTime())))));
        glColor3f(r*perc, g*perc, b*perc);
    }
    else
        glColor3f(r, g, b);
    DrawSphere(xx, yy, zz, rad);

    /*
    	// draw target
    	if (targetUnit >= 0)
    	{
    		si->GetPublicUnitInfo( targetUnit, pui );
    		xyLoc tloc = pui.currentState;
    		map->GetOpenGLCoord(tloc.x, tloc.y, xx, yy, zz, rad);

    		double perc = (1.0-sqrt(sqrt(abs(sin(targetTime+0.25*si->GetSimulationTime())))));
    		glColor3f(r*perc, g*perc, b*perc);

    		DrawPyramid(xx, yy, zz, 1.1*rad, 0.75*rad);
    	}
    */
}
Exemplo n.º 4
0
void MyFrameHandler(unsigned long windowID, unsigned int viewport, void *)
{
	if (viewport == 0)
	{
		unitSims[windowID]->StepTime(stepsPerFrame);
	}
	
	if (unitSims[windowID]->GetNumUnits() > 0)
	{
		if (!unitSims[windowID]->GetPaused())
			stepsPerFrame*=1.002;//1.01;//
		if (unitSims[windowID]->Done() && recording)
		{
			recording = false;
//			stopRecording();
		}

	}

	if (GetNumPorts(windowID) == unitSims[windowID]->GetNumUnits())
	{
		unitSims[windowID]->GetEnvironment()->OpenGLDraw();
		unitSims[windowID]->OpenGLDraw(viewport);
		//measure.OpenGLDraw(unitSims[windowID]->GetEnvironment());
	}
	else {
		unitSims[windowID]->GetEnvironment()->OpenGLDraw();
		unitSims[windowID]->OpenGLDraw();
	}
	
	if (mouseTracking)
	{
		glBegin(GL_LINES);
		glColor3f(1.0f, 0.0f, 0.0f);
		Map *m = unitSims[windowID]->GetEnvironment()->GetMap();
		GLdouble x, y, z, r;
		m->GetOpenGLCoord(px1, py1, x, y, z, r);
		glVertex3f(x, y, z-3*r);
		m->GetOpenGLCoord(px2, py2, x, y, z, r);
		glVertex3f(x, y, z-3*r);
		glEnd();
	}
}
Exemplo n.º 5
0
void MyFrameHandler(unsigned long windowID, unsigned int viewport, void *)
{
	if (ge)
	{
		ge->OpenGLDraw();
		return;
	}
	if (viewport == 0)
	{
		unitSims[windowID]->StepTime(1.0/30.0);
	}
//	for (unsigned int x = 0; x < astars.size(); x++)
//		astars[x].OpenGLDraw();
	//	astar.OpenGLDraw();	
	unitSims[windowID]->OpenGLDraw();
	//unitSims[windowID]->GetEnvironment()->OpenGLDraw();
	
	if (screenShot)
	{
		SaveScreenshot(windowID, gDefaultMap);
		exit(0);
	}
//	glTranslatef(0, 0, -0.1);
//	glLineWidth(6.0);
//	if (ge == 0)
//		ge = new GraphEnvironment(GraphSearchConstants::GetGraph(unitSims[windowID]->GetEnvironment()->GetMap()));
//	ge->OpenGLDraw();

	if (astars.size() > 0)
		msa->OpenGLDraw();
	
	if (mouseTracking)
	{
		glBegin(GL_LINES);
		glColor3f(1.0f, 0.0f, 0.0f);
		Map *m = unitSims[windowID]->GetEnvironment()->GetMap();
		GLdouble x, y, z, r;
		m->GetOpenGLCoord(px1, py1, x, y, z, r);
		glVertex3f(x, y, z-3*r);
		m->GetOpenGLCoord(px2, py2, x, y, z, r);
		glVertex3f(x, y, z-3*r);
		glEnd();
	}
	
	if ((gdh) && (!ma1))
		gdh->OpenGLDraw();

	if (viewport == 1)
		mo->OpenGLDraw();
	if (viewport == 2)
		mo_g->OpenGLDraw();
	if (viewport == 3)
		mo_h->OpenGLDraw();
	
	if ((ma1) && (viewport == 0)) // only do this once...
	{
		ma1->SetColor(0.0, 0.5, 0.0, 0.75);
		if (runningSearch1 && !unitSims[windowID]->GetPaused())
		{
			ma1->SetColor(0.0, 0.0, 1.0, 0.75);
			for (int x = 0; x < gStepsPerFrame*4; x++)
			{
				if (a1.DoSingleSearchStep(path))
				{
					printf("Solution: moves %d, length %f, %lld nodes, %u on OPEN\n",
						   (int)path.size(), ma1->GetPathLength(path), a1.GetNodesExpanded(),
						   a1.GetNumOpenItems());
					runningSearch1 = false;
					break;
				}
			}
		}
		a1.OpenGLDraw();
	}
	if (ma2)
	{
		ma2->SetColor(1.0, 0.0, 0.0, 0.5);
		if (runningSearch2)
		{
			ma2->SetColor(1.0, 0.0, 1.0, 0.5);
			for (int x = 0; x < gStepsPerFrame; x++)
			{
				if (a2.DoSingleSearchStep(path))
				{
					printf("Solution: moves %d, length %f, %lld nodes\n",
						   (int)path.size(), ma1->GetPathLength(path), a2.GetNodesExpanded());
					runningSearch2 = false;
					break;
				}
			}
		}
		a2.OpenGLDraw();
	}

	if (0&&(runningSearch1 || runningSearch2 || mouseTracking) && viewport == GetNumPorts(windowID)-1)
	{
		static int cnt = 0;
		char fname[255];
		sprintf(fname, "/Users/nathanst/Movies/epea/EPEA%d%d%d", (cnt/100)%10, (cnt/10)%10, cnt%10);
		SaveScreenshot(windowID, fname);
		printf("Saved %s\n", fname);
		cnt++;
	}
}