Exemplo n.º 1
0
void CCommandAI::DrawCommands(void)
{
	float3 pos=owner->midPos;
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		bool draw=false;
		switch(ci->id){
		case CMD_ATTACK:
		case CMD_DGUN:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			} else {
				pos=float3(ci->params[0],ci->params[1]+3,ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			draw=true;
			break;
		default:
			break;
		}
		if(draw){
			glVertexf3(pos);
			cursorIcons->AddIcon(ci->id, pos);
		}
	}
	glEnd();
}
Exemplo n.º 2
0
void CSkyBox::Draw()
{
    //glTranslatef(camera->pos.x, camera->pos.y, camera->pos.z);
    //glCallList(displist);

    glDisable(GL_FOG);
    glColor3f(1,1,1);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_TEXTURE_CUBE_MAP_ARB);
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, tex);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glDepthMask(0);
    glDisable(GL_DEPTH_TEST);

    float3 v1 = camera->CalcPixelDir(0,0);
    float3 v2 = camera->CalcPixelDir(gu->viewSizeX,0);
    float3 v3 = camera->CalcPixelDir(gu->viewSizeX,gu->viewSizeY);
    float3 v4 = camera->CalcPixelDir(0,gu->viewSizeY);

    glBegin(GL_QUADS);

    glTexCoord3f(-v1.x,-v1.y,-v1.z);
    //glNormal3f(0,1,0);
    glVertexf3(camera->pos + v1*(NEAR_PLANE+5));

    glTexCoord3f(-v2.x,-v2.y,-v2.z);
    //glNormal3f(1,1,0);
    glVertexf3(camera->pos + v2*(NEAR_PLANE+5));

    glTexCoord3f(-v3.x,-v3.y,-v3.z);
    //glNormal3f(0,1,1);
    glVertexf3(camera->pos + v3*(NEAR_PLANE+5));

    glTexCoord3f(-v4.x,-v4.y,-v4.z);
    //glNormal3f(1,1,1);
    glVertexf3(camera->pos + v4*(NEAR_PLANE+5));
    glEnd();

    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glDepthMask(1);
    glDisable(GL_ALPHA_TEST);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    if (gu->drawFog) {
        glFogfv(GL_FOG_COLOR,mapInfo->atmosphere.fogColor);
        glFogi(GL_FOG_MODE,GL_LINEAR);
        glFogf(GL_FOG_START,gu->viewRange*fogStart);
        glFogf(GL_FOG_END,gu->viewRange);
        glFogf(GL_FOG_DENSITY,1.00f);
        glEnable(GL_FOG);
    }
}
Exemplo n.º 3
0
void CPathFinder::Draw(void)
{
    glColor3f(0.7,0.2,0.2);
    glDisable(GL_TEXTURE_2D);
    glBegin(GL_LINES);
    for(OpenSquare* os=openSquareBuffer; os!=openSquareBufferPointer; ++os) {
        int2 sqr=os->square;
        int square = os->sqr;
        if(squareState[square].status & PATHOPT_START)
            continue;
        float3 p1;
        p1.x=sqr.x*SQUARE_SIZE;
        p1.z=sqr.y*SQUARE_SIZE;
        p1.y=ground->GetHeight(p1.x,p1.z)+15;
        float3 p2;
        int obx=sqr.x-directionVector[squareState[square].status & PATHOPT_DIRECTION].x;
        int obz=sqr.y-directionVector[squareState[square].status & PATHOPT_DIRECTION].y;
        int obsquare =  obz * gs->mapx + obx;

        if(obsquare>=0) {
            p2.x=obx*SQUARE_SIZE;
            p2.z=obz*SQUARE_SIZE;
            p2.y=ground->GetHeight(p2.x,p2.z)+15;

            glVertexf3(p1);
            glVertexf3(p2);
        }
    }
    glEnd();
}
void CSelectedUnits::Draw()
{
	glDisable(GL_DEPTH_TEST );
	//glEnable(GL_BLEND);
	//glColor4f(0,0.8f,0,0.4f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glColor3f(0,1.0f,0);
	set<CUnit*>::iterator ui;
	glBegin(GL_QUADS);
	if(selectedGroup!=-1){
		for(ui=grouphandler->groups[selectedGroup]->units.begin();ui!=grouphandler->groups[selectedGroup]->units.end();++ui){
			float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset);
			glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4));
			glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4));
		}
	} else {
		for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){
			float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset);
			glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4));
			glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4));
		}
	}
	glEnd();
	glEnable(GL_DEPTH_TEST );
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	//glDisable(GL_BLEND);
}
Exemplo n.º 5
0
void CMouseHandler::Draw()
{
	dir=hide ? camera->forward : camera->CalcPixelDir(lastx,lasty);
	if(activeReceiver)
		return;

#ifdef DIRECT_CONTROL_ALLOWED
	if(gu->directControl){
		return;
	}
#endif
	if(buttons[SDL_BUTTON_LEFT].pressed && buttons[SDL_BUTTON_LEFT].movement>4 && mouseHandlerMayDoSelection && ( !inMapDrawer || !inMapDrawer->keyPressed )){
		glDisable(GL_TEXTURE_2D);
		glColor4f(1,1,1,0.5);

		float dist=ground->LineGroundCol(buttons[SDL_BUTTON_LEFT].camPos,buttons[SDL_BUTTON_LEFT].camPos+buttons[SDL_BUTTON_LEFT].dir*gu->viewRange*1.4);
		if(dist<0)
			dist=gu->viewRange*1.4;
		float3 pos1=buttons[SDL_BUTTON_LEFT].camPos+buttons[SDL_BUTTON_LEFT].dir*dist;

		dist=ground->LineGroundCol(camera->pos,camera->pos+dir*gu->viewRange*1.4);
		if(dist<0)
			dist=gu->viewRange*1.4;
		float3 pos2=camera->pos+dir*dist;

		float3 dir1=pos1-camera->pos;
		dir1.Normalize();
		float3 dir2=pos2-camera->pos;
		dir2.Normalize();

		float3 dir1S=camera->right*(dir1.dot(camera->right))/dir1.dot(camera->forward);
		float3 dir1U=camera->up*(dir1.dot(camera->up))/dir1.dot(camera->forward);

		float3 dir2S=camera->right*(dir2.dot(camera->right))/dir2.dot(camera->forward);
		float3 dir2U=camera->up*(dir2.dot(camera->up))/dir2.dot(camera->forward);

		glDisable(GL_FOG);
		glDisable(GL_DEPTH_TEST);
		glBegin(GL_LINE_STRIP);
		glVertexf3(camera->pos+dir1U*30+dir1S*30+camera->forward*30);
		glVertexf3(camera->pos+dir2U*30+dir1S*30+camera->forward*30);
		glVertexf3(camera->pos+dir2U*30+dir2S*30+camera->forward*30);
		glVertexf3(camera->pos+dir1U*30+dir2S*30+camera->forward*30);
		glVertexf3(camera->pos+dir1U*30+dir1S*30+camera->forward*30);
		glEnd();

		glEnable(GL_DEPTH_TEST);
		glEnable(GL_FOG);
	}
}
Exemplo n.º 6
0
/*
Draw path-lines for each path in pathmap.
*/
void CPathManager::Draw() {
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glLineWidth(3);
	std::map<unsigned int, MultiPath*>::iterator pi;
	for(pi = pathMap.begin(); pi != pathMap.end(); pi++) {
		MultiPath* path = pi->second;
		std::list<float3>::iterator pvi;

		//Start drawing a line.
		glBegin(GL_LINE_STRIP);

		//Drawing estimatePath2.
		glColor4f(0,0,1,1);
		for(pvi = path->estimatedPath2.path.begin(); pvi != path->estimatedPath2.path.end(); pvi++) {
			float3 pos = *pvi;
			pos.y += 5;
			glVertexf3(pos);
		}

		//Drawing estimatePath.
		glColor4f(0,1,0,1);
		for(pvi = path->estimatedPath.path.begin(); pvi != path->estimatedPath.path.end(); pvi++) {
			float3 pos = *pvi;
			pos.y += 5;
			glVertexf3(pos);
		}

		//Drawing detailPath
		glColor4f(1,0,0,1);
		for(pvi = path->detailedPath.path.begin(); pvi != path->detailedPath.path.end(); pvi++) {
			float3 pos = *pvi;
			pos.y += 5;
			glVertexf3(pos);
		}

		//Stop drawing a line.
		glEnd();

		//Tell the CPathFinderDef to visualise it self.
		path->peDef->Draw();
	}
	glLineWidth(1);
#if !defined(USE_GML) || !GML_ENABLE_SIMDRAW // making this threadsafe might be too costly performance wise
	pf->Draw();
	pe->Draw();
	pe2->Draw();
#endif
}
Exemplo n.º 7
0
void CTracerProjectile::Draw()
{
	if (drawLength > 3) {
		drawLength = 3;
	}

	glTexCoord2f(1.0f/16, 1.0f/16);
	glColor4f(1, 1, 0.1f, 0.4f);
	glBegin(GL_LINES);
		glVertexf3(drawPos);				
		glVertexf3(drawPos-dir * drawLength);				
	glEnd();
	glColor4f(1, 1, 1, 1);
	glTexCoord2f(0, 0);
}
void CTracerProjectile::Draw()
{
	if(inArray)
		DrawArray();

	if(drawLength>3)
		drawLength=3;

	float3 interPos=pos+speed*gu->timeOffset;
	glTexCoord2f(1.0f/16,1.0f/16);
	glColor4f(1,1,0.1f,0.4f);
	glBegin(GL_LINES);
		glVertexf3( interPos);				
		glVertexf3( interPos-dir*drawLength);				
	glEnd();
}
Exemplo n.º 9
0
/*
Draw path-lines for each path in pathmap.
*/
void CPathManager::Draw() {
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glLineWidth(3);
	map<unsigned int, MultiPath*>::iterator pi;
	for(pi = pathMap.begin(); pi != pathMap.end(); pi++) {
		MultiPath* path = pi->second;
		list<float3>::iterator pvi;
		
		//Start drawing a line.
		glBegin(GL_LINE_STRIP);

		//Drawing estimatePath2.
		glColor4f(0,0,1,1);
		for(pvi = path->estimatedPath2.path.begin(); pvi != path->estimatedPath2.path.end(); pvi++) {
			float3 pos = *pvi;
			pos.y += 5;
			glVertexf3(pos);
		}

		//Drawing estimatePath.
		glColor4f(0,1,0,1);
		for(pvi = path->estimatedPath.path.begin(); pvi != path->estimatedPath.path.end(); pvi++) {
			float3 pos = *pvi;
			pos.y += 5;
			glVertexf3(pos);
		}

		//Drawing detailPath
		glColor4f(1,0,0,1);
		for(pvi = path->detailedPath.path.begin(); pvi != path->detailedPath.path.end(); pvi++) {
			float3 pos = *pvi;
			pos.y += 5;
			glVertexf3(pos);
		}

		//Stop drawing a line.
		glEnd();

		//Tell the CPathFinderDef to visualise it self.
		path->peDef->Draw();
	}
	glLineWidth(1);
	pf->Draw();
	pe->Draw();
	pe2->Draw();
}
Exemplo n.º 10
0
void CBuilderCAI::DrawQuedBuildingSquares(void)
{
	deque<Command>::const_iterator ci;
	for (ci = commandQue.begin(); ci != commandQue.end(); ++ci) {
		if (buildOptions.find(ci->id) != buildOptions.end()) {
			BuildInfo bi(*ci);
			bi.pos = helper->Pos2BuildPos(bi);
			const float xsize = bi.GetXSize()*4;
			const float ysize = bi.GetYSize()*4;
			glBegin(GL_LINE_LOOP);
			glVertexf3(bi.pos + float3(+xsize, 1, +ysize));
			glVertexf3(bi.pos + float3(-xsize, 1, +ysize));
			glVertexf3(bi.pos + float3(-xsize, 1, -ysize));
			glVertexf3(bi.pos + float3(+xsize, 1, -ysize));
			glEnd();
		}
	}
}
Exemplo n.º 11
0
/*
Draws a trigonometric circle in 'resolution' steps.
*/
void glSurfaceCircle(const float3& center, float radius, unsigned int resolution) {
	glBegin(GL_LINE_STRIP);
	for(int i = 0; i <= resolution; ++i) {
		float3 pos = float3(center.x + sin(i*2*PI / resolution)*radius, 0, center.z + cos(i*2*PI / resolution)*radius);
		pos.y = ground->GetHeight(pos.x,pos.z) + 5;
		glVertexf3(pos);
	}
	glEnd();
}
Exemplo n.º 12
0
void CBuilderCAI::DrawQuedBuildingSquares(void)
{
	CCommandQueue::const_iterator ci;
	for (ci = commandQue.begin(); ci != commandQue.end(); ++ci) {
		if (buildOptions.find(ci->id) != buildOptions.end()) {
			BuildInfo bi(*ci);
			bi.pos = helper->Pos2BuildPos(bi);
			const float xsize = bi.GetXSize()*4;
			const float zsize = bi.GetZSize()*4;
			glBegin(GL_LINE_LOOP);
			glVertexf3(bi.pos + float3(+xsize, 1, +zsize));
			glVertexf3(bi.pos + float3(-xsize, 1, +zsize));
			glVertexf3(bi.pos + float3(-xsize, 1, -zsize));
			glVertexf3(bi.pos + float3(+xsize, 1, -zsize));
			glEnd();
			if (bi.pos.y < 0.0f) {
				const float s[4] = { 0.0f, 0.0f, 1.0f, 0.5f }; // start color
				const float e[4] = { 0.0f, 0.5f, 1.0f, 1.0f }; // end color

				const float h = bi.pos.y;
				const float x1 = bi.pos.x - xsize;
				const float z1 = bi.pos.z - zsize;
				const float x2 = bi.pos.x + xsize;
				const float z2 = bi.pos.z + zsize;

				glPushAttrib(GL_CURRENT_BIT);
				glBegin(GL_LINES);
				glColor4fv(s); glVertex3f(x1, h, z1); glColor4fv(e); glVertex3f(x1, 0.0f, z1);
				glColor4fv(s); glVertex3f(x2, h, z1); glColor4fv(e); glVertex3f(x2, 0.0f, z1);
				glColor4fv(s); glVertex3f(x1, h, z2); glColor4fv(e); glVertex3f(x1, 0.0f, z2);
				glColor4fv(s); glVertex3f(x2, h, z2); glColor4fv(e); glVertex3f(x2, 0.0f, z2);
				glEnd();
				// using the last end color
				glBegin(GL_LINE_LOOP);
				glVertex3f(x1, 0.0f, z1);
				glVertex3f(x1, 0.0f, z2);
				glVertex3f(x2, 0.0f, z2);
				glVertex3f(x2, 0.0f, z1);
				glEnd();
				glPopAttrib();
			}
		}
	}
}
Exemplo n.º 13
0
void CFactoryCAI::DrawCommands(void)
{
	float3 pos=owner->midPos;
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	deque<Command>::iterator ci;
	for(ci=newUnitCommands.begin();ci!=newUnitCommands.end();++ci){
		bool draw=false;
		switch(ci->id){
		case CMD_MOVE:
			pos=float3(ci->params[0],ci->params[1]+3,ci->params[2]);
			glColor4f(0.5,1,0.5,0.4);
			draw=true;
			break;
		case CMD_FIGHT:
		case CMD_PATROL:
			pos=float3(ci->params[0],ci->params[1]+3,ci->params[2]);
			glColor4f(0.5,0.5,1,0.4);
			draw=true;
			break;
		case CMD_ATTACK:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=uh->units[int(ci->params[0])]->pos;
			} else {
				pos=float3(ci->params[0],ci->params[1]+3,ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			draw=true;
			break;
		case CMD_GUARD:
			if(uh->units[int(ci->params[0])]!=0)
				pos=uh->units[int(ci->params[0])]->pos;
			glColor4f(0.3,0.3,1,0.4);
			draw=true;
			break;
		}
		if(draw){
			glVertexf3(pos);	
		}
	}
	glEnd();
}
Exemplo n.º 14
0
void CAirCAI::DrawCommands(void)
{
	CAirMoveType* myPlane=(CAirMoveType*)owner->moveType;
	//CAircraft* myPlane=(CAircraft*)owner;
	float3 pos=owner->pos;
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		switch(ci->id){
		case CMD_MOVE:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,1,0.5,0.4);
			glVertexf3(pos);
			cursorIcons->AddIcon(ci->id, pos);
			break;
		case CMD_FIGHT:
		case CMD_PATROL:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,0.5,1,0.4);
			glVertexf3(pos);
			cursorIcons->AddIcon(ci->id, pos);
			break;
		case CMD_ATTACK:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			} else {
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			glVertexf3(pos);
			cursorIcons->AddIcon(ci->id, pos);
			break;
		case CMD_AREA_ATTACK:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(1,0.5,0.5,0.4);
			glVertexf3(pos);
			glEnd();
			glSurfaceCircle(pos, ci->params[3], 20);
			glBegin(GL_LINE_STRIP);
			glVertexf3(pos);
			cursorIcons->AddIcon(ci->id, pos);
			break;
		case CMD_GUARD:
			if(uh->units[int(ci->params[0])]!=0)
				pos=uh->units[int(ci->params[0])]->pos;
			glColor4f(0.3,0.3,1,0.4);
			glVertexf3(pos);
			cursorIcons->AddIcon(ci->id, pos);
			break;
		}
	}
	glEnd();
}
Exemplo n.º 15
0
void CGuiHandler::DrawArea(float3 pos, float radius)
{
	glDisable(GL_TEXTURE_2D);
	glColor4f(0.5,1,0.5,0.5);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_FOG);
	glBegin(GL_TRIANGLE_FAN);
		glVertexf3(pos);
		for(int a=0;a<=40;++a){
			float3 p(cos(a*2*PI/40)*radius,0,sin(a*2*PI/40)*radius);
			p+=pos;		
			p.y=ground->GetHeight(p.x,p.z);
			glVertexf3(p);
		}
	glEnd();
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_FOG);
}
Exemplo n.º 16
0
/*
 *  Draws a trigonometric circle in 'resolution' steps.
 */
static void defSurfaceCircle(const float3& center, float radius, unsigned int res)
{
	glBegin(GL_LINE_LOOP);
	for (int i = 0; i < res; ++i) {
		const float radians = (2.0f * PI) * (float)i / (float)res;
		float3 pos;
		pos.x = center.x + (sin(radians) * radius);
		pos.z = center.z + (cos(radians) * radius);
		pos.y = ground->GetHeight(pos.x, pos.z) + 5.0f;
		glVertexf3(pos);
	}
	glEnd();
}
Exemplo n.º 17
0
void CBuilderCAI::DrawQuedBuildingSquares(void)
{
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		map<int,string>::iterator boi;
		if((boi=buildOptions.find(ci->id))!=buildOptions.end()){
			float3 pos=float3(ci->params[0],ci->params[1]+3,ci->params[2]);
			UnitDef *unitdef = unitDefHandler->GetUnitByName(boi->second);

			pos=helper->Pos2BuildPos(pos,unitdef);

			float xsize=unitdef->xsize*4;
			float ysize=unitdef->ysize*4;
			glColor4f(0.2,1,0.2,1);
			glBegin(GL_LINE_STRIP);
			glVertexf3(pos+float3(xsize,1,ysize));
			glVertexf3(pos+float3(-xsize,1,ysize));
			glVertexf3(pos+float3(-xsize,1,-ysize));
			glVertexf3(pos+float3(xsize,1,-ysize));
			glVertexf3(pos+float3(xsize,1,ysize));
			glEnd();
		}
	}
}
Exemplo n.º 18
0
void CSelectedUnits::Draw()
{
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND); // for line smoothing
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glLineWidth(cmdColors.UnitBoxLineWidth());

	glColor4fv(cmdColors.unitBox);

	glBegin(GL_QUADS);
	set<CUnit*>::iterator ui;
	if(selectedGroup!=-1){
		for(ui=grouphandler->groups[selectedGroup]->units.begin();ui!=grouphandler->groups[selectedGroup]->units.end();++ui){
			if((*ui)->isIcon)
				continue;
			float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset);
			glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4));
			glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4));
		}
	} else {
		for(ui=selectedUnits.begin();ui!=selectedUnits.end();++ui){
			if((*ui)->isIcon)
				continue;
			float3 pos((*ui)->pos+(*ui)->speed*gu->timeOffset);
			glVertexf3(pos+float3((*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,(*ui)->ysize*4));
			glVertexf3(pos+float3(-(*ui)->xsize*4,0,-(*ui)->ysize*4));
			glVertexf3(pos+float3((*ui)->xsize*4,0,-(*ui)->ysize*4));
		}
	}
	glEnd();
	
	glLineWidth(1.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
}
Exemplo n.º 19
0
/*
 *  Draws a trigonometric circle in 'resolution' steps, with a slope modifier
 */
void glBallisticCircle(const float3& center, const float radius,
                       const CWeapon* weapon,
                       unsigned int resolution, float slope)
{
	glBegin(GL_LINE_LOOP);
	for (int i = 0; i < resolution; ++i) {
		const float radians = (2.0f * PI) * (float)i / (float)resolution;
		float rad = radius;
		float3 pos;
		float sinR = sin(radians);
		float cosR = cos(radians);
		pos.x = center.x + (sinR * rad);
		pos.z = center.z + (cosR * rad);
		pos.y = ground->GetHeight(pos.x, pos.z);
		float heightDiff = (pos.y - center.y)/2;
		rad -= heightDiff * slope;
		float adjRadius = weapon ? weapon->GetRange2D(heightDiff*weapon->heightMod) : rad;
		float adjustment = rad/2;
		float ydiff = 0;
		int j;
		for(j = 0; j < 50 && fabs(adjRadius - rad) + ydiff > .01*rad; j++){
			if(adjRadius > rad) {
				rad += adjustment;
			} else {
				rad -= adjustment;
				adjustment /= 2;
			}
			pos.x = center.x + (sinR * rad);
			pos.z = center.z + (cosR * rad);
			float newY = ground->GetHeight(pos.x, pos.z);
			ydiff = fabs(pos.y - newY);
			pos.y = newY;
			heightDiff = (pos.y - center.y);
			adjRadius = weapon ? weapon->GetRange2D(heightDiff*weapon->heightMod) : rad;
		}
		pos.x = center.x + (sinR * adjRadius);
		pos.z = center.z + (cosR * adjRadius);
		pos.y = ground->GetHeight(pos.x, pos.z) + 5.0f;
		glVertexf3(pos);
	}
	glEnd();
}
Exemplo n.º 20
0
/*
 *  Draws a trigonometric circle in 'resolution' steps, with a slope modifier
 */
void glBallisticCircle(const float3& center, float radius, float slope,
                       unsigned int resolution)
{
    glBegin(GL_LINE_LOOP);
    for (int i = 0; i < resolution; ++i) {
        const float radians = (2.0f * PI) * (float)i / (float)resolution;
        float3 pos;
        pos.x = center.x + (sin(radians) * radius);
        pos.z = center.z + (cos(radians) * radius);
        pos.y = ground->GetHeight(pos.x, pos.z);

        const float heightDiff = (pos.y - center.y);
        const float adjRadius = radius - (heightDiff * slope);
        pos.x = center.x + (sin(radians) * adjRadius);
        pos.z = center.z + (cos(radians) * adjRadius);
        pos.y = ground->GetHeight(pos.x, pos.z) + 5.0f;
        glVertexf3(pos);
    }
    glEnd();
}
Exemplo n.º 21
0
void CSelectedUnits::Draw()
{
	glDisable(GL_TEXTURE_2D);
	glDepthMask(false);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND); // for line smoothing
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glLineWidth(cmdColors.UnitBoxLineWidth());

	GML_RECMUTEX_LOCK(sel); // Draw
	GML_RECMUTEX_LOCK(group); // Draw

	if (cmdColors.unitBox[3] > 0.0f) {
		glColor4fv(cmdColors.unitBox);

		const CUnitSet* unitSet;
		if (selectedGroup != -1) {
			unitSet = &grouphandlers[gu->myTeam]->groups[selectedGroup]->units;
		} else {
			unitSet = &selectedUnits;
		}

		glBegin(GL_QUADS);
		CUnitSet::const_iterator ui;
		for (ui = unitSet->begin(); ui != unitSet->end(); ++ui) {
			const CUnit* unit = *ui;
			if (unit->isIcon) {
				continue;
			}

			glVertexf3(unit->drawPos + float3( unit->xsize * 4, 0,  unit->zsize * 4));
			glVertexf3(unit->drawPos + float3(-unit->xsize * 4, 0,  unit->zsize * 4));
			glVertexf3(unit->drawPos + float3(-unit->xsize * 4, 0, -unit->zsize * 4));
			glVertexf3(unit->drawPos + float3( unit->xsize * 4, 0, -unit->zsize * 4));
		}
		glEnd();
	}

	// highlight queued build sites if we are about to build something
	// (or old-style, whenever the shift key is being held down)
	if (cmdColors.buildBox[3] > 0.0f) {
		if (!selectedUnits.empty() &&
				((cmdColors.BuildBoxesOnShift() && keys[SDLK_LSHIFT]) ||
				 ((guihandler->inCommand >= 0) &&
					(guihandler->inCommand < int(guihandler->commands.size())) &&
					(guihandler->commands[guihandler->inCommand].id < 0)))) {

			GML_STDMUTEX_LOCK(cai); // Draw

			bool myColor = true;
			glColor4fv(cmdColors.buildBox);
			std::list<CBuilderCAI*>::const_iterator bi;
			for (bi = uh->builderCAIs.begin(); bi != uh->builderCAIs.end(); ++bi) {
				CBuilderCAI* builder = *bi;
				if (builder->owner->team == gu->myTeam) {
					if (!myColor) {
						glColor4fv(cmdColors.buildBox);
						myColor = true;
					}
					builder->DrawQuedBuildingSquares();
				}
				else if (teamHandler->AlliedTeams(builder->owner->team, gu->myTeam)) {
					if (myColor) {
						glColor4fv(cmdColors.allyBuildBox);
						myColor = false;
					}
					builder->DrawQuedBuildingSquares();
				}
			}
		}
	}

	glLineWidth(1.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glEnable(GL_TEXTURE_2D);
}
Exemplo n.º 22
0
void CAirCAI::DrawCommands(void)
{
	CAirMoveType* myPlane=(CAirMoveType*)owner->moveType;
	//CAircraft* myPlane=(CAircraft*)owner;
	float3 pos=owner->pos;
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	float curHeight=pos.y-ground->GetHeight(pos.x,pos.z);
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		switch(ci->id){
		case CMD_MOVE:
			pos=float3(ci->params[0],ci->params[1]+curHeight,ci->params[2]);
			glColor4f(0.5,1,0.5,0.4);
			glVertexf3(pos);	
			break;
		case CMD_PATROL:
			pos=float3(ci->params[0],ci->params[1]+curHeight,ci->params[2]);
			glColor4f(0.5,0.5,1,0.4);
			glVertexf3(pos);	
			break;
		case CMD_ATTACK:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			} else {
				pos=float3(ci->params[0],ci->params[1]+curHeight,ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			glVertexf3(pos);	
			break;
		case CMD_AREA_ATTACK:
			pos=float3(ci->params[0],ci->params[1]+curHeight,ci->params[2]);
			glColor4f(1,0.1,0.1,0.6);
			glVertexf3(pos);
			if(owner->userTarget){
				glEnd();
				glBegin(GL_LINES);
					glVertexf3(pos);
					glVertexf3(owner->userTarget->pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
			} else if(owner->userAttackGround){
				glEnd();
				glBegin(GL_LINES);
					glVertexf3(pos);
					glVertexf3(owner->userAttackPos);
				glEnd();
				glBegin(GL_LINE_STRIP);
			}
			break;
		case CMD_GUARD:
			if(uh->units[int(ci->params[0])]!=0)
				pos=uh->units[int(ci->params[0])]->pos;
			glColor4f(0.3,0.3,1,0.4);
			glVertexf3(pos);	
			break;
		}
	}
	glEnd();
}
Exemplo n.º 23
0
void CGuiHandler::DrawFront(int button,float maxSize,float sizeDiv)
{
	glDisable(GL_TEXTURE_2D);
	glColor4f(0.5,1,0.5,0.5);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	CMouseHandler::ButtonPress& bp=mouse->buttons[button];
	if(bp.movement<5)
		return;
	float dist=ground->LineGroundCol(bp.camPos,bp.camPos+bp.dir*9000);
	if(dist<0)
		return;
	float3 pos1=bp.camPos+bp.dir*dist;
	dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
	if(dist<0)
		return;
	float3 pos2=camera->pos+mouse->dir*dist;
	float3 forward=(pos1-pos2).cross(UpVector);
	forward.Normalize();
	float3 side=forward.cross(UpVector);
	if(pos1.distance2D(pos2)>maxSize){
		pos2=pos1+side*maxSize;
		pos2.y=ground->GetHeight(pos2.x,pos2.z);
	}

	glDisable(GL_DEPTH_TEST);
	glBegin(GL_QUADS);
		glVertexf3(pos1+side*25);
		glVertexf3(pos1-side*25);
		glVertexf3(pos1-side*25+forward*50);
		glVertexf3(pos1+side*25+forward*50);

		glVertexf3(pos1+side*40+forward*50);
		glVertexf3(pos1-side*40+forward*50);
		glVertexf3(pos1+forward*100);
		glVertexf3(pos1+forward*100);
	glEnd();
	glEnable(GL_DEPTH_TEST);


	pos1+=pos1-pos2;
	glDisable(GL_FOG);
	glBegin(GL_QUADS);
		glVertexf3(pos1-float3(0,-100,0));
		glVertexf3(pos1+float3(0,-100,0));
		glVertexf3(pos2+float3(0,-100,0));
		glVertexf3(pos2-float3(0,-100,0));
	glEnd();

	if(sizeDiv!=0){
		char c[40];
		SNPRINTF(c, 40, "%d", (int)(pos1.distance2D(pos2)/sizeDiv) );
		mouse->cursorTextRight=c;
	}
	glEnable(GL_FOG);
}
Exemplo n.º 24
0
void CGuiHandler::DrawMapStuff(void)
{
	if(activeMousePress){
		int cc=-1;
		int button=SDL_BUTTON_LEFT;
		if(inCommand!=-1){
			cc=inCommand;
		} else {
			if(mouse->buttons[SDL_BUTTON_RIGHT].pressed && mouse->activeReceiver==this){
				cc=defaultCmdMemory;//GetDefaultCommand(mouse->lastx,mouse->lasty);
				button=SDL_BUTTON_RIGHT;
			}
		}

		if(cc>=0 && cc<commands.size()){
			switch(commands[cc].type){
			case CMDTYPE_ICON_FRONT:
				if(mouse->buttons[button].movement>30){
					if(commands[cc].params.size()>0)
						if(commands[cc].params.size()>1)
							DrawFront(button,atoi(commands[cc].params[0].c_str()),atof(commands[cc].params[1].c_str()));
						else
							DrawFront(button,atoi(commands[cc].params[0].c_str()),0);
					else
						DrawFront(button,1000,0);
				}
				break;
			case CMDTYPE_ICON_UNIT_OR_AREA:
			case CMDTYPE_ICON_UNIT_FEATURE_OR_AREA:
			case CMDTYPE_ICON_AREA:{
				float maxRadius=100000;
				if(commands[cc].params.size()==1)
					maxRadius=atof(commands[cc].params[0].c_str());
				if(mouse->buttons[button].movement>4){
					float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*9000);
					if(dist<0){
						break;
					}
					float3 pos=mouse->buttons[button].camPos+mouse->buttons[button].dir*dist;
					dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
					if(dist<0){
						break;
					}
					float3 pos2=camera->pos+mouse->dir*dist;
					DrawArea(pos,min(maxRadius,pos.distance2D(pos2)));
				}
				break;}
			default:
				break;
			}
		}
	}
	//draw buildings we are about to build
	if(inCommand>=0 && inCommand<commands.size() && commands[guihandler->inCommand].type==CMDTYPE_ICON_BUILDING){
		float dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
		if(dist>0){
			string s=commands[guihandler->inCommand].name;
			UnitDef *unitdef = unitDefHandler->GetUnitByName(s);

			if(unitdef){
				float3 pos=camera->pos+mouse->dir*dist;
				std::vector<float3> buildPos;
				if(keys[SDLK_LSHIFT] && mouse->buttons[SDL_BUTTON_LEFT].pressed){
					float dist=ground->LineGroundCol(mouse->buttons[SDL_BUTTON_LEFT].camPos,mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*9000);
					float3 pos2=mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*dist;
					buildPos=GetBuildPos(pos2,pos,unitdef);
				} else {
					buildPos=GetBuildPos(pos,pos,unitdef);
				}

				for(std::vector<float3>::iterator bpi=buildPos.begin();bpi!=buildPos.end();++bpi){
					float3 pos=*bpi;
					if(uh->ShowUnitBuildSquare(pos,unitdef))
						glColor4f(0.7,1,1,0.4);
					else
						glColor4f(1,0.5,0.5,0.4);

					unitDrawer->SetupForGhostDrawing ();
					S3DOModel* model=modelParser->Load3DO((unitdef->model.modelpath).c_str() ,1, gu->myTeam);
					glPushMatrix();
					glTranslatef3(pos);
					//glCallList(model->displist);
					model->DrawStatic();
					unitDrawer->CleanUpGhostDrawing();
					glPopMatrix();
					if(unitdef->weapons.size()>0){	//draw range
						glDisable(GL_TEXTURE_2D);
						glColor4f(1,0.3,0.3,0.7);
						glBegin(GL_LINE_STRIP);
						for(int a=0;a<=40;++a){
							float3 wpos(cos(a*2*PI/40)*unitdef->weapons[0].def->range,0,sin(a*2*PI/40)*unitdef->weapons[0].def->range);
							wpos+=pos;
							float dh=ground->GetHeight(wpos.x,wpos.z)-pos.y;
							float modRange=unitdef->weapons[0].def->range-dh*unitdef->weapons[0].def->heightmod;
							wpos=float3(cos(a*2*PI/40)*(modRange),0,sin(a*2*PI/40)*(modRange));
							wpos+=pos;
							wpos.y=ground->GetHeight(wpos.x,wpos.z)+8;
							glVertexf3(wpos);
						}
						glEnd();
					}
					if(unitdef->extractRange>0){	//draw range
						glDisable(GL_TEXTURE_2D);
						glColor4f(1,0.3,0.3,0.7);
						glBegin(GL_LINE_STRIP);
						for(int a=0;a<=40;++a){
							float3 wpos(cos(a*2*PI/40)*unitdef->extractRange,0,sin(a*2*PI/40)*unitdef->extractRange);
							wpos+=pos;
							wpos.y=ground->GetHeight(wpos.x,wpos.z)+8;
							glVertexf3(wpos);
						}
						glEnd();
					}
				}
			}
		}
	}

	if(keys[SDLK_LSHIFT]){
		CUnit* unit=0;
		float dist2=helper->GuiTraceRay(camera->pos,mouse->dir,9000,unit,20,false);
		if(unit && ((unit->losStatus[gu->myAllyTeam] & LOS_INLOS) || gu->spectating)){		//draw weapon range
			if(unit->maxRange>0){
				glDisable(GL_TEXTURE_2D);
				glColor4f(1,0.3,0.3,0.7);
				glBegin(GL_LINE_STRIP);
				float h=unit->pos.y;
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->maxRange,0,sin(a*2*PI/40)*unit->maxRange);
					pos+=unit->pos;
					float dh=ground->GetHeight(pos.x,pos.z)-h;
					pos=float3(cos(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod),0,sin(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod));
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
			}
			if(unit->unitDef->decloakDistance>0){			//draw decloak distance
				glDisable(GL_TEXTURE_2D);
				glColor4f(0.3,0.3,1,0.7);
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->unitDef->decloakDistance,0,sin(a*2*PI/40)*unit->unitDef->decloakDistance);
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
			}
			if(unit->unitDef->kamikazeDist>0){			//draw self destruct and damage distance
				glDisable(GL_TEXTURE_2D);
				glColor4f(0.8,0.8,0.1,0.7);
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->unitDef->kamikazeDist,0,sin(a*2*PI/40)*unit->unitDef->kamikazeDist);
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
				if(!unit->unitDef->selfDExplosion.empty()){
					glColor4f(0.8,0.1,0.1,0.7);
					WeaponDef* wd=weaponDefHandler->GetWeapon(unit->unitDef->selfDExplosion);

					glBegin(GL_LINE_STRIP);
					for(int a=0;a<=40;++a){
						float3 pos(cos(a*2*PI/40)*wd->areaOfEffect,0,sin(a*2*PI/40)*wd->areaOfEffect);
						pos+=unit->pos;
						pos.y=ground->GetHeight(pos.x,pos.z)+8;
						glVertexf3(pos);
					}
					glEnd();
				}
			}
		}
	}
	//draw range circles if attack orders are imminent
	int defcmd=GetDefaultCommand(mouse->lastx,mouse->lasty);
	if((inCommand>0 && inCommand<commands.size() && commands[inCommand].id==CMD_ATTACK) || (inCommand==-1 && defcmd>0 && commands[defcmd].id==CMD_ATTACK)){
		for(std::set<CUnit*>::iterator si=selectedUnits.selectedUnits.begin();si!=selectedUnits.selectedUnits.end();++si){
			CUnit* unit=*si;
			if(unit->maxRange>0 && ((unit->losStatus[gu->myAllyTeam] & LOS_INLOS) || gu->spectating)){
				glDisable(GL_TEXTURE_2D);
				glColor4f(1,0.3,0.3,0.7);
				glBegin(GL_LINE_STRIP);
				float h=unit->pos.y;
				for(int a=0;a<=40;++a){
					float3 pos(cos(a*2*PI/40)*unit->maxRange,0,sin(a*2*PI/40)*unit->maxRange);
					pos+=unit->pos;
					float dh=ground->GetHeight(pos.x,pos.z)-h;
					pos=float3(cos(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod),0,sin(a*2*PI/40)*(unit->maxRange-dh*unit->weapons.front()->heightMod));
					pos+=unit->pos;
					pos.y=ground->GetHeight(pos.x,pos.z)+8;
					glVertexf3(pos);
				}
				glEnd();
			}
		}
	}
}
Exemplo n.º 25
0
void CMouseHandler::Draw()
{
	dir=hide ? camera->forward : camera->CalcPixelDir(lastx,lasty);
	if(activeReceiver)
		return;

#ifdef DIRECT_CONTROL_ALLOWED
	if(gu->directControl){
		return;
	}
#endif
	if(buttons[SDL_BUTTON_LEFT].pressed && !buttons[SDL_BUTTON_LEFT].chorded &&
	   (buttons[SDL_BUTTON_LEFT].movement > 4) &&
	   mouseHandlerMayDoSelection && (!inMapDrawer || !inMapDrawer->keyPressed)){

		float dist=ground->LineGroundCol(buttons[SDL_BUTTON_LEFT].camPos,
		                                 buttons[SDL_BUTTON_LEFT].camPos
		                                 + buttons[SDL_BUTTON_LEFT].dir*gu->viewRange*1.4f);
		if(dist<0)
			dist=gu->viewRange*1.4f;
		float3 pos1=buttons[SDL_BUTTON_LEFT].camPos+buttons[SDL_BUTTON_LEFT].dir*dist;

		dist=ground->LineGroundCol(camera->pos,camera->pos+dir*gu->viewRange*1.4f);
		if(dist<0)
			dist=gu->viewRange*1.4f;
		float3 pos2=camera->pos+dir*dist;

		float3 dir1=pos1-camera->pos;
		dir1.Normalize();
		float3 dir2=pos2-camera->pos;
		dir2.Normalize();

		float3 dir1S=camera->right*(dir1.dot(camera->right))/dir1.dot(camera->forward);
		float3 dir1U=camera->up*(dir1.dot(camera->up))/dir1.dot(camera->forward);

		float3 dir2S=camera->right*(dir2.dot(camera->right))/dir2.dot(camera->forward);
		float3 dir2U=camera->up*(dir2.dot(camera->up))/dir2.dot(camera->forward);

		glColor4fv(cmdColors.mouseBox);

		glPushAttrib(GL_ENABLE_BIT);

		glDisable(GL_FOG);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_TEXTURE_2D);

		glEnable(GL_BLEND);
		glBlendFunc((GLenum)cmdColors.MouseBoxBlendSrc(),
		            (GLenum)cmdColors.MouseBoxBlendDst());

		glLineWidth(cmdColors.MouseBoxLineWidth());
		glBegin(GL_LINE_LOOP);
		glVertexf3(camera->pos+dir1U*30+dir1S*30+camera->forward*30);
		glVertexf3(camera->pos+dir2U*30+dir1S*30+camera->forward*30);
		glVertexf3(camera->pos+dir2U*30+dir2S*30+camera->forward*30);
		glVertexf3(camera->pos+dir1U*30+dir2S*30+camera->forward*30);
		glEnd();
		glLineWidth(1.0f);
		
		
		glPopAttrib();
	}
}
Exemplo n.º 26
0
void CTransportCAI::DrawCommands(void)
{
	float3 pos=owner->midPos;
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		bool draw=false;
		switch(ci->id){
		case CMD_MOVE:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,1,0.5,0.4);
			draw=true;
			break;
		case CMD_FIGHT:
		case CMD_PATROL:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,0.5,1,0.4);
			draw=true;
			break;
		case CMD_ATTACK:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			} else {
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			draw=true;
			break;
		case CMD_GUARD:
			if(uh->units[int(ci->params[0])]!=0)
				pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			glColor4f(0.3,0.3,1,0.4);
			draw=true;
			break;
		case CMD_LOAD_UNITS:
			glColor4f(0.3,1,1,0.4);
			if(ci->params.size()==4){
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
				float radius=ci->params[3];
				glVertexf3(pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=20;++a){
					float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
					pos2.y=ground->GetHeight(pos2.x,pos2.z);
					glVertexf3(pos2);
				}
				glEnd();
				glBegin(GL_LINE_STRIP);
			} else {
				int id=(int)(ci->params[0]);
				if(uh->units[id]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			}
			draw=true;
			break;
		case CMD_UNLOAD_UNITS:
			glColor4f(1,1,0,0.4);
			if(ci->params.size()==4){
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
				float radius=ci->params[3];
				glVertexf3(pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=20;++a){
					float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
					pos2.y=ground->GetHeight(pos2.x,pos2.z);
					glVertexf3(pos2);
				}
				glEnd();
				glBegin(GL_LINE_STRIP);
			}
			draw=true;
			break;
		case CMD_UNLOAD_UNIT:
			glColor4f(1,1,0,0.4);
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			draw=true;
			break;
		}
		if(draw){
			glVertexf3(pos);	
		}
	}
	glEnd();
}
Exemplo n.º 27
0
void HUDDrawer::DrawTargetReticle(const CUnit* unit)
{
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);

	// draw the reticle in world coordinates
	glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glMultMatrixd(camera->GetProjMat());
	glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glMultMatrixd(camera->GetViewMat());

	glPushMatrix();

		for (unsigned int a = 0; a < unit->weapons.size(); ++a) {
			const CWeapon* w = unit->weapons[a];

			if (!w) {
				continue;
			}
			switch (a) {
				case 0:
					glColor4f(0.0f, 1.0f, 0.0f, 0.7f);
					break;
				case 1:
					glColor4f(1.0f, 0.0f, 0.0f, 0.7f);
					break;
				default:
					glColor4f(0.0f, 0.0f, 1.0f, 0.7f);
			}

			if (w->targetType != Target_None) {
				float3 pos = w->targetPos;
				float3 v1 = (pos-camera->pos).ANormalize();
				float3 v2 = (v1.cross(UpVector)).ANormalize();
				float3 v3 = (v2.cross(v1)).Normalize();
				float radius = 10.0f;

				if (w->targetType == Target_Unit)
					radius = w->targetUnit->radius;

				// draw the reticle
				glBegin(GL_LINE_STRIP);
				for (int b = 0; b <= 80; ++b) {
					glVertexf3(pos + (v2 * fastmath::sin(b * 2 * PI / 80) + v3 * fastmath::cos(b * 2 * PI / 80)) * radius);
				}
				glEnd();

				if (!w->onlyForward) {
					const float dist = std::min(w->owner->directControl->targetDist, w->range * 0.9f);

					pos = w->weaponPos + w->wantedDir * dist;
					v1 = (pos - camera->pos).ANormalize();
					v2 = (v1.cross(UpVector)).ANormalize();
					v3 = (v2.cross(v1)).ANormalize();
					radius = dist / 100.0f;

					glBegin(GL_LINE_STRIP);
					for (int b = 0; b <= 80; ++b) {
						glVertexf3(pos + (v2 * fastmath::sin(b * 2 * PI / 80) + v3 * fastmath::cos(b * 2 * PI / 80)) * radius);
					}
					glEnd();
				}

				glBegin(GL_LINES);
				if (!w->onlyForward) {
					glVertexf3(pos);
					glVertexf3(w->targetPos);

					glVertexf3(pos + (v2 * fastmath::sin(PI * 0.25f) + v3 * fastmath::cos(PI * 0.25f)) * radius);
					glVertexf3(pos + (v2 * fastmath::sin(PI * 1.25f) + v3 * fastmath::cos(PI * 1.25f)) * radius);

					glVertexf3(pos + (v2 * fastmath::sin(PI * -0.25f) + v3 * fastmath::cos(PI * -0.25f)) * radius);
					glVertexf3(pos + (v2 * fastmath::sin(PI * -1.25f) + v3 * fastmath::cos(PI * -1.25f)) * radius);
				}
				if ((w->targetPos - camera->pos).ANormalize().dot(camera->forward) < 0.7f) {
					glVertexf3(w->targetPos);
					glVertexf3(camera->pos + camera->forward * 100.0f);
				}
				glEnd();
			}
		}

	glPopMatrix();
}
Exemplo n.º 28
0
void CPathEstimator::Draw(void)
{
	MoveData* md=moveinfo->GetMoveDataFromName("TANKSH2");
	if(!selectedUnits.selectedUnits.empty() && (*selectedUnits.selectedUnits.begin())->unitDef->movedata)
		md=(*selectedUnits.selectedUnits.begin())->unitDef->movedata;

	glDisable(GL_TEXTURE_2D);
	glColor3f(1,1,0);
/*	float blue=BLOCK_SIZE==32?1:0;
	glBegin(GL_LINES);
	for(int z = 0; z < nbrOfBlocksZ; z++) {
		for(int x = 0; x < nbrOfBlocksX; x++) {
			int blocknr = z * nbrOfBlocksX + x;
			float3 p1;
			p1.x=(blockState[blocknr].sqrCenter[md->pathType].x)*8;
			p1.z=(blockState[blocknr].sqrCenter[md->pathType].y)*8;
			p1.y=ground->GetHeight(p1.x,p1.z)+10;

			glColor3f(1,1,blue);
			glVertexf3(p1);
			glVertexf3(p1-UpVector*10);
			for(int dir = 0; dir < PATH_DIRECTION_VERTICES; dir++){
				int obx = x + directionVector[dir].x;
				int obz = z + directionVector[dir].y;

				if(obx >= 0 && obz >= 0 && obx < nbrOfBlocksX && obz < nbrOfBlocksZ) {
					float3 p2;
					int obblocknr = obz * nbrOfBlocksX + obx;

					p2.x=(blockState[obblocknr].sqrCenter[md->pathType].x)*8;
					p2.z=(blockState[obblocknr].sqrCenter[md->pathType].y)*8;
					p2.y=ground->GetHeight(p2.x,p2.z)+10;

					int vertexNbr = md->pathType * nbrOfBlocks * PATH_DIRECTION_VERTICES + blocknr * PATH_DIRECTION_VERTICES + directionVertex[dir];
					float cost=vertex[vertexNbr];

					glColor3f(1/(sqrt(cost/BLOCK_SIZE)),1/(cost/BLOCK_SIZE),blue);
					glVertexf3(p1);
					glVertexf3(p2);
				}
			}
		}

	}
	glEnd();/**/
/*	glEnable(GL_TEXTURE_2D);
	for(int z = 0; z < nbrOfBlocksZ; z++) {
		for(int x = 0; x < nbrOfBlocksX; x++) {
			int blocknr = z * nbrOfBlocksX + x;
			float3 p1;
			p1.x=(blockState[blocknr].sqrCenter[md->pathType].x)*SQUARE_SIZE;
			p1.z=(blockState[blocknr].sqrCenter[md->pathType].y)*SQUARE_SIZE;
			p1.y=ground->GetHeight(p1.x,p1.z)+10;

			glColor3f(1,1,blue);
			for(int dir = 0; dir < PATH_DIRECTION_VERTICES; dir++){
				int obx = x + directionVector[dir].x;
				int obz = z + directionVector[dir].y;

				if(obx >= 0 && obz >= 0 && obx < nbrOfBlocksX && obz < nbrOfBlocksZ) {
					float3 p2;
					int obblocknr = obz * nbrOfBlocksX + obx;

					p2.x=(blockState[obblocknr].sqrCenter[md->pathType].x)*SQUARE_SIZE;
					p2.z=(blockState[obblocknr].sqrCenter[md->pathType].y)*SQUARE_SIZE;
					p2.y=ground->GetHeight(p2.x,p2.z)+10;

					int vertexNbr = md->pathType * nbrOfBlocks * PATH_DIRECTION_VERTICES + blocknr * PATH_DIRECTION_VERTICES + directionVertex[dir];
					float cost=vertex[vertexNbr];

					glColor3f(1,1/(cost/BLOCK_SIZE),blue);

					p2=(p1+p2)/2;
					if(camera->pos.distance(p2)<500){
						glPushMatrix();
						glTranslatef3(p2);
						glScalef(5,5,5);
						font->glWorldPrint("%.0f",cost);
						glPopMatrix();
					}
				}
			}
		}
	}
*/
	if(BLOCK_SIZE==8)
		glColor3f(0.2f,0.7f,0.2f);
	else
		glColor3f(0.2f,0.2f,0.7f);
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_LINES);
	for(OpenBlock*  ob=openBlockBuffer;ob!=openBlockBufferPointer;++ob){
		int blocknr = ob->blocknr;
		float3 p1;
		p1.x=(blockState[blocknr].sqrCenter[md->pathType].x)*SQUARE_SIZE;
		p1.z=(blockState[blocknr].sqrCenter[md->pathType].y)*SQUARE_SIZE;
		p1.y=ground->GetHeight(p1.x,p1.z)+15;

		float3 p2;
		int obx=blockState[ob->blocknr].parentBlock.x;
		int obz=blockState[ob->blocknr].parentBlock.y;
		int obblocknr =  obz * nbrOfBlocksX + obx;

		if(obblocknr>=0){
			p2.x=(blockState[obblocknr].sqrCenter[md->pathType].x)*SQUARE_SIZE;
			p2.z=(blockState[obblocknr].sqrCenter[md->pathType].y)*SQUARE_SIZE;
			p2.y=ground->GetHeight(p2.x,p2.z)+15;

			glVertexf3(p1);
			glVertexf3(p2);
		}
	}
	glEnd();
/*	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glColor4f(1,0,blue,0.7f);
	glAlphaFunc(GL_GREATER,0.05f);
	int a=0;
	for(OpenBlock*  ob=openBlockBuffer;ob!=openBlockBufferPointer;++ob){
		int blocknr = ob->blocknr;
		float3 p1;
		p1.x=(ob->block.x * BLOCK_SIZE + blockState[blocknr].sqrCenter[md->pathType].x)*SQUARE_SIZE;
		p1.z=(ob->block.y * BLOCK_SIZE + blockState[blocknr].sqrCenter[md->pathType].y)*SQUARE_SIZE;
		p1.y=ground->GetHeight(p1.x,p1.z)+15;

		if(camera->pos.distance(p1)<500){
			glPushMatrix();
			glTranslatef3(p1);
			glScalef(5,5,5);
			font->glWorldPrint("%.0f %.0f",ob->cost,ob->currentCost);
			glPopMatrix();
		}
		++a;
	}
	glDisable(GL_BLEND);*/
}
Exemplo n.º 29
0
void CBuilderCAI::DrawCommands(void)
{
	float3 pos=owner->midPos;
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	glEnable(GL_BLEND);

	if(uh->limitDgun && owner->unitDef->isCommander){
		glColor4f(1,1,1,0.6);
		float3 p=gs->Team(owner->team)->startPos;
		glBegin(GL_LINE_STRIP);
		for(int a=0;a<=40;++a){
			float3 pos2=float3(p.x+sin(a*PI*2/40)*uh->dgunRadius,0,p.z+cos(a*PI*2/40)*uh->dgunRadius);
			pos2.y=ground->GetHeight(pos2.x,pos2.z)+5;
			glVertexf3(pos2);
		}
		glEnd();
	}
	glColor4f(1,1,1,0.4);
	glBegin(GL_LINE_STRIP);
	glVertexf3(pos);
	deque<Command>::iterator ci;
	for(ci=commandQue.begin();ci!=commandQue.end();++ci){
		bool draw=false;
		switch(ci->id){
		case CMD_MOVE:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,1,0.5,0.4);
			draw=true;
			break;
		case CMD_RECLAIM:
		case CMD_RESURRECT:
			if(ci->id==CMD_RECLAIM)
				glColor4f(1,0.2,1,0.4);
			else
				glColor4f(0.2,0.6,1,0.4);

			if(ci->params.size()==4){
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
				float radius=ci->params[3];
				glVertexf3(pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=20;++a){
					float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
					pos2.y=ground->GetHeight(pos2.x,pos2.z)+5;
					glVertexf3(pos2);
				}
				glEnd();
				glBegin(GL_LINE_STRIP);
			} else {
				int id=(int) ci->params[0];
				if(id>=MAX_UNITS){
					if(featureHandler->features[id-MAX_UNITS])
						pos=featureHandler->features[id-MAX_UNITS]->midPos;
				} else {
					if(uh->units[id]!=0 && uh->units[id]!=owner)
						pos=helper->GetUnitErrorPos(uh->units[id],owner->allyteam);
				}
			}
			draw=true;
			break;
		case CMD_PATROL:
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			glColor4f(0.5,0.5,1,0.4);
			draw=true;
			break;
		case CMD_REPAIR:
		case CMD_CAPTURE:
			if(ci->id==CMD_REPAIR)
				glColor4f(0.3,1,1,0.4);
			else
				glColor4f(1,1,0.3,0.4);
			if(ci->params.size()==4){
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
				float radius=ci->params[3];
				glVertexf3(pos);
				glEnd();
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=20;++a){
					float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
					pos2.y=ground->GetHeight(pos2.x,pos2.z);
					glVertexf3(pos2);
				}
				glEnd();
				glBegin(GL_LINE_STRIP);
			} else {
				int id=(int) ci->params[0];
				if(uh->units[id]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			}
			draw=true;
			break;
		case CMD_RESTORE:{
			glColor4f(0.3,1,0.5,0.4);
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			float radius=ci->params[3];
			glVertexf3(pos);
			glEnd();
			glBegin(GL_LINE_STRIP);
			for(int a=0;a<=20;++a){
				float3 pos2=float3(pos.x+sin(a*PI*2/20)*radius,0,pos.z+cos(a*PI*2/20)*radius);
				pos2.y=ground->GetHeight(pos2.x,pos2.z);
				glVertexf3(pos2);
			}
			glEnd();
			glBegin(GL_LINE_STRIP);
			draw=true;
			break;}
		case CMD_GUARD:
			if(uh->units[int(ci->params[0])]!=0)
				pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			glColor4f(0.3,0.3,1,0.4);
			draw=true;
			break;
		case CMD_ATTACK:
		case CMD_DGUN:
			if(ci->params.size()==1){
				if(uh->units[int(ci->params[0])]!=0)
					pos=helper->GetUnitErrorPos(uh->units[int(ci->params[0])],owner->allyteam);
			} else {
				pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			}
			glColor4f(1,0.5,0.5,0.4);
			draw=true;
			break;
		}
		map<int,string>::iterator boi;
		if((boi=buildOptions.find(ci->id))!=buildOptions.end()){
			pos=float3(ci->params[0],ci->params[1],ci->params[2]);
			UnitDef *unitdef = unitDefHandler->GetUnitByName(boi->second);

			glColor4f(1,1,1,0.4);
			glVertexf3(pos);
			glEnd();

			pos=helper->Pos2BuildPos(pos,unitdef);

			if(unitdef->extractRange>0){	//draw range
				glDisable(GL_TEXTURE_2D);
				glColor4f(1,0.3,0.3,0.7);
				glBegin(GL_LINE_STRIP);
				for(int a=0;a<=40;++a){
					float3 wpos(cos(a*2*PI/40)*unitdef->extractRange,0,sin(a*2*PI/40)*unitdef->extractRange);
					wpos+=pos;
					wpos.y=ground->GetHeight(wpos.x,wpos.z)+8;
					glVertexf3(wpos);
				}
				glEnd();
			}

			glColor4f(1,1,1,0.3);
			unitDrawer->DrawBuildingSample(unitdef, owner->team, pos);

			glColor4f(1,1,1,0.4);
			glBegin(GL_LINE_STRIP);
			draw=true;
		}
		if(draw){
			glVertexf3(pos);	
		}
	}
	glEnd();
}
Exemplo n.º 30
0
void CStartPosSelecter::Draw()
{
	if(gu->spectating){
		delete this;
		return;
	}

	glPushMatrix();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glMatrixMode(GL_MODELVIEW);

	glColor4f(0.2f,0.8f,0.2f,0.5f);
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
	glBegin(GL_QUADS);
	float by= gameSetup->allyStartingData[gu->myAllyTeam].startRectTop *gs->mapy*8;
	float bx= gameSetup->allyStartingData[gu->myAllyTeam].startRectLeft *gs->mapx*8;

	float dy = (gameSetup->allyStartingData[gu->myAllyTeam].startRectBottom - gameSetup->allyStartingData[gu->myAllyTeam].startRectTop) *gs->mapy*8/10;
	float dx = (gameSetup->allyStartingData[gu->myAllyTeam].startRectRight - gameSetup->allyStartingData[gu->myAllyTeam].startRectLeft) *gs->mapx*8/10;

	for(int a=0;a<10;++a){	//draw start rect restrictions
		float3 pos1(bx+a*dx,0,by);
		pos1.y=ground->GetHeight(pos1.x,pos1.z);
		float3 pos2(bx+(a+1)*dx,0,by);
		pos2.y=ground->GetHeight(pos2.x,pos2.z);

		glVertexf3(pos1);
		glVertexf3(pos2);
		glVertexf3(pos2+UpVector*100);
		glVertexf3(pos1+UpVector*100);

		pos1=float3(bx+a*dx,0,by+dy*10);
		pos1.y=ground->GetHeight(pos1.x,pos1.z);
		pos2=float3(bx+(a+1)*dx,0,by+dy*10);
		pos2.y=ground->GetHeight(pos2.x,pos2.z);

		glVertexf3(pos1);
		glVertexf3(pos2);
		glVertexf3(pos2+UpVector*100);
		glVertexf3(pos1+UpVector*100);

		pos1=float3(bx,0,by+dy*a);
		pos1.y=ground->GetHeight(pos1.x,pos1.z);
		pos2=float3(bx,0,by+dy*(a+1));
		pos2.y=ground->GetHeight(pos2.x,pos2.z);

		glVertexf3(pos1);
		glVertexf3(pos2);
		glVertexf3(pos2+UpVector*100);
		glVertexf3(pos1+UpVector*100);

		pos1=float3(bx+dx*10,0,by+dy*a);
		pos1.y=ground->GetHeight(pos1.x,pos1.z);
		pos2=float3(bx+dx*10,0,by+dy*(a+1));
		pos2.y=ground->GetHeight(pos2.x,pos2.z);

		glVertexf3(pos1);
		glVertexf3(pos2);
		glVertexf3(pos2+UpVector*100);
		glVertexf3(pos1+UpVector*100);
	}
	glEnd();

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glDisable(GL_DEPTH_TEST);

	float mx=float(mouse->lastx)/gu->viewSizeX;
	float my=(gu->viewSizeY-float(mouse->lasty))/gu->viewSizeY;

	glDisable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glDisable(GL_ALPHA_TEST);

	if (!showReady) {
		return;
	}

	if (InBox(mx, my, readyBox)) {
		glColor4f(0.7f, 0.2f, 0.2f, guiAlpha);
	} else {
		glColor4f(0.7f, 0.7f, 0.2f, guiAlpha);
	}
	DrawBox(readyBox);

	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	if (InBox(mx, my, readyBox)) {
		glColor4f(0.7f, 0.2f, 0.2f, guiAlpha);
	} else {
		glColor4f(0.7f, 0.7f, 0.2f, guiAlpha);
	}
	DrawBox(readyBox);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// fit text into box
	const float unitWidth  = font->GetSize() * font->GetTextWidth("Ready") * gu->pixelX;
	const float unitHeight = font->GetSize() * font->GetLineHeight() * gu->pixelY;

	const float ySize = (readyBox.y2 - readyBox.y1);
	const float xSize = (readyBox.x2 - readyBox.x1);

	const float fontScale = 0.9f * std::min(xSize/unitWidth, ySize/unitHeight);
	const float yPos = 0.5f * (readyBox.y1 + readyBox.y2);
	const float xPos = 0.5f * (readyBox.x1 + readyBox.x2);

	font->Begin(); 
	font->SetColors(); // default
	font->glPrint(xPos, yPos, fontScale, FONT_OUTLINE | FONT_CENTER | FONT_VCENTER | FONT_SCALE | FONT_NORM, "Ready");
	font->End(); 
}