Skip to content

Commit

Permalink
Save some glTranslate on drawTank/drawFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Apr 21, 2024
1 parent c97b510 commit 6b81e62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/bzflag/RadarRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ void RadarRenderer::setTankColor(const Player* player)

void RadarRenderer::drawTank(const float pos[3], const Player* player, bool useSquares)
{
glPushMatrix();

// 'ps' is pixel scale, setup in render()
const float tankRadius = BZDBCache::tankRadius;
float minSize = 1.5f + (ps * BZDBCache::radarTankPixels);
Expand All @@ -179,9 +177,6 @@ void RadarRenderer::drawTank(const float pos[3], const Player* player, bool useS
// NOTE: myTank was checked in render()
const float myAngle = LocalPlayer::getMyTank()->getAngle();

// transform to the tanks location
glTranslatef(pos[0], pos[1], 0.0f);

// draw the tank
if (useSquares || !useTankDimensions)
{
Expand Down Expand Up @@ -224,8 +219,6 @@ void RadarRenderer::drawTank(const float pos[3], const Player* player, bool useS
glVertex2f(0.0f, +size);
glVertex2f(-size, 0.0f);
glEnd();

glPopMatrix();
}


Expand Down Expand Up @@ -278,13 +271,12 @@ void RadarRenderer::drawFlag(const float pos[3])
glEnd();
}

void RadarRenderer::drawFlagOnTank(const float pos[3])
void RadarRenderer::drawFlagOnTank()
{
glPushMatrix();

// align it to the screen axes
const float angle = LocalPlayer::getMyTank()->getAngle();
glTranslatef(pos[0], pos[1], 0.0f);
glRotatef(float(angle * 180.0 / M_PI), 0.0f, 0.0f, 1.0f);

float tankRadius = BZDBCache::tankRadius;
Expand Down Expand Up @@ -644,16 +636,23 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer)

const float* position = player->getPosition();

glPushMatrix();

// transform to the tanks location
glTranslatef(position[0], position[1], 0.0f);

if (player->getFlag() != Flags::Null)
{
glColor3fv(player->getFlag()->getRadarColor());
drawFlagOnTank(position);
drawFlagOnTank();
}

if (!observer)
drawTank(position, player, true);
else
drawTank(position, player, false);

glPopMatrix();
}

bool coloredShot = BZDB.isTrue("coloredradarshots");
Expand Down Expand Up @@ -753,18 +752,21 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer)
{
// revert to the centered transformation
glRotatef((float)(90.0 - myAngle * 180.0 / M_PI), 0.0f, 0.0f, 1.0f);
glTranslatef(-myPos[0], -myPos[1], 0.0f);

glPushMatrix();

// my flag
if (myTank->getFlag() != Flags::Null)
{
glColor3fv(myTank->getFlag()->getRadarColor());
drawFlagOnTank(myPos);
drawFlagOnTank();
}

// my tank
drawTank(myPos, myTank, false);

glPopMatrix();

// re-setup the blending function
// (was changed by drawing jump jets)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Expand Down
2 changes: 1 addition & 1 deletion src/bzflag/RadarRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class RadarRenderer
bool useSquares);
void drawFancyTank(const class Player* player);
void drawFlag(const float pos[3]);
void drawFlagOnTank(const float pos[3]);
void drawFlagOnTank();

static float colorScale(const float z, const float h);
static float transScale(const float z, const float h);
Expand Down

0 comments on commit 6b81e62

Please sign in to comment.