예제 #1
0
static inline void DrawObjectMidAndAimPos(const CSolidObject* o)
{
	GLUquadricObj* q = gluNewQuadric();
	glDisable(GL_DEPTH_TEST);

	if (o->aimPos != o->midPos) {
		// draw the aim-point
		glPushMatrix();
		glTranslatef3(o->relAimPos * WORLD_TO_OBJECT_SPACE);
		glColor3f(1.0f, 0.0f, 0.0f);
		gluQuadricDrawStyle(q, GLU_FILL);
		gluSphere(q, 2.0f, 5, 5);
		glPopMatrix();
	}

	{
		// draw the mid-point, keep this transform on the stack
		glTranslatef3(o->relMidPos * WORLD_TO_OBJECT_SPACE);
		glColor3f(1.0f, 0.0f, 1.0f);
		gluQuadricDrawStyle(q, GLU_FILL);
		gluSphere(q, 2.0f, 5, 5);
		glColorf3(DEFAULT_VOLUME_COLOR);
	}

	glEnable(GL_DEPTH_TEST);
	gluDeleteQuadric(q);
}
예제 #2
0
void CRoamMeshDrawer::DrawInMiniMap()
{
	glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0, -1.0);
		minimap->ApplyConstraintsMatrix();
	glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glTranslatef3(UpVector);
		glScalef(1.0f / gs->mapx, -1.0f / gs->mapy, 1.0f);

	glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
	for (std::vector<Patch>::iterator it = roamPatches.begin(); it != roamPatches.end(); ++it) {
		if (!it->IsVisible()) {
			glRectf(it->m_WorldX, it->m_WorldY, it->m_WorldX + PATCH_SIZE, it->m_WorldY + PATCH_SIZE);
		}
	}

	glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
}
예제 #3
0
static inline void DrawFeatureColVol(const CFeature* f)
{
	if (f->collisionVolume && !f->collisionVolume->IsDisabled()) {
		if (!f->IsInLosForAllyTeam(gu->myAllyTeam) && !gu->spectatingFullView) return;
		if (!camera->InView(f->pos, f->drawRadius)) return;

		glPushMatrix();
			glMultMatrixf(f->transMatrix.m);
			glTranslatef3(f->relMidPos * float3(-1.0f, 1.0f, 1.0f));

			GLUquadricObj* q = gluNewQuadric();

			// draw the centerpos
			glColor3f(1.0f, 0.0f, 1.0f);
			gluQuadricDrawStyle(q, GLU_FILL);
			gluSphere(q, 2.0f, 5, 5);

			glColorf3(defaultColVolColor);
			gluQuadricDrawStyle(q, GLU_LINE);

			DrawCollisionVolume(f->collisionVolume, q);

			gluDeleteQuadric(q);
		glPopMatrix();
	}
}
예제 #4
0
void InMapDraw_QuadDrawer::DrawQuad (int x,int y)
{
	int drawQuadsX = imd->drawQuadsX;
	CInMapDraw::DrawQuad* dq=&imd->drawQuads[y*drawQuadsX+x];

	for(std::list<CInMapDraw::MapPoint>::iterator pi=dq->points.begin();pi!=dq->points.end();++pi){
		float3 pos=pi->pos;

		float3 dif(pos-camera->pos);
		float camDist=dif.Length();
		dif/=camDist;
		float3 dir1(dif.cross(UpVector));
		dir1.Normalize();
		float3 dir2(dif.cross(dir1));

		unsigned char col[4];
		col[0]=pi->color[0];
		col[1]=pi->color[1];
		col[2]=pi->color[2];
		col[3]=200;//intensity*255;

		float size=6;

		float3 pos1=pos;
		float3 pos2=pos1;
		pos2.y+=100;

		va->AddVertexTC(pos1-dir1*size,					  0.25f,0,col);
		va->AddVertexTC(pos1+dir1*size,					  0.25f,1,col);
		va->AddVertexTC(pos1+dir1*size+dir2*size, 0.00f,1,col);
		va->AddVertexTC(pos1-dir1*size+dir2*size, 0.00f,0,col);

		va->AddVertexTC(pos1-dir1*size,0.75f,0,col);
		va->AddVertexTC(pos1+dir1*size,0.75f,1,col);
		va->AddVertexTC(pos2+dir1*size,0.75f,1,col);
		va->AddVertexTC(pos2-dir1*size,0.75f,0,col);

		va->AddVertexTC(pos2-dir1*size,					  0.25f,0,col);
		va->AddVertexTC(pos2+dir1*size,					  0.25f,1,col);
		va->AddVertexTC(pos2+dir1*size-dir2*size, 0.00f,1,col);
		va->AddVertexTC(pos2-dir1*size-dir2*size, 0.00f,0,col);

		if(pi->label.size()>0){
			glPushMatrix();
			glTranslatef3(pi->pos+UpVector*105);
			glScalef(30,30,30);
			glColor4ub(pi->color[0],pi->color[1],pi->color[2],250);
			font->glWorldPrint("%s",pi->label.c_str());
			glPopMatrix();
			glBindTexture(GL_TEXTURE_2D, texture);
		}
	}
	for(std::list<CInMapDraw::MapLine>::iterator li=dq->lines.begin();li!=dq->lines.end();++li){
		lineva->AddVertexC(li->pos-(li->pos - camera->pos).Normalize()*26,li->color);
		lineva->AddVertexC(li->pos2-(li->pos2 - camera->pos).Normalize()*26,li->color);
	}
}
static inline void DrawFeatureColVol(const CFeature* f)
{
	const CollisionVolume* v = &f->collisionVolume;

	if (f->IsInVoid())
		return;
	if (!f->IsInLosForAllyTeam(gu->myAllyTeam) && !gu->spectatingFullView)
		return;
	if (!camera->InView(f->pos, f->GetDrawRadius()))
		return;

	const bool vCustomType = (v->GetVolumeType() < CollisionVolume::COLVOL_TYPE_SPHERE);
	const bool vCustomDims = ((v->GetOffsets()).SqLength() >= 1.0f || math::fabs(v->GetBoundingRadius() - f->radius) >= 1.0f);

	glPushMatrix();
		glMultMatrixf(f->GetTransformMatrixRef());
		DrawObjectMidAndAimPos(f);

		if (v->DefaultToPieceTree()) {
			// draw only the piece volumes for less clutter
			// note: relMidPos transform is on the stack at this
			// point but all piece-positions are relative to pos
			// --> undo it
			glTranslatef3(-f->relMidPos * WORLD_TO_OBJECT_SPACE);
			DrawObjectDebugPieces(f);
			glTranslatef3(f->relMidPos * WORLD_TO_OBJECT_SPACE);
		} else {
			if (!v->IgnoreHits()) {
				DrawCollisionVolume(v);
			}
		}

		if (vCustomType || vCustomDims) {
			// assume this is a custom volume
			glColor4f(0.5f, 0.5f, 0.5f, 0.35f);
			glScalef(f->radius, f->radius, f->radius);
			glWireSphere(&volumeDisplayListIDs[0], 20, 20);
		}
	glPopMatrix();
}
예제 #6
0
void DefaultPathDrawer::DrawInMiniMap()
{
	const CBaseGroundDrawer* gd = readMap->GetGroundDrawer();
	const CPathEstimator* pe = pm->medResPE;
	const MoveDef* md = GetSelectedMoveDef();

	if (md == NULL)
		return;

	if (gd->GetDrawMode() < CBaseGroundDrawer::drawPathTrav)
		return;
	if (gd->GetDrawMode() > CBaseGroundDrawer::drawPathCost)
		return;

	glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f);
		glTranslatef((float)minimap->GetPosX() * globalRendering->pixelX, (float)minimap->GetPosY() * globalRendering->pixelY, 0.0f);
		glScalef((float)minimap->GetSizeX() * globalRendering->pixelX, (float)minimap->GetSizeY() * globalRendering->pixelY, 1.0f);
	glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glTranslatef3(UpVector);
		glScalef(1.0f / gs->mapx, -1.0f / gs->mapy, 1.0f);

	glDisable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 0.0f, 0.7f);

	for (const CPathEstimator::SingleBlock& sb: pe->updatedBlocks) {
		if (sb.moveDef == md) {
			const int blockIdxX = sb.blockPos.x * pe->GetBlockSize();
			const int blockIdxY = sb.blockPos.y * pe->GetBlockSize();
			glRectf(blockIdxX, blockIdxY, blockIdxX + pe->GetBlockSize(), blockIdxY + pe->GetBlockSize());
		}
	}
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glEnable(GL_TEXTURE_2D);

	glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
}
예제 #7
0
static inline void DrawUnitColVol(const CUnit* unit)
{
	if (!(unit->losStatus[gu->myAllyTeam] & LOS_INLOS) && !gu->spectatingFullView) return;
	if (!camera->InView(unit->drawMidPos, unit->drawRadius)) return;

	glPushMatrix();
		glMultMatrixf(unit->GetTransformMatrix());
		glTranslatef3(unit->relMidPos * float3(-1.0f, 1.0f, 1.0f));

		GLUquadricObj* q = gluNewQuadric();

		// draw the aimpoint
		glColor3f(1.0f, 0.0f, 1.0f);
		gluQuadricDrawStyle(q, GLU_FILL);
		gluSphere(q, 2.0f, 5, 5);

		glColorf3(defaultColVolColor);
		gluQuadricDrawStyle(q, GLU_LINE);

		if (unit->unitDef->usePieceCollisionVolumes) {
			//! draw only the piece volumes for less clutter
			CMatrix44f mat(unit->relMidPos * float3(0.0f, -1.0f, 0.0f));
			DrawUnitDebugPieceTree(unit->localmodel->GetRoot(), unit->lastAttackedPiece, unit->lastAttackedPieceFrame, mat, q);
		} else {
			if (!unit->collisionVolume->IsDisabled()) {
				//! make it fade red under attack
				if (unit->lastAttack > 0 && ((gs->frameNum - unit->lastAttack) < 150)) {
					glColor3f((1.0f - ((gs->frameNum - unit->lastAttack) / 150.0f)), 0.0f, 0.0f);
				}

				DrawCollisionVolume(unit->collisionVolume, q);

				if (unit->lastAttack > 0 && ((gs->frameNum - unit->lastAttack) < 150)) {
					glColorf3(defaultColVolColor);
				}
			}
		}

		gluDeleteQuadric(q);
	glPopMatrix();
}
예제 #8
0
void CGrassDrawer::DrawNear(const std::vector<InviewNearGrass>& inviewGrass)
{
	for (const InviewNearGrass& g: inviewGrass) {
		rng.Seed(g.y * mapDims.mapx / grassSquareSize + g.x);
//		const float distSq = GetCamDistOfGrassBlock(g.x, g.y, true);
		const float rdist  = 1.0f + rng.RandFloat() * 0.5f;
		const float alpha  = linearstep(maxDetailedDist, maxDetailedDist + 128.f * rdist, g.dist);

		for (int a = 0; a < numTurfs; a++) {
			const STurfParams& p = GetTurfParams(rng, g.x, g.y);
			float3 pos(p.x, CGround::GetHeightReal(p.x, p.y, false), p.y);
				pos.y -= CGround::GetSlope(p.x, p.y, false) * 30.0f;
				pos.y -= 2.0f * mapInfo->grass.bladeHeight * alpha;

			glPushMatrix();
			glTranslatef3(pos);
			glRotatef(p.rotation, 0.0f, 1.0f, 0.0f);
			glCallList(grassDL);
			glPopMatrix();
		}
	}
}
예제 #9
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();
			}
		}
	}
}
예제 #10
0
bool CProjectileDrawer::DrawProjectileModel(const CProjectile* p, bool shadowPass) {
	if (!(p->weapon || p->piece) || (p->model == NULL)) {
		return false;
	}

	if (p->weapon) {
		// weapon-projectile
		const CWeaponProjectile* wp = dynamic_cast<const CWeaponProjectile*>(p);

		#define SET_TRANSFORM_VECTORS(dir)           \
			float3 rightdir, updir;                  \
                                                     \
			if (fabs(dir.y) < 0.95f) {               \
				rightdir = dir.cross(UpVector);      \
				rightdir.SafeANormalize();           \
			} else {                                 \
				rightdir = float3(1.0f, 0.0f, 0.0f); \
			}                                        \
                                                     \
			updir = rightdir.cross(dir);

		#define TRANSFORM_DRAW(mat)                                \
			glPushMatrix();                                        \
				glMultMatrixf(mat);                                \
				glCallList(wp->model->GetRootPiece()->dispListID); \
			glPopMatrix();

		switch (wp->GetProjectileType()) {
			case CWeaponProjectile::WEAPON_BASE_PROJECTILE:
			case CWeaponProjectile::WEAPON_EXPLOSIVE_PROJECTILE: 
			case CWeaponProjectile::WEAPON_LASER_PROJECTILE:
			case CWeaponProjectile::WEAPON_TORPEDO_PROJECTILE: {
				if (!shadowPass) {
					unitDrawer->SetTeamColour(wp->colorTeam);
				}

				float3 dir(wp->speed);
				dir.SafeANormalize();
				SET_TRANSFORM_VECTORS(dir);

				CMatrix44f transMatrix(wp->drawPos, -rightdir, updir, dir);

				TRANSFORM_DRAW(transMatrix);
			} break;

			case CWeaponProjectile::WEAPON_MISSILE_PROJECTILE: {
				if (!shadowPass) {
					unitDrawer->SetTeamColour(wp->colorTeam);
				}

				SET_TRANSFORM_VECTORS(wp->dir);

				CMatrix44f transMatrix(wp->drawPos + wp->dir * wp->radius * 0.9f, -rightdir, updir, wp->dir);

				TRANSFORM_DRAW(transMatrix);
			} break;

			case CWeaponProjectile::WEAPON_STARBURST_PROJECTILE: {
				if (!shadowPass) {
					unitDrawer->SetTeamColour(wp->colorTeam);
				}

				SET_TRANSFORM_VECTORS(wp->dir);

				CMatrix44f transMatrix(wp->drawPos, -rightdir, updir, wp->dir);

				TRANSFORM_DRAW(transMatrix);
			} break;

			default: {
			} break;
		}

		#undef SET_TRANSFORM_VECTORS
		#undef TRANSFORM_DRAW
	} else {
		// piece-projectile
		const CPieceProjectile* pp = dynamic_cast<const CPieceProjectile*>(p);

		if (!shadowPass) {
			unitDrawer->SetTeamColour(pp->colorTeam);
		}

		if (pp->alphaThreshold != 0.1f) {
			glPushAttrib(GL_COLOR_BUFFER_BIT);
			glAlphaFunc(GL_GEQUAL, pp->alphaThreshold);
		}

		glPushMatrix();
			glTranslatef3(pp->pos);
			glRotatef(pp->spinAngle, pp->spinVec.x, pp->spinVec.y, pp->spinVec.z);
			glCallList(pp->dispList);
		glPopMatrix();

		if (pp->alphaThreshold != 0.1f) {
			glPopAttrib();
		}
	}

	return true;
}
예제 #11
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();
			}

			unitDrawer->SetupForGhostDrawing();
			glColor4f(1,1,1,0.3);
			S3DOModel* model=modelParser->Load3DO(unitdef->model.modelpath.c_str() ,1, owner->team);
			glPushMatrix();
			glTranslatef3(pos);
			//glCallList(model->displist);
			model->DrawStatic();
			unitDrawer->CleanUpGhostDrawing();

			glPopMatrix();
			glColor4f(1,1,1,0.4);
			glBegin(GL_LINE_STRIP);
			draw=true;
		}
		if(draw){
			glVertexf3(pos);	
		}
	}
	glEnd();
}
예제 #12
0
파일: UnitDrawer.cpp 프로젝트: arlukin/dev
void CUnitDrawer::Draw()
{
#ifdef PROFILE_TIME
	LARGE_INTEGER start;
	QueryPerformanceCounter(&start);
#endif
	scaleFactor=1/(65536.0);
	glDisable(GL_CULL_FACE);
	glDisable(GL_BLEND);
	texturehandler->SetTexture();
	glDisable(GL_ALPHA_TEST);
	glEnable(GL_TEXTURE_2D);
//	(*info) << g.shared->numPlayers << " " << g.shared->maxUnits << " " << g.shared->players[0].maxUsedUnit << "\n";
//	(*info) << g.shared->units[0].active << " " << g.shared->units[0].name << "\n";
//	(*info) << g.shared->units[0].pos.x*scaleFactor << " " << g.shared->units[0].pos.y*scaleFactor << " " << g.shared->units[0].pos.z*scaleFactor << "\n";
	for(int p=0;p<g.shared->numPlayers;++p){
		int maxUsed=p * g.shared->maxUnits + g.shared->players[p].maxUsedUnit;
		for(int u=p*g.shared->maxUnits;u<maxUsed;++u){
			if(g.shared->units[u].active && g.shared->units[u].name[0]!=0){
				curUnit=&g.shared->units[u];

				float3 pos(curUnit->pos.x*scaleFactor,curUnit->pos.z*scaleFactor,curUnit->pos.y*scaleFactor);

				if(camera.InView(pos,80)){
					if(curUnit->beingBuilt){
/*						float complete=(1065353216-curUnit->beingBuilt)/1000.0;

						GLfloat gld[]=	{ 0.7f*complete, 1.4f*(1-complete)+0.7f*complete, 0.7f*complete, 1.0f };
						GLfloat gla[]=	{ 0.3f*complete, 0.6f*(1-complete)+0.3f*complete, 0.3f*complete, 1.0f };
*/						glLightfv(GL_LIGHT1, GL_AMBIENT, GreenLightAmbient);
						glLightfv(GL_LIGHT1, GL_DIFFUSE, GreenLightDiffuse);
						glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
						greenLight=true;
					} else {
						if(greenLight){
							greenLight=false;
							glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbientLand);		// Setup The Ambient Light
							glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuseLand);		// Setup The Diffuse Light
							glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
						}
					}
					glPushMatrix();
					glTranslatef3(pos);
					if(curUnit->turn.x!=0)
						glRotatef(curUnit->turn.x*(360.0f*(1/65536.0f)),0,1,0);
					if(curUnit->turn.y!=0)
						glRotatef(curUnit->turn.y*(360.0f*(1/65536.0f)),-1,0,0);
					if(curUnit->turn.z!=0)
						glRotatef(curUnit->turn.z*(360.0f*(1/65536.0f)),0,0,1);
					S3DO* model;
					if(strcmp(prevUnits[u].name,curUnit->name)==0){
						model=prevUnits[u].model;
					} else {
						model=unitparser->Load3DO((string("objects3d\\")+curUnit->name+".3do").c_str(),1,g.shared->players[p].color);
						prevUnits[u].model=model;
						strcpy(prevUnits[u].name,curUnit->name);
					}
					curPart=0;
					DrawPart(model);
					glPopMatrix();
					if(drawHealth){
						glTexCoord2f(PlasmaMidX,PlasmaMidY);
						glNormal3f(0,0.7f,0.7f);
						float h=curUnit->health/100.0;
						glColor3f(0.3f+(1-h),0.3+h*0.7,0.3f);
						float3 up(0,1,0);
						glBegin(GL_QUADS);
							glVertexf3(pos+camera.right*-9+up*(model->size+2)+camera.up*2);
							glVertexf3(pos+camera.right*(h*18-9)+up*(model->size+2)+camera.up*2);
							glVertexf3(pos+camera.right*(h*18-9)+up*(model->size+2));
							glVertexf3(pos+camera.right*-9+up*(model->size+2));
							glColor3f(0,0,0);
							glVertexf3(pos+camera.right*9+up*(model->size+2)+camera.up*2);
							glVertexf3(pos+camera.right*(h*18-9)+up*(model->size+2)+camera.up*2);
							glVertexf3(pos+camera.right*(h*18-9)+up*(model->size+2));
							glVertexf3(pos+camera.right*9+up*(model->size+2));
						glEnd();
					}
					if(drawKills && curUnit->kills){
						if(curUnit->kills>4)
							glColor3f(2,2.0,2.0);
						else
							glColor3f(2,0.5,0.5);
						glPushMatrix();
						glEnable(GL_ALPHA_TEST);
						glEnable(GL_BLEND);
						float3 up(0,1,0);
						glTranslatef3(pos+up*(model->size+4)-camera.right*2);
						glScalef(8,8,8);
						font->glWorldPrint("%d",curUnit->kills);						
						glDisable(GL_BLEND);
						glDisable(GL_ALPHA_TEST);
						glPopMatrix();
						texturehandler->SetTexture();
					}
					if(drawName && model->writeName){
						glColor3f(2,2.0,2.0);
						glPushMatrix();
						glEnable(GL_ALPHA_TEST);
						glEnable(GL_BLEND);
						float3 up(0,1,0);
						glTranslatef3(pos+up*(model->size+10)-camera.right*2);
						glScalef(8,8,8);
						font->glWorldPrint("%s",g.shared->players[p].name);						
						glDisable(GL_BLEND);
						glDisable(GL_ALPHA_TEST);
						glPopMatrix();
						texturehandler->SetTexture();						
					}
				}
			}
		}
	}
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbientLand);		// Setup The Ambient Light
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuseLand);		// Setup The Diffuse Light
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
#ifdef PROFILE_TIME
	LARGE_INTEGER stop;
	QueryPerformanceCounter(&stop);
	profiler.AddTime("Drawing units",stop.QuadPart - start.QuadPart);
#endif
}
예제 #13
0
void CInMapDraw::Draw(void)
{
	glDepthMask(0);

	CVertexArray* va=GetVertexArray();
	va->Initialize();

	CVertexArray* lineva=GetVertexArray();
	lineva->Initialize();

	int cx=(int)(camera->pos.x/(SQUARE_SIZE*DRAW_QUAD_SIZE));
	int cy=(int)(camera->pos.z/(SQUARE_SIZE*DRAW_QUAD_SIZE));

	float drawDist=3000;
	int drawSquare=int(drawDist/(SQUARE_SIZE*DRAW_QUAD_SIZE))+1;

	int sy=cy-drawSquare;
	if(sy<0)
		sy=0;
	int ey=cy+drawSquare;
	if(ey>drawQuadsY-1)
		ey=drawQuadsY-1;

	for(int y=sy;y<=ey;y++){
		int sx=cx-drawSquare;
		if(sx<0)
			sx=0;
		int ex=cx+drawSquare;
		if(ex>drawQuadsX-1)
			ex=drawQuadsX-1;
		float xtest,xtest2;
		std::vector<CBaseGroundDrawer::fline>::iterator fli;
		for(fli=groundDrawer->left.begin();fli!=groundDrawer->left.end();fli++){
			xtest=((fli->base/SQUARE_SIZE+fli->dir*(y*DRAW_QUAD_SIZE)));
			xtest2=((fli->base/SQUARE_SIZE+fli->dir*((y*DRAW_QUAD_SIZE)+DRAW_QUAD_SIZE)));
			if(xtest>xtest2)
				xtest=xtest2;
			xtest=xtest/DRAW_QUAD_SIZE;
			if(xtest>sx)
				sx=(int)xtest;
		}
		for(fli=groundDrawer->right.begin();fli!=groundDrawer->right.end();fli++){
			xtest=((fli->base/SQUARE_SIZE+fli->dir*(y*DRAW_QUAD_SIZE)));
			xtest2=((fli->base/SQUARE_SIZE+fli->dir*((y*DRAW_QUAD_SIZE)+DRAW_QUAD_SIZE)));
			if(xtest<xtest2)
				xtest=xtest2;
			xtest=xtest/DRAW_QUAD_SIZE;
			if(xtest<ex)
				ex=(int)xtest;
		}
		for(int x=sx;x<=ex;x++){/**/
			DrawQuad* dq=&drawQuads[y*drawQuadsX+x];

			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			glEnable(GL_TEXTURE_2D);
			glEnable(GL_BLEND);

			glBindTexture(GL_TEXTURE_2D,texture);

			for(std::list<MapPoint>::iterator pi=dq->points.begin();pi!=dq->points.end();++pi){
				float3 pos=pi->pos;

				float3 dif(pos-camera->pos);
				float camDist=dif.Length();
				dif/=camDist;
				float3 dir1(dif.cross(UpVector));
				dir1.Normalize();
				float3 dir2(dif.cross(dir1));

				unsigned char col[4];
				col[0]=pi->color[0];
				col[1]=pi->color[1];
				col[2]=pi->color[2];
				col[3]=200;//intensity*255;

				float size=6;

				float3 pos1=pos;
				float3 pos2=pos1;
				pos2.y+=100;

				va->AddVertexTC(pos1-dir1*size,					  0.25,0,col);
				va->AddVertexTC(pos1+dir1*size,					  0.25,1,col);
				va->AddVertexTC(pos1+dir1*size+dir2*size, 0.00,1,col);
				va->AddVertexTC(pos1-dir1*size+dir2*size, 0.00,0,col);

				va->AddVertexTC(pos1-dir1*size,0.75,0,col);
				va->AddVertexTC(pos1+dir1*size,0.75,1,col);
				va->AddVertexTC(pos2+dir1*size,0.75,1,col);
				va->AddVertexTC(pos2-dir1*size,0.75,0,col);

				va->AddVertexTC(pos2-dir1*size,					  0.25,0,col);
				va->AddVertexTC(pos2+dir1*size,					  0.25,1,col);
				va->AddVertexTC(pos2+dir1*size-dir2*size, 0.00,1,col);
				va->AddVertexTC(pos2-dir1*size-dir2*size, 0.00,0,col);

				if(pi->label.size()>0){
					glPushMatrix();
					glTranslatef3(pi->pos+UpVector*105);
					glScalef(30,30,30);
					glColor4ub(pi->color[0],pi->color[1],pi->color[2],250);
					font->glWorldPrint("%s",pi->label.c_str());
					glPopMatrix();
				}
			}
			for(std::list<MapLine>::iterator li=dq->lines.begin();li!=dq->lines.end();++li){
				lineva->AddVertexC(li->pos-(li->pos - camera->pos).Normalize()*26,li->color);
				lineva->AddVertexC(li->pos2-(li->pos2 - camera->pos).Normalize()*26,li->color);
			}
		}
	}

	glDisable(GL_TEXTURE_2D);
	glLineWidth(3);
	lineva->DrawArrayC(GL_LINES);
	glLineWidth(1);
	glEnable(GL_TEXTURE_2D);
	va->DrawArrayTC(GL_QUADS);
	glDepthMask(1);
}
예제 #14
0
void CUnit::DrawStats()
{
    if(gu->myAllyTeam!=allyteam && !gu->spectating && unitDef->hideDamage) {
        return;
    }

    float3 interPos=pos+speed*gu->timeOffset;
    interPos.y+=model->height+5;

    glBegin(GL_QUADS);

    float hpp = health/maxHealth;
    float end=(0.5-(hpp))*10;

    //black background for healthbar
    glColor3f(0.0,0.0,0.0);
    glVertexf3(interPos+(camera->up*6-camera->right*end));
    glVertexf3(interPos+(camera->up*6+camera->right*5));
    glVertexf3(interPos+(camera->up*4+camera->right*5));
    glVertexf3(interPos+(camera->up*4-camera->right*end));

    if(stunned) {
        glColor3f(0,0,1.0);
    } else {
        if(hpp>0.5f)
            glColor3f(1.0f-((hpp-0.5f)*2.0f),1.0f,0.0);
        else
            glColor3f(1.0f,hpp*2.0f,0.0);
    }
    //healthbar
    glVertexf3(interPos+(camera->up*6-camera->right*5));
    glVertexf3(interPos+(camera->up*6-camera->right*end));
    glVertexf3(interPos+(camera->up*4-camera->right*end));
    glVertexf3(interPos+(camera->up*4-camera->right*5));

    if(gu->myTeam!=team && !gu->spectating) {
        glEnd();
        return;
    }
    glColor3f(1,1,1);
    end=(limExperience*0.8f)*10;
    glVertexf3(interPos+(-camera->up*2+camera->right*6));
    glVertexf3(interPos+(-camera->up*2+camera->right*8));
    glVertexf3(interPos+(camera->up*(end-2)+camera->right*8));
    glVertexf3(interPos+(camera->up*(end-2)+camera->right*6));
    glEnd();

    if(group) {
        glPushMatrix();
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glTranslatef3(interPos-camera->right*10);
        glScalef(10,10,10);
        font->glWorldPrint("%d",group->id);
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);
        glPopMatrix();
    }
    if(beingBuilt) {
        glColor3f(1,0,0);
        float end=(buildProgress*0.8f)*10;
        glBegin(GL_QUADS);
        glVertexf3(interPos-camera->up*2-camera->right*6);
        glVertexf3(interPos-camera->up*2-camera->right*8);
        glVertexf3(interPos+camera->up*(end-2)-camera->right*8);
        glVertexf3(interPos+camera->up*(end-2)-camera->right*6);
        glEnd();
    }
    if(stockpileWeapon) {
        glColor3f(1,0,0);
        float end=(stockpileWeapon->buildPercent*0.8f)*10;
        glBegin(GL_QUADS);
        glVertexf3(interPos-camera->up*2-camera->right*6);
        glVertexf3(interPos-camera->up*2-camera->right*8);
        glVertexf3(interPos+camera->up*(end-2)-camera->right*8);
        glVertexf3(interPos+camera->up*(end-2)-camera->right*6);
        glEnd();
    }
}
예제 #15
0
void CUnit::Draw()
{
    glPushMatrix();
    float3 interPos=pos+speed*gu->timeOffset;

    if (physicalState == Flying && unitDef->canmove) {
        //aircraft or skidding ground unit
        CMatrix44f transMatrix(interPos,-rightdir,updir,frontdir);

        glMultMatrixf(&transMatrix[0]);
    } else if(upright || !unitDef->canmove) {
        glTranslatef3(interPos);
        if(heading!=0)
            glRotatef(heading*(180.0/32768.0),0,1,0);
    } else {
        float3 frontDir=GetVectorFromHeading(heading);		//making local copies of vectors
        float3 upDir=ground->GetSmoothNormal(pos.x,pos.z);
        float3 rightDir=frontDir.cross(upDir);
        rightDir.Normalize();
        frontDir=upDir.cross(rightDir);

        CMatrix44f transMatrix(interPos,-rightDir,upDir,frontDir);

        glMultMatrixf(&transMatrix[0]);
    }

    if(beingBuilt && unitDef->showNanoFrame) {
        if(shadowHandler->inShadowPass) {
            if(buildProgress>0.66)
                localmodel->Draw();
        } else {
            float height=model->height;
            float start=model->miny;
            glEnable(GL_CLIP_PLANE0);
            glEnable(GL_CLIP_PLANE1);
            //float col=fabs(128.0-((gs->frameNum*4)&255))/255.0+0.5f;
            float3 fc;// fc frame color
            if(gu->teamNanospray) {
                unsigned char* tcol=gs->Team(team)->color;
                fc = float3(tcol[0]*(1./255.),tcol[1]*(1./255.),tcol[2]*(1./255.));
            } else {
                fc = unitDef->nanoColor;
            }
            glColorf3(fc);

            unitDrawer->UnitDrawingTexturesOff(model);

            double plane[4]= {0,-1,0,start+height*buildProgress*3};
            glClipPlane(GL_CLIP_PLANE0 ,plane);
            double plane2[4]= {0,1,0,-start-height*(buildProgress*10-9)};
            glClipPlane(GL_CLIP_PLANE1 ,plane2);
            glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
            localmodel->Draw();
            glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

            if(buildProgress>0.33) {
                glColorf3(fc*1.4f);
                double plane[4]= {0,-1,0,start+height*(buildProgress*3-1)};
                glClipPlane(GL_CLIP_PLANE0 ,plane);
                double plane2[4]= {0,1,0,-start-height*(buildProgress*3-2)};
                glClipPlane(GL_CLIP_PLANE1 ,plane2);

                localmodel->Draw();
            }
            glDisable(GL_CLIP_PLANE1);
            unitDrawer->UnitDrawingTexturesOn(model);

            if(buildProgress>0.66) {
                double plane[4]= {0,-1,0,start+height*(buildProgress*3-2)};
                glClipPlane(GL_CLIP_PLANE0 ,plane);
                if(shadowHandler->drawShadows && !water->drawReflection) {
                    glPolygonOffset(1,1);
                    glEnable(GL_POLYGON_OFFSET_FILL);
                }
                localmodel->Draw();
                if(shadowHandler->drawShadows && !water->drawReflection) {
                    glDisable(GL_POLYGON_OFFSET_FILL);
                }
            }
            glDisable(GL_CLIP_PLANE0);
        }
    } else {
        localmodel->Draw();
    }
    if(gu->drawdebug) {
        glPushMatrix();
        glTranslatef3(frontdir*relMidPos.z + updir*relMidPos.y + rightdir*relMidPos.x);
        GLUquadricObj* q=gluNewQuadric();
        gluQuadricDrawStyle(q,GLU_LINE);
        gluSphere(q,radius,10,10);
        gluDeleteQuadric(q);
        glPopMatrix();
    }/**/
    glPopMatrix();
}
예제 #16
0
void CUnit::DrawStats()
{
	if ((gu->myAllyTeam != allyteam) &&
	    !gu->spectatingFullView && unitDef->hideDamage) {
		return;
	}

	float3 interPos = pos + (speed * gu->timeOffset);
	interPos.y += model->height + 5.0f;

	glBegin(GL_QUADS);

	const float3& camUp    = camera->up;
	const float3& camRight = camera->right;

	const float hpp = max(0.0f, health / maxHealth);
	const float end = (0.5f - hpp) * 10.0f;

	// black background for healthbar
	glColor3f(0.0f, 0.0f, 0.0f);
	glVertexf3(interPos + (camUp * 6.0f) - (camRight * end));
	glVertexf3(interPos + (camUp * 6.0f) + (camRight * 5.0f));
	glVertexf3(interPos + (camUp * 4.0f) + (camRight * 5.0f));
	glVertexf3(interPos + (camUp * 4.0f) - (camRight * end));

	if (stunned) {
		glColor3f(0.0f, 0.0f, 1.0f);
	} else {
		if (hpp > 0.5f) {
			glColor3f(1.0f - ((hpp - 0.5f) * 2.0f), 1.0f, 0.0f);
		} else {
			glColor3f(1.0f, hpp * 2.0f, 0.0f);
		}
	}
	// healthbar
	glVertexf3(interPos + (camUp * 6.0f) - (camRight * 5.0f));
	glVertexf3(interPos + (camUp * 6.0f) - (camRight * end));
	glVertexf3(interPos + (camUp * 4.0f) - (camRight * end));
	glVertexf3(interPos + (camUp * 4.0f) - (camRight * 5.0f));

	if ((gu->myTeam != team) && !gu->spectatingFullView) {
		glEnd();
		return;
	}

	// experience bar
	glColor3f(1.0f, 1.0f, 1.0f);
	const float hEnd = (limExperience * 0.8f) * 10.0f;
	glVertexf3(interPos + (-camUp * 2.0f)         + (camRight * 6.0f));
	glVertexf3(interPos + (-camUp * 2.0f)         + (camRight * 8.0f));
	glVertexf3(interPos + (camUp * (hEnd - 2.0f)) + (camRight * 8.0f));
	glVertexf3(interPos + (camUp * (hEnd - 2.0f)) + (camRight * 6.0f));
	glEnd();

	if (group) {
		glPushMatrix();
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glTranslatef3(interPos - (camRight * 10.0f));
		glScalef(10.0f, 10.0f, 10.0f);
		font->glWorldPrint("%d", group->id);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_BLEND);
		glPopMatrix();
	}

	if (beingBuilt) {
		glColor3f(1.0f, 0.0f, 0.0f);
		const float end = (buildProgress * 0.8f) * 10.0f;
		glBegin(GL_QUADS);
		glVertexf3(interPos - (camUp * 2.0f)         - (camRight * 6.0f));
		glVertexf3(interPos - (camUp * 2.0f)         - (camRight * 8.0f));
		glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 8.0f));
		glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 6.0f));
		glEnd();
	}
	else if (stockpileWeapon) {
		glColor3f(1.0f, 0.0f, 0.0f);
		const float end = (stockpileWeapon->buildPercent * 0.8f) * 10.0f;
		glBegin(GL_QUADS);
		glVertexf3(interPos - (camUp * 2.0f)         - (camRight * 6.0f));
		glVertexf3(interPos - (camUp * 2.0f)         - (camRight * 8.0f));
		glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 8.0f));
		glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 6.0f));
		glEnd();
	}
}
예제 #17
0
void InMapDraw_QuadDrawer::DrawQuad(int x, int y)
{
	int drawQuadsX = imd->drawQuadsX;
	CInMapDraw::DrawQuad* dq = &imd->drawQuads[y * drawQuadsX + x];

	va->EnlargeArrays(dq->points.size()*12,0,VA_SIZE_TC);
	// draw point markers
	for (std::list<CInMapDraw::MapPoint>::iterator pi = dq->points.begin(); pi != dq->points.end(); ++pi) {
		const int allyteam = pi->senderAllyTeam;
		const bool spec = pi->senderSpectator;
		const bool allied = (gs->Ally(gu->myAllyTeam, allyteam) && gs->Ally(allyteam, gu->myAllyTeam));
		const bool maySee = (gu->spectating || (!spec && allied) || imd->drawAll);

		if (maySee) {
			float3 pos = pi->pos;
			float3 dif(pos - camera->pos);
			float camDist = dif.Length();
			dif /= camDist;
			float3 dir1(dif.cross(UpVector));
			dir1.Normalize();
			float3 dir2(dif.cross(dir1));

			unsigned char col[4];
			col[0] = pi->color[0];
			col[1] = pi->color[1];
			col[2] = pi->color[2];
			col[3] = 200;

			float size = 6;
			float3 pos1 = pos;
			float3 pos2 = pos1;
			pos2.y += 100;

			va->AddVertexQTC(pos1 - dir1 * size,               0.25f, 0, col);
			va->AddVertexQTC(pos1 + dir1 * size,               0.25f, 1, col);
			va->AddVertexQTC(pos1 + dir1 * size + dir2 * size, 0.00f, 1, col);
			va->AddVertexQTC(pos1 - dir1 * size + dir2 * size, 0.00f, 0, col);

			va->AddVertexQTC(pos1 - dir1 * size,               0.75f, 0, col);
			va->AddVertexQTC(pos1 + dir1 * size,               0.75f, 1, col);
			va->AddVertexQTC(pos2 + dir1 * size,               0.75f, 1, col);
			va->AddVertexQTC(pos2 - dir1 * size,               0.75f, 0, col);

			va->AddVertexQTC(pos2 - dir1 * size,               0.25f, 0, col);
			va->AddVertexQTC(pos2 + dir1 * size,               0.25f, 1, col);
			va->AddVertexQTC(pos2 + dir1 * size - dir2 * size, 0.00f, 1, col);
			va->AddVertexQTC(pos2 - dir1 * size - dir2 * size, 0.00f, 0, col);

			if (pi->label.size() > 0) {
				glPushMatrix();
				glTranslatef3(pi->pos + UpVector * 105);
				glScalef(1200, 1200, 1200);
				glColor4ub(pi->color[0], pi->color[1], pi->color[2], 250);
				font->glWorldPrint(pi->label.c_str());
				glPopMatrix();
			}
		}
	}

	va->EnlargeArrays(dq->lines.size()*2,0,VA_SIZE_C);
	// draw line markers
	for (std::list<CInMapDraw::MapLine>::iterator li = dq->lines.begin(); li != dq->lines.end(); ++li) {
		const int allyteam = li->senderAllyTeam;
		const bool spec = li->senderSpectator;
		const bool allied = (gs->Ally(gu->myAllyTeam, allyteam) && gs->Ally(allyteam, gu->myAllyTeam));
		const bool maySee = (gu->spectating || (!spec && allied) || imd->drawAll);

		if (maySee) {
			lineva->AddVertexQC(li->pos - (li->pos - camera->pos).ANormalize() * 26, li->color);
			lineva->AddVertexQC(li->pos2 - (li->pos2 - camera->pos).ANormalize() * 26, li->color);
		}
	}
}
예제 #18
0
void CGrassBlockDrawer::DrawQuad(int x, int y)
{
	const float maxDetailedDist = gd->maxDetailedDist;

	CGrassDrawer::NearGrassStruct* nearGrass = gd->nearGrass;

	if (abs(x - cx) <= gd->detailedBlocks && abs(y - cy) <= gd->detailedBlocks) {
		//! blocks close to the camera
		for (int y2 = y * grassBlockSize; y2 < (y + 1) * grassBlockSize; ++y2) {
			for (int x2 = x * grassBlockSize; x2 < (x + 1) * grassBlockSize; ++x2) {
				if (gd->grassMap[y2 * gs->mapx / grassSquareSize + x2]) {
					float3 squarePos((x2 + 0.5f) * gSSsq, 0.0f, (y2 + 0.5f) * gSSsq);
						squarePos.y = CGround::GetHeightReal(squarePos.x, squarePos.z, false);

					const float sqdist = (camera->GetPos() - squarePos).SqLength();

					CGrassDrawer::NearGrassStruct* ng = &nearGrass[(y2 & 31) * 32 + (x2 & 31)];

					if (sqdist < (maxDetailedDist * maxDetailedDist)) {
						//! close grass, draw directly
						rng.Seed(y2 * 1025 + x2);

						for (int a = 0; a < gd->numTurfs; a++) {
							const float dx = (x2 + rng.RandFloat()) * gSSsq;
							const float dy = (y2 + rng.RandFloat()) * gSSsq;

							float3 pos(dx, CGround::GetHeightReal(dx, dy, false), dy);
								pos.y -= CGround::GetSlope(dx, dy, false) * 10.0f + 0.03f;

							if (ng->square != y2 * 2048 + x2) {
								const float3 v = squarePos - camera->GetPos();
								ng->rotation = GetHeadingFromVector(v.x, v.z) * 180.0f / 32768 + 180; //FIXME make more random
								ng->square = y2 * 2048 + x2;
							}

							glPushMatrix();
							glTranslatef3(pos);
							glRotatef(ng->rotation, 0.0f, 1.0f, 0.0f);
							glCallList(gd->grassDL);
							glPopMatrix();
						}
					} else {
						//! near but not close, save for later drawing
						CGrassDrawer::InviewNearGrass iv;
							iv.dist = sqdist;
							iv.x = x2;
							iv.y = y2;
						inviewNearGrass.push_back(iv);
						ng->square = -1;
					}
				}
			}
		}

		return;
	}

	const float3 dif(camera->GetPos().x - ((x + 0.5f) * bMSsq), 0.0f, camera->GetPos().z - ((y + 0.5f) * bMSsq));
	const float dist = dif.SqLength2D();

	if (dist < Square(gd->maxGrassDist)) {
		const int curSquare = y * gd->blocksX + x;
		const int curModSquare = (y & 31) * 32 + (x & 31);

		CGrassDrawer::GrassStruct* grass = gd->grass + curModSquare;
		grass->lastSeen = globalRendering->drawFrame;

		if (grass->square != curSquare) {
			grass->square = curSquare;

			delete grass->va;
			grass->va = NULL;
		}

		if (!grass->va) {
			grass->va = new CVertexArray;
			grass->pos = float3((x + 0.5f) * bMSsq, CGround::GetHeightReal((x + 0.5f) * bMSsq, (y + 0.5f) * bMSsq, false), (y + 0.5f) * bMSsq);

			CVertexArray* va = grass->va;
			va->Initialize();

			for (int y2 = y * grassBlockSize; y2 < (y + 1) * grassBlockSize; ++y2) {
				for (int x2 = x * grassBlockSize; x2 < (x + 1) * grassBlockSize; ++x2) {
					if (gd->grassMap[y2 * gs->mapx / grassSquareSize + x2]) {
						rng.Seed(y2 * 1025 + x2);

						for (int a = 0; a < gd->numTurfs; a++) {
							const float dx = (x2 + rng.RandFloat()) * gSSsq;
							const float dy = (y2 + rng.RandFloat()) * gSSsq;
							const float col = 1.0f;

							float3 pos(dx, CGround::GetHeightReal(dx, dy, false) + 0.5f, dy);
								pos.y -= (CGround::GetSlope(dx, dy, false) * 10.0f + 0.03f);

							va->AddVertexTN(pos, 0.0f,         0.0f, float3(-partTurfSize, -partTurfSize, col));
							va->AddVertexTN(pos, 1.0f / 16.0f, 0.0f, float3( partTurfSize, -partTurfSize, col));
							va->AddVertexTN(pos, 1.0f / 16.0f, 1.0f, float3( partTurfSize,  partTurfSize, col));
							va->AddVertexTN(pos, 0.0f,         1.0f, float3(-partTurfSize,  partTurfSize, col));
						}
					}
				}
			}
		}

		CGrassDrawer::InviewGrass ig;
			ig.num = curModSquare;
			ig.dist = dif.Length2D();
		inviewGrass.push_back(ig);
	}
}
예제 #19
0
static inline void DrawUnitColVol(const CUnit* u)
{
	if (u->IsInVoid())
		return;
	if (!(u->losStatus[gu->myAllyTeam] & LOS_INLOS) && !gu->spectatingFullView)
		return;
	if (!camera->InView(u->drawMidPos, u->GetDrawRadius()))
		return;

	const CollisionVolume* v = &u->collisionVolume;
	const bool vCustomType = (v->GetVolumeType() < CollisionVolume::COLVOL_TYPE_SPHERE);
	const bool vCustomDims = ((v->GetOffsets()).SqLength() >= 1.0f || math::fabs(v->GetBoundingRadius() - u->radius) >= 1.0f);

	GLUquadricObj* q = gluNewQuadric();
	gluQuadricDrawStyle(q, GLU_FILL);
	glDisable(GL_DEPTH_TEST);

	for (const CWeapon* w: u->weapons) {
		glPushMatrix();
		glTranslatef3(w->aimFromPos);
		glColor4f(1.0f, 1.0f, 0.0f, 0.4f);
		gluSphere(q, 1.0f, 5, 5);
		glPopMatrix();

		glPushMatrix();
		glTranslatef3(w->weaponMuzzlePos);
		if (w->HaveTarget()) {
			glColor4f(1.0f, 0.8f, 0.0f, 0.4f);
		} else {
			glColor4f(1.0f, 0.0f, 0.0f, 0.4f);
		}
		gluSphere(q, 1.0f, 5, 5);
		glPopMatrix();

		if (w->HaveTarget()) {
			glPushMatrix();
			glTranslatef3(w->GetCurrentTargetPos());
			glColor4f(1.0f, 0.8f, 0.0f, 0.4f);
			gluSphere(q, 1.0f, 5, 5);
			glPopMatrix();
		}
	}

	glColorf4(DEFAULT_VOLUME_COLOR);
	glEnable(GL_DEPTH_TEST);
	gluDeleteQuadric(q);


	glPushMatrix();
		glMultMatrixf(u->GetTransformMatrix());
		DrawObjectMidAndAimPos(u);

		if (v->DefaultToPieceTree()) {
			// draw only the piece volumes for less clutter
			// note: relMidPos transform is on the stack at this
			// point but all piece-positions are relative to pos
			// --> undo it
			glTranslatef3(-u->relMidPos * WORLD_TO_OBJECT_SPACE);
			DrawObjectDebugPieces(u);
			glTranslatef3(u->relMidPos * WORLD_TO_OBJECT_SPACE);
		} else {
			if (!v->IgnoreHits()) {
				// make it fade red under attack
				if (u->lastAttackFrame > 0 && ((gs->frameNum - u->lastAttackFrame) < 150)) {
					glColor3f((1.0f - ((gs->frameNum - u->lastAttackFrame) / 150.0f)), 0.0f, 0.0f);
				}

				// if drawing this, disable the DrawObjectMidAndAimPos call
				// DrawCollisionVolume((u->localModel).GetBoundingVolume());
				DrawCollisionVolume(v);

				if (u->lastAttackFrame > 0 && ((gs->frameNum - u->lastAttackFrame) < 150)) {
					glColorf4(DEFAULT_VOLUME_COLOR);
				}
			}
		}
		if (u->shieldWeapon != nullptr) {
			const CPlasmaRepulser* shield = static_cast<const CPlasmaRepulser*>(u->shieldWeapon);
			glColor4f(0.0f, 0.0f, 0.6f, 0.35f);
			DrawCollisionVolume(&shield->collisionVolume);
		}

		if (vCustomType || vCustomDims) {
			// assume this is a custom volume
			glColor4f(0.5f, 0.5f, 0.5f, 0.35f);
			glScalef(u->radius, u->radius, u->radius);
			glWireSphere(&volumeDisplayListIDs[0], 20, 20);
		}

	glPopMatrix();
}