Skip to content

Commit fc12ac3

Browse files
committed
Enhanced Radar
1 parent fa42c32 commit fc12ac3

16 files changed

+444
-257
lines changed

data/playing.vert

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ uniform bool localViewer;
2121
uniform int texGen;
2222
uniform float zTank;
2323
uniform float repeat;
24+
uniform int csProc;
2425

2526
const int texGenNone = 0;
2627
const int texGenSphereMap = 1;
2728
const int texGenLinear = 2;
2829

30+
const int csNone = 0;
31+
const int csColor = 1;
32+
const int csColTr = 2;
33+
2934
vec3 ecPosition3;
3035
vec3 normal;
3136
vec3 eye;
@@ -94,6 +99,40 @@ void Light(in gl_LightProducts lightProduct,
9499
specular += lightProduct.specular * pf * attenuation;
95100
}
96101

102+
float colorScale(float z, float h)
103+
{
104+
float atten = zTank - (z + h);
105+
if (atten < 0.0)
106+
atten = z - zTank;
107+
if (atten < 0.0)
108+
atten = 0.0;
109+
110+
const float colorFactor = 40.0;
111+
atten /= colorFactor;
112+
113+
float scale = max(1.0 - atten, 0.35);
114+
115+
return scale;
116+
}
117+
118+
float transScale(const float z, const float h)
119+
{
120+
float atten = zTank - (z + h);
121+
122+
if (atten <= 0.0)
123+
atten = z - zTank;
124+
125+
if (atten <= 0.0)
126+
atten = 0.0;
127+
128+
const float colorFactor = 40.0;
129+
atten /= colorFactor;
130+
131+
float scale = max(1.0 - atten, 0.5);
132+
133+
return scale;
134+
}
135+
97136
void setOutput(in vec4 ecPosition, in vec4 texCoord, in vec4 color)
98137
{
99138
// Transform vertex to clip space
@@ -105,7 +144,23 @@ void setOutput(in vec4 ecPosition, in vec4 texCoord, in vec4 color)
105144

106145
gl_ClipVertex = ecPosition;
107146
gl_TexCoord[0] = texCoord;
108-
gl_FrontColor = color;
147+
if (csProc == csNone)
148+
{
149+
gl_FrontColor = color;
150+
}
151+
else
152+
{
153+
float z = ecPosition.z;
154+
float bh = color.a;
155+
float scale = colorScale(z, bh);
156+
if (csProc == csColTr)
157+
{
158+
float trans = transScale(z, bh);
159+
gl_FrontColor = vec4(scale * color.rgb, trans);
160+
}
161+
else if (csProc == csColor)
162+
gl_FrontColor = vec4(scale * color.rgb, 1.0);
163+
}
109164
gl_FrontSecondaryColor = vec4(0.0, 0.0, 0.0, 1.0);
110165
gl_BackSecondaryColor = gl_FrontSecondaryColor;
111166
gl_BackColor = gl_FrontColor;

include/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ noinst_HEADERS = \
126126
TimeKeeper.h \
127127
TriWallSceneNode.h \
128128
Vertex_Chunk.h \
129+
Vertex_Chunkes.h \
129130
ViewFrustum.h \
130131
VotingBooth.h \
131132
VBO_Geometry.h \

include/PlayingShader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ class PlayingShader: public Singleton<PlayingShader>, public Shader
4040
int setTexGen(int texGenMode);
4141
void setZTank(float zTank);
4242
void setRepeat(float repeat);
43+
void setColorProcessing(int csProc);
4344

4445
const int texGenNone = 0;
4546
const int texGenSphereMap = 1;
4647
const int texGenLinear = 2;
4748

49+
const int csNone = 0;
50+
const int csColor = 1;
51+
const int csColTr = 2;
52+
4853
protected:
4954
friend class Singleton<PlayingShader>;
5055

@@ -65,6 +70,7 @@ class PlayingShader: public Singleton<PlayingShader>, public Shader
6570
GLint texGenUniform;
6671
GLint zTankUniform;
6772
GLint repeatUniform;
73+
GLint csProcUniform;
6874

6975
GLint lightEnabled[128];
7076
GLint maxLights;

include/Vertex_Chunkes.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* bzflag
2+
* Copyright (c) 2019-2019 Tim Riker
3+
*
4+
* This package is free software; you can redistribute it and/or
5+
* modify it under the terms of the license found in the file
6+
* named COPYING that should have accompanied this file.
7+
*
8+
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9+
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#pragma once
14+
15+
// 1st
16+
#include "common.h"
17+
18+
// Common headers
19+
#include "Vertex_Chunk.h"
20+
21+
class Vertex_Chunkes
22+
{
23+
public:
24+
Vertex_Chunkes();
25+
~Vertex_Chunkes();
26+
27+
void setChunkes(std::vector<Vertex_Chunk> &chunkes);
28+
29+
void draw(GLenum mode);
30+
private:
31+
GLint *first;
32+
GLsizei *count;
33+
int drawCount;
34+
VBO_Vertex *myVBO;
35+
};
36+
37+
// Local Variables: ***
38+
// mode: C++ ***
39+
// tab-width: 4 ***
40+
// c-basic-offset: 4 ***
41+
// indent-tabs-mode: nil ***
42+
// End: ***
43+
// ex: shiftwidth=4 tabstop=4

src/bzflag/GuidedMissleStrategy.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Intersect.h"
2525
#include "OpenGLAPI.h"
2626
#include "VBO_Drawing.h"
27+
#include "PlayingShader.h"
2728

2829
/* local implementation headers */
2930
#include "LocalPlayer.h"
@@ -479,13 +480,13 @@ void GuidedMissileStrategy::radarRender()
479480

480481
float shotTailLength = BZDB.eval(StateDatabase::BZDB_SHOTTAILLENGTH);
481482
glPushMatrix();
482-
glTranslatef(orig[0], orig[1], 0.0f);
483+
glTranslate(orig);
483484
// Display leading lines
484485
if (length > 0)
485486
{
486487
const auto vel = getPath().getVelocity();
487488
const auto dir = glm::normalize(vel) * shotTailLength * float(length);
488-
glScalef(dir[0], dir[1], 0.0f);
489+
glScalef(dir[0], dir[1], 1.0f);
489490
if (BZDBCache::leadingShotLine == 1) //leading
490491
DRAWER.leadingLine();
491492
else if (BZDBCache::leadingShotLine == 0) //lagging
@@ -496,10 +497,12 @@ void GuidedMissileStrategy::radarRender()
496497
// draw a "bright reddish" missle tip
497498
if (size > 0)
498499
{
500+
SHADER.setColorProcessing(SHADER.csNone);
499501
glColor4f(1.0f, 0.75f, 0.75f, 1.0f);
500502
glPointSize((float)size);
501503
DRAWER.point();
502504
glPointSize(1.0f);
505+
SHADER.setColorProcessing(SHADER.csColor);
503506
}
504507
}
505508
else

0 commit comments

Comments
 (0)