Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Radar::SphereDisplay Class Reference

#include <sphere_display.h>

Inheritance diagram for Radar::SphereDisplay:
Radar::DualDisplayBase Radar::Display

Public Member Functions

 SphereDisplay ()
 
void Draw (const Sensor &sensor, VSSprite *, VSSprite *)
 
- Public Member Functions inherited from Radar::DualDisplayBase
 DualDisplayBase ()
 
void OnPauseBegin ()
 
void OnPauseEnd ()
 
- Public Member Functions inherited from Radar::Display
virtual ~Display ()
 
virtual void OnDockEnd ()
 
virtual void OnJumpBegin ()
 
virtual void OnJumpEnd ()
 

Protected Member Functions

void DrawBackground (const Sensor &, const ViewArea &)
 
void DrawTrack (const Sensor &, const ViewArea &, const Track &, bool negate_z=false)
 
void DrawTargetMarker (const Vector &, float)
 
- Protected Member Functions inherited from Radar::DualDisplayBase
float Jitter (float errorOffset, float errorRange)
 
void Jitter (float errorOffset, float errorRange, Vector &position)
 

Protected Attributes

const float innerSphere
 
float radarTime
 
- Protected Attributes inherited from Radar::DualDisplayBase
ViewArea leftRadar
 
ViewArea rightRadar
 
bool isPaused
 
RandomEngine randomEngine
 
RandomDistribution randomDistribution
 
RandomGenerator randomGenerator
 

Detailed Description

Definition at line 15 of file sphere_display.h.

Constructor & Destructor Documentation

Radar::SphereDisplay::SphereDisplay ( )

Definition at line 35 of file sphere_display.cpp.

36  : innerSphere(0.98),
37  radarTime(0.0)
38 {
39 }

Member Function Documentation

void Radar::SphereDisplay::Draw ( const Sensor sensor,
VSSprite frontSprite,
VSSprite rearSprite 
)
virtual

Implements Radar::Display.

Definition at line 41 of file sphere_display.cpp.

References DEPTHTEST, DEPTHWRITE, VSSprite::Draw(), DrawBackground(), DrawTrack(), Radar::Sensor::FindTracksInRange(), GetElapsedTime(), VegaConfig::getVariable(), GFXDisable(), GFXEnable(), GFXPointSize(), Radar::DualDisplayBase::leftRadar, XMLSupport::parse_bool(), radarTime, Radar::DualDisplayBase::rightRadar, Radar::ViewArea::SetSprite(), and vs_config.

44 {
45  assert(frontSprite || rearSprite); // There should be at least one radar display
46 
48 
49  leftRadar.SetSprite(frontSprite);
50  rightRadar.SetSprite(rearSprite);
51 
52  if (frontSprite)
53  frontSprite->Draw();
54  if (rearSprite)
55  rearSprite->Draw();
56 
58 
59  // FIXME: Consider using std::sort instead of the z-buffer
62 
63  DrawBackground(sensor, leftRadar);
64  DrawBackground(sensor, rightRadar);
65 
66  for (Sensor::TrackCollection::const_iterator it = tracks.begin(); it != tracks.end(); ++it)
67  {
68  static bool draw_both =
69  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_blips_on_both_radar", "false" ));
70  if (it->GetPosition().z < 0 || draw_both)
71  {
72  // Draw tracks behind the ship
73  DrawTrack(sensor, rightRadar, *it,true);
74  }
75  if (it->GetPosition().z >= 0 || draw_both)
76  {
77  // Draw tracks in front of the ship
78  DrawTrack(sensor, leftRadar, *it);
79  }
80  }
81 
82  GFXPointSize(1);
85 }
void Radar::SphereDisplay::DrawBackground ( const Sensor sensor,
const ViewArea radarView 
)
protected

Definition at line 190 of file sphere_display.cpp.

References center, g_game, Radar::ViewArea::GetColor(), Radar::Sensor::GetPlayer(), Unit::GetWarpVelocity(), GFXBegin(), GFXColorf(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINE, GFXLineWidth(), GFXVertexf(), Radar::ViewArea::IsActive(), Radar::ViewArea::Scale(), size, SMOOTH, Vector, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by Draw().

191 {
192  // Split crosshair
193 
194  if (!radarView.IsActive())
195  return;
196 
197  GFXColor groundColor = radarView.GetColor();
198 
199  float velocity = sensor.GetPlayer()->GetWarpVelocity().Magnitude();
200  float logvelocity = 3.0; // std::log10(1000.0);
201  if (velocity > 1000.0)
202  {
203  // Max logvelocity is log10(speed_of_light) = 10.46
204  logvelocity = std::log10(velocity);
205  }
206  const float size = 3.0 * logvelocity; // [9; 31]
207  const float xground = size / g_game.x_resolution;
208  const float yground = size / g_game.y_resolution;
209  Vector center = radarView.Scale(Vector(0.0, 0.0, 0.0));
210 
211  GFXEnable(SMOOTH);
212  GFXLineWidth(1);
213  GFXColorf(groundColor);
214  GFXBegin(GFXLINE);
215  GFXVertexf(Vector(center.x - 2.0 * xground, center.y, center.z));
216  GFXVertexf(Vector(center.x - xground, center.y, center.z));
217  GFXVertexf(Vector(center.x + 2.0 * xground, center.y, center.z));
218  GFXVertexf(Vector(center.x + xground, center.y, center.z));
219  GFXVertexf(Vector(center.x, center.y - 2.0 * yground, center.z));
220  GFXVertexf(Vector(center.x, center.y - yground, center.z));
221  GFXVertexf(Vector(center.x, center.y + 2.0 * yground, center.z));
222  GFXVertexf(Vector(center.x, center.y + yground, center.z));
223  GFXEnd();
225 }
void Radar::SphereDisplay::DrawTargetMarker ( const Vector position,
float  trackSize 
)
protected

Definition at line 170 of file sphere_display.cpp.

References g_game, GFXBegin(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINE, GFXLineWidth(), GFXVertex3f(), SMOOTH, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by DrawTrack().

171 {
172  // Crosshair
173  const float crossSize = 8.0;
174  const float xcross = crossSize / g_game.x_resolution;
175  const float ycross = crossSize / g_game.y_resolution;
176 
177  // The crosshair wiggles as it moves around. The wiggling is less noticable
178  // when the crosshair is drawn with the smooth option.
179  GFXEnable(SMOOTH);
180  GFXLineWidth(trackSize);
181  GFXBegin(GFXLINE);
182  GFXVertex3f(position.x + xcross, position.y, 0.0f);
183  GFXVertex3f(position.x - xcross, position.y, 0.0f);
184  GFXVertex3f(position.x, position.y - ycross, 0.0f);
185  GFXVertex3f(position.x, position.y + ycross, 0.0f);
186  GFXEnd();
188 }
void Radar::SphereDisplay::DrawTrack ( const Sensor sensor,
const ViewArea radarView,
const Track track,
bool  negate_z = false 
)
protected

Definition at line 87 of file sphere_display.cpp.

References GFXColor::a, DrawTargetMarker(), error, Radar::Track::ExplodingProgress(), Radar::Sensor::GetColor(), anonymous_namespace{bubble_display.cpp}::GetDangerRate(), Radar::Sensor::GetMaxRange(), Radar::Track::GetPosition(), Radar::Track::GetType(), VegaConfig::getVariable(), GFXBegin(), GFXColorf(), GFXEnd(), GFXPOINT, GFXPointSize(), GFXVertexf(), Radar::Track::HasActiveECM(), Radar::Sensor::IdentifyThreat(), innerSphere, Radar::Sensor::InsideNebula(), Radar::ViewArea::IsActive(), Radar::Track::IsExploding(), Radar::Sensor::IsTracking(), Radar::DualDisplayBase::Jitter(), Radar::Track::Type::Nebula, XMLSupport::parse_bool(), radarTime, Radar::ViewArea::Scale(), Radar::Sensor::UseThreatAssessment(), Vector, and vs_config.

Referenced by Draw().

91 {
92  if (!radarView.IsActive())
93  return;
94 
95  GFXColor color = sensor.GetColor(track);
96 
97  Vector position = track.GetPosition();
98  if (negate_z) position.z=-position.z;
99  if (position.z < 0){
100  static bool negate_z =
101  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "show_negative_blips_as_positive", "true" ));
102  if (negate_z)
103  position.z=-position.z;
104  else
105  position.z = .125;
106  }
107  const float trackSize = 2.0;
108 
109  // FIXME: Jitter only on boundary, not in center
110  if (sensor.InsideNebula())
111  {
112  Jitter(0.02, 0.04, position);
113  }
114  else
115  {
116  const bool isNebula = (track.GetType() == Track::Type::Nebula);
117  const bool isEcmActive = track.HasActiveECM();
118  if (isNebula || isEcmActive)
119  {
120  float error = 0.02 * trackSize;
121  Jitter(error, error, position);
122  }
123  }
124 
125  // The magnitude is used to calculate the unit vector. With subtle scaling
126  // of the magnitude we generate a unit vector whose length will vary from
127  // innerSphere to 1.0, depending on the distance to the object. Combined
128  // with the OpenGL z-buffering, this will ensure that close tracks are drawn
129  // on top of distant tracks.
130  float magnitude = position.Magnitude();
131  float scaleFactor = 0.0; // [0; 1] where 0 = border, 1 = center
132  const float maxRange = sensor.GetMaxRange();
133  if (magnitude <= maxRange)
134  {
135  // [innerSphere; 1]
136  scaleFactor = (1.0 - innerSphere) * (maxRange - magnitude) / maxRange;
137  magnitude /= (1.0 - scaleFactor);
138  }
139  Vector scaledPosition = Vector(-position.x, position.y, position.z) / magnitude;
140 
141  Vector head = radarView.Scale(scaledPosition);
142 
143  GFXColor headColor = color;
144  if (sensor.UseThreatAssessment())
145  {
146  float dangerRate = GetDangerRate(sensor.IdentifyThreat(track));
147  if (dangerRate > 0.0)
148  {
149  // Blinking track
150  headColor.a *= cosf(dangerRate * radarTime);
151  }
152  }
153  // Fade out dying ships
154  if (track.IsExploding())
155  {
156  headColor.a *= (1.0 - track.ExplodingProgress());
157  }
158 
159  GFXColorf(headColor);
160  if (sensor.IsTracking(track))
161  {
162  DrawTargetMarker(head, trackSize);
163  }
164  GFXPointSize(trackSize);
166  GFXVertexf(head);
167  GFXEnd();
168 }

Member Data Documentation

const float Radar::SphereDisplay::innerSphere
protected

Definition at line 28 of file sphere_display.h.

Referenced by DrawTrack().

float Radar::SphereDisplay::radarTime
protected

Definition at line 29 of file sphere_display.h.

Referenced by Draw(), and DrawTrack().


The documentation for this class was generated from the following files: