Skip to content

Commit 33c59a3

Browse files
committed
Inline drawFlagInTank, add myAngle tankSize flagSize pars to drawTank
1 parent e359357 commit 33c59a3

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

src/bzflag/RadarRenderer.cxx

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,32 @@ glm::vec3 RadarRenderer::getTankColor(const Player* player)
142142
return color;
143143
}
144144

145-
void RadarRenderer::drawTank(const glm::vec3 &pos, const Player* player, bool useSquares)
145+
void RadarRenderer::drawTank(const glm::vec3 &pos,
146+
float myAngle,
147+
float tankSize, float flagSize,
148+
const Player* player, bool useSquares)
146149
{
147150
auto flag = player->getFlag();
148151

149152
// my flag
150153
if (flag != Flags::Null)
151154
{
152155
glColor(flag->getRadarColor());
153-
drawFlagOnTank();
156+
glPushMatrix();
157+
158+
// align it to the screen axes
159+
glRotatef(float(myAngle * 180.0 / M_PI), 0.0f, 0.0f, 1.0f);
160+
161+
glScalef(flagSize, flagSize, 0);
162+
DRAWER.cross();
163+
164+
glPopMatrix();
154165
}
155166

156-
// 'ps' is pixel scale, setup in render()
157-
const float tankRadius = BZDBCache::tankRadius;
158-
float minSize = 1.5f + (ps * BZDBCache::radarTankPixels);
159-
GLfloat size;
160-
if (tankRadius < minSize)
161-
size = minSize;
162-
else
163-
size = tankRadius;
164167
if (pos[2] < 0.0f)
165-
size = 0.5f;
168+
tankSize = 0.5f;
166169

167170
// NOTE: myTank was checked in render()
168-
const float myAngle = LocalPlayer::getMyTank()->getAngle();
169-
170171
// draw the tank
171172
if (!useSquares)
172173
{
@@ -184,17 +185,17 @@ void RadarRenderer::drawTank(const glm::vec3 &pos, const Player* player, bool us
184185
if (useSquares)
185186
{
186187
glPushMatrix();
187-
glScalef(size, size, 0.0f);
188+
glScalef(tankSize, tankSize, 0.0f);
188189
DRAWER.simmetricRect();
189190
glPopMatrix();
190191
}
191192

192193
// adjust with height box size
193194
const float boxHeight = BZDB.eval(StateDatabase::BZDB_BOXHEIGHT);
194-
size = size * (1.0f + (0.5f * (pos[2] / boxHeight)));
195+
tankSize *= 1.0f + 0.5f * pos[2] / boxHeight;
195196

196197
// draw the height box
197-
glScalef(size, size, 0.0f);
198+
glScalef(tankSize, tankSize, 0.0f);
198199
DRAWER.diamondLoop();
199200
}
200201

@@ -243,23 +244,6 @@ void RadarRenderer::drawFlag(const glm::vec3 &pos)
243244
glPopMatrix();
244245
}
245246

246-
void RadarRenderer::drawFlagOnTank()
247-
{
248-
glPushMatrix();
249-
250-
// align it to the screen axes
251-
const float angle = LocalPlayer::getMyTank()->getAngle();
252-
glRotatef(float(angle * 180.0 / M_PI), 0.0f, 0.0f, 1.0f);
253-
254-
float tankRadius = BZDBCache::tankRadius;
255-
GLfloat s = 2.5f * tankRadius > 4.0f * ps ? 2.5f * tankRadius : 4.0f * ps;
256-
glScalef(s, s, 0);
257-
DRAWER.cross();
258-
259-
glPopMatrix();
260-
}
261-
262-
263247
void RadarRenderer::renderFrame(SceneRenderer& renderer)
264248
{
265249
const MainWindow& window = renderer.getWindow();
@@ -550,6 +534,11 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer)
550534
}
551535
}
552536

537+
const float tankRadius = BZDBCache::tankRadius;
538+
// 'ps' is pixel scale, setup in render()
539+
const float minSize = 1.5f + ps * BZDBCache::radarTankPixels;
540+
const float tankSize = std::max(minSize, tankRadius);
541+
const float flagSize = std::max(2.5f * tankRadius, 4.0f * ps);
553542
// draw other tanks (and any flags on them)
554543
// note about flag drawing. each line segment is drawn twice
555544
// (once in each direction); this degrades the antialiasing
@@ -576,9 +565,9 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer)
576565
glTranslatef(position[0], position[1], 0.0f);
577566

578567
if (!observer)
579-
drawTank(position, player, true);
568+
drawTank(position, myAngle, tankSize, flagSize, player, true);
580569
else
581-
drawTank(position, player, !useTankModels);
570+
drawTank(position, myAngle, tankSize, flagSize, player, !useTankModels);
582571

583572
glPopMatrix();
584573
}
@@ -682,7 +671,7 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer)
682671
glPushMatrix();
683672

684673
// my tank
685-
drawTank(myPos, myTank, !useTankModels);
674+
drawTank(myPos, myAngle, tankSize, flagSize, myTank, !useTankModels);
686675

687676
glPopMatrix();
688677

src/bzflag/RadarRenderer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ class RadarRenderer
7171

7272
glm::vec3 getTankColor(const class Player *player);
7373
void drawTank(const glm::vec3 &pos,
74+
float myAngle,
75+
float tankSize, float flagSize,
7476
const class Player* player,
7577
bool useSquares);
7678
void drawFancyTank(const class Player* player);
7779
void drawFlag(const glm::vec3 &pos);
78-
void drawFlagOnTank();
7980
void buildBoxPyrMeshVBO();
8081
void buildWallsVBO();
8182
void buildBasesAndTelesVBO();

0 commit comments

Comments
 (0)