예제 #1
0
void UnitDrawerStateARB::SetNanoColor(const float4& color) const {
	if (color.a > 0.0f) {
		glColorf4(color);
	} else {
		glColorf3(OnesVector);
	}
}
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);
		glColor4f(1.0f, 0.0f, 0.0f, 0.35f);
		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);
		glColor4f(1.0f, 0.0f, 1.0f, 0.35f);
		gluQuadricDrawStyle(q, GLU_FILL);
		gluSphere(q, 2.0f, 5, 5);
		glColorf4(DEFAULT_VOLUME_COLOR);
	}

	glEnable(GL_DEPTH_TEST);
	gluDeleteQuadric(q);
}
static void DrawObjectDebugPieces(const CSolidObject* o)
{
	const int hitDeltaTime = (gs->frameNum - o->lastHitPieceFrame);

	for (unsigned int n = 0; n < o->localModel.pieces.size(); n++) {
		const LocalModelPiece* lmp = o->localModel.GetPiece(n);
		const CollisionVolume* lmpVol = lmp->GetCollisionVolume();

		const bool b0 = ((o->lastHitPieceFrame > 0) && (hitDeltaTime < 150));
		const bool b1 = (lmp == o->lastHitPiece);

		if (!lmp->scriptSetVisible || lmpVol->IgnoreHits())
			continue;

		if (b0 && b1) {
			glColor3f((1.0f - (hitDeltaTime / 150.0f)), 0.0f, 0.0f);
		}

		glPushMatrix();
		glMultMatrixf(lmp->GetModelSpaceMatrix());
		// factors in the volume offsets
		DrawCollisionVolume(lmpVol);
		glPopMatrix();

		if (b0 && b1) {
			glColorf4(DEFAULT_VOLUME_COLOR);
		}
	}
}
예제 #4
0
void UnitDrawerStateFFP::SetNanoColor(const float4& color) const {
	if (color.a > 0.0f) {
		UnitDrawerStateFFP::DisableTextures();
		glColorf4(color);
	} else {
		UnitDrawerStateFFP::EnableTextures();
		glColorf3(OnesVector);
	}
}
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();
}