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
navscreen.cpp
Go to the documentation of this file.
1 #include <set>
2 #include "vsfilesystem.h"
3 #include "vs_globals.h"
4 #include "vegastrike.h"
5 #include "gfx/gauge.h"
6 #include "gfx/cockpit.h"
7 #include "universe.h"
8 #include "star_system.h"
9 #include "cmd/unit_generic.h"
10 #include "cmd/unit_factory.h"
11 #include "cmd/collection.h"
12 #include "gfx/hud.h"
13 #include "gfx/vdu.h"
14 #include "lin_time.h" //for fps
15 #include "config_xml.h"
16 #include "lin_time.h"
17 #include "cmd/images.h"
18 #include "cmd/script/mission.h"
19 #include "cmd/script/msgcenter.h"
20 #include "cmd/ai/flyjoystick.h"
21 #include "cmd/ai/firekeyboard.h"
22 #include "cmd/ai/aggressive.h"
23 #include "main_loop.h"
24 #include <assert.h> //needed for assert() calls
25 #include "savegame.h"
26 #include "gfx/animation.h"
27 #include "gfx/mesh.h"
28 #include "universe_util.h"
29 #include "in_mouse.h"
30 #include "gui/glut_support.h"
31 #include "networking/netclient.h"
32 #include "cmd/unit_util.h"
33 #include "math.h"
34 #include "save_util.h"
35 #include "gfx/vdu.h"
36 #include "navscreen.h"
37 #include "gfx/masks.h"
38 #include "navgetxmldata.h"
39 #include "navitemstodraw.h"
40 #include "navparse.h"
41 #include "navcomputer.h"
42 #include "navpath.h"
43 
44 //This sets up the items in the navscreen
45 //**********************************
46 
48 {
49  draw = -1;
50  whattodraw = (1|2);
51  pathman = new PathManager();
52  navcomp = new NavComputer( this );
53  for (int i = 0; i < NAVTOTALMESHCOUNT; i++)
54  mesh[i] = NULL;
55  factioncolours = NULL;
56 }
57 
59 {
60  draw = 0;
61  //delete mesh;
62  delete screenoccupation;
63  delete mesh[0];
64  delete mesh[1];
65  delete mesh[2];
66  delete mesh[3];
67  delete mesh[4];
68  delete mesh[5];
69  delete mesh[6];
70  delete mesh[7];
71  delete factioncolours;
72 }
74 {
75  mousex = x;
76  mousey = y;
77 }
79 {
80  mousex = x;
81  mousey = y;
82 }
83 void NavigationSystem::mouseClick( int button, int state, int x, int y )
84 {
85  mousex = x;
86  mousey = y;
87  if (state == WS_MOUSE_DOWN)
88  mousestat |= ( 1<<lookupMouseButton( button ) );
89  else if (button != WS_WHEEL_UP && button != WS_WHEEL_DOWN)
90  mousestat &= ( ~( 1<<lookupMouseButton( button ) ) );
91 }
92 
94 {
96 
97  configmode = 0;
98 
99  rotations = 0;
100 
101  minimumitemscaledown = 0.2;
102  maximumitemscaleup = 3.0;
103 
104  axis = 3;
105 
106  rx = -0.5; //galaxy mode settings
107  ry = 0.5;
108  rz = 0.0;
109  zoom = 1.8;
110 
111  rx_s = -0.5; //system mode settings
112  ry_s = 1.5;
113  rz_s = 0.0;
114  zoom_s = 1.8;
115 
116  scrolloffset = 0;
117 
118  camera_z = 1.0; //updated after a pass
119  center_x = 0.0; //updated after a pass
120  center_y = 0.0; //updated after a pass
121  center_z = 0.0; //updated after a pass
122 
123  path_view = PATH_ON;
124  static bool start_sys_ortho = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "system_map_ortho_view", "false" ) );
125  static bool start_sec_ortho = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "sector_map_ortho_view", "false" ) );
126  system_view = start_sys_ortho ? VIEW_ORTHO : VIEW_2D;
127  galaxy_view = start_sec_ortho ? VIEW_ORTHO : VIEW_2D;
128  system_multi_dimensional = 1;
129  galaxy_multi_dimensional = 1;
130 
131  zshiftmultiplier = 2.5; //shrink the output
132  item_zscalefactor = 1.0; //camera distance prespective multiplier for affecting item sizes
133  system_item_scale = 1.0;
134  mouse_previous_state[0] = 0; //could have used a loop, but this way the system uses immediate instead of R type.
135  mouse_previous_state[1] = 0;
136  mouse_previous_state[2] = 0;
137  mouse_previous_state[3] = 0;
138  mouse_previous_state[4] = 0;
139  mouse_wentup[0] = 0;
140  mouse_wentup[1] = 0;
141  mouse_wentup[2] = 0;
142  mouse_wentup[3] = 0;
143  mouse_wentup[4] = 0;
144  mouse_wentdown[0] = 0;
145  mouse_wentdown[1] = 0;
146  mouse_wentdown[2] = 0;
147  mouse_wentdown[3] = 0;
148  mouse_wentdown[4] = 0;
149  mouse_x_previous = ( -1+float(mousex)/(.5*g_game.x_resolution) );
150  mouse_y_previous = ( 1+float(-1*mousey)/(.5*g_game.y_resolution) );
151 
152  static int max_map_nodes = XMLSupport::parse_int( vs_config->getVariable( "graphics", "max_map_nodes", "256000" ) );
153  systemIter.init( UniverseUtil::getSystemFile(), max_map_nodes );
154  sectorIter.init( systemIter );
155  systemselectionindex = 0;
156  sectorselectionindex = 0;
157  destinationsystemindex = 0;
158  currentsystemindex = 0;
159  setFocusedSystemIndex( 0 );
160 
161  static int time_to_helpscreen = XMLSupport::parse_int( vs_config->getVariable( "general", "times_to_show_help_screen", "3" ) );
162  buttonstates = 0;
163  if (getSaveData( 0, "436457r1K3574r7uP71m35", 0 ) <= time_to_helpscreen)
164  whattodraw = 0;
165  else
166  whattodraw = (1|2);
167  currentselection = NULL;
168  factioncolours = new GFXColor[FactionUtil::GetNumFactions()];
169  unselectedalpha = 1.0;
170 
171  sectorOffset = systemOffset = 0;
172 
173  unsigned int p;
174  for (p = 0; p < FactionUtil::GetNumFactions(); p++) {
175  factioncolours[p].r = 1;
176  factioncolours[p].g = 1;
177  factioncolours[p].b = 1;
178  factioncolours[p].a = 1;
179  }
180  for (p = 0; p < NAVTOTALMESHCOUNT; p++)
181  meshcoordinate_x[p] = 0.0;
182  for (p = 0; p < NAVTOTALMESHCOUNT; p++)
183  meshcoordinate_y[p] = 0.0;
184  for (p = 0; p < NAVTOTALMESHCOUNT; p++)
185  meshcoordinate_z[p] = 0.0;
186  for (p = 0; p < NAVTOTALMESHCOUNT; p++)
187  meshcoordinate_z_delta[p] = 0.0;
188  //select target
189  //NAV/MISSION toggle
190  //
191 
192 //HERE GOES THE PARSING
193 
194 //*************************
195  screenskipby4[0] = .3;
196  screenskipby4[1] = .7;
197  screenskipby4[2] = .3;
198  screenskipby4[3] = .7;
199 
200  buttonskipby4_1[0] = .75;
201  buttonskipby4_1[1] = .95;
202  buttonskipby4_1[2] = .85;
203  buttonskipby4_1[3] = .90;
204 
205  buttonskipby4_2[0] = .75;
206  buttonskipby4_2[1] = .95;
207  buttonskipby4_2[2] = .75;
208  buttonskipby4_2[3] = .80;
209 
210  buttonskipby4_3[0] = .75;
211  buttonskipby4_3[1] = .95;
212  buttonskipby4_3[2] = .65;
213  buttonskipby4_3[3] = .70;
214 
215  buttonskipby4_4[0] = .75;
216  buttonskipby4_4[1] = .95;
217  buttonskipby4_4[2] = .55;
218  buttonskipby4_4[3] = .60;
219 
220  buttonskipby4_5[0] = .75;
221  buttonskipby4_5[1] = .95;
222  buttonskipby4_5[2] = .45;
223  buttonskipby4_5[3] = .50;
224 
225  buttonskipby4_6[0] = .75;
226  buttonskipby4_6[1] = .95;
227  buttonskipby4_6[2] = .35;
228  buttonskipby4_6[3] = .40;
229 
230  buttonskipby4_7[0] = .75;
231  buttonskipby4_7[1] = .95;
232  buttonskipby4_7[2] = .25;
233  buttonskipby4_7[3] = .30;
234  if ( !ParseFile( "navdata.xml" ) ) {
235  //start DUMMP VARS
236  screenskipby4[0] = .3;
237  screenskipby4[1] = .7;
238  screenskipby4[2] = .3;
239  screenskipby4[3] = .7;
240 
241  buttonskipby4_1[0] = .75;
242  buttonskipby4_1[1] = .95;
243  buttonskipby4_1[2] = .85;
244  buttonskipby4_1[3] = .90;
245 
246  buttonskipby4_2[0] = .75;
247  buttonskipby4_2[1] = .95;
248  buttonskipby4_2[2] = .75;
249  buttonskipby4_2[3] = .80;
250 
251  buttonskipby4_3[0] = .75;
252  buttonskipby4_3[1] = .95;
253  buttonskipby4_3[2] = .65;
254  buttonskipby4_3[3] = .70;
255 
256  buttonskipby4_4[0] = .75;
257  buttonskipby4_4[1] = .95;
258  buttonskipby4_4[2] = .55;
259  buttonskipby4_4[3] = .60;
260 
261  buttonskipby4_5[0] = .75;
262  buttonskipby4_5[1] = .95;
263  buttonskipby4_5[2] = .45;
264  buttonskipby4_5[3] = .50;
265 
266  buttonskipby4_6[0] = .75;
267  buttonskipby4_6[1] = .95;
268  buttonskipby4_6[2] = .35;
269  buttonskipby4_6[3] = .40;
270 
271  buttonskipby4_7[0] = .75;
272  buttonskipby4_7[1] = .95;
273  buttonskipby4_7[2] = .25;
274  buttonskipby4_7[3] = .30;
275 
276  unsetbit( whattodraw, 4 );
277  for (int i = 0; i < NAVTOTALMESHCOUNT; i++)
278  mesh[i] = NULL;
279  vs_fprintf( stderr, "ERROR: Map mesh file not found!!! Using default: blank mesh.\n" );
280  //end DUMMY VARS
281  }
282  ScreenToCoord( screenskipby4[0] );
283  ScreenToCoord( screenskipby4[1] );
284  ScreenToCoord( screenskipby4[2] );
285  ScreenToCoord( screenskipby4[3] );
286 
287  ScreenToCoord( buttonskipby4_1[0] );
288  ScreenToCoord( buttonskipby4_1[1] );
289  ScreenToCoord( buttonskipby4_1[2] );
290  ScreenToCoord( buttonskipby4_1[3] );
291 
292  ScreenToCoord( buttonskipby4_2[0] );
293  ScreenToCoord( buttonskipby4_2[1] );
294  ScreenToCoord( buttonskipby4_2[2] );
295  ScreenToCoord( buttonskipby4_2[3] );
296 
297  ScreenToCoord( buttonskipby4_3[0] );
298  ScreenToCoord( buttonskipby4_3[1] );
299  ScreenToCoord( buttonskipby4_3[2] );
300  ScreenToCoord( buttonskipby4_3[3] );
301 
302  ScreenToCoord( buttonskipby4_4[0] );
303  ScreenToCoord( buttonskipby4_4[1] );
304  ScreenToCoord( buttonskipby4_4[2] );
305  ScreenToCoord( buttonskipby4_4[3] );
306 
307  ScreenToCoord( buttonskipby4_5[0] );
308  ScreenToCoord( buttonskipby4_5[1] );
309  ScreenToCoord( buttonskipby4_5[2] );
310  ScreenToCoord( buttonskipby4_5[3] );
311 
312  ScreenToCoord( buttonskipby4_6[0] );
313  ScreenToCoord( buttonskipby4_6[1] );
314  ScreenToCoord( buttonskipby4_6[2] );
315  ScreenToCoord( buttonskipby4_6[3] );
316 
317  ScreenToCoord( buttonskipby4_7[0] );
318  ScreenToCoord( buttonskipby4_7[1] );
319  ScreenToCoord( buttonskipby4_7[2] );
320  ScreenToCoord( buttonskipby4_7[3] );
321 
322 //reverse = XMLSupport::parse_bool (vs_config->getVariable ("joystick","reverse_mouse_spr","true"))?1:-1;
323 
324  reverse = -1;
325  if ( (screenskipby4[1]-screenskipby4[0]) < (screenskipby4[3]-screenskipby4[2]) )
326  system_item_scale *= (screenskipby4[1]-screenskipby4[0]); //is actually over 1, which is itself
327  else
328  system_item_scale *= (screenskipby4[3]-screenskipby4[2]);
329  screenoccupation = new navscreenoccupied( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], 1 );
330 
331  //Get special colors from the config
332  float tempcol1[4] = {1, 0.3, 0.3, 1.0};
333  vs_config->getColor( "nav", "current_system", tempcol1, true );
334  currentcol = GFXColor( tempcol1[0], tempcol1[1], tempcol1[2], tempcol1[3] );
335  float tempcol2[4] = {1, 0.77, 0.3, 1.0};
336  vs_config->getColor( "nav", "destination_system", tempcol2, true );
337  destinationcol = GFXColor( tempcol2[0], tempcol2[1], tempcol2[2], tempcol2[3] );
338  float tempcol3[4] = {0.3, 1, 0.3, 1.0};
339  vs_config->getColor( "nav", "selection_system", tempcol3, true );
340  selectcol = GFXColor( tempcol3[0], tempcol3[1], tempcol3[2], tempcol3[3] );
341  float tempcol4[4] = {1, 0.3, 0.3, 1.0};
342  vs_config->getColor( "nav", "path_system", tempcol4, true );
343  pathcol = GFXColor( tempcol4[0], tempcol4[1], tempcol4[2], tempcol4[3] );
344 
345  navcomp->init();
346 }
347 
348 //**********************************
349 
350 //This is the main draw loop for the nav screen
351 //**********************************
353 {
354  if ( !CheckDraw() )
355  return;
356  if (_Universe->AccessCockpit()->GetParent() == NULL)
357  return;
358 
359  //DRAW THE SCREEN MODEL
360  //**********************************
361  Vector p, q, r;
362  static float zrange =
363  XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_nav_zrange", "10" ) );
364  static float zfloor =
365  XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_nav_zfloor", "0.1" ) );
366  _Universe->AccessCamera()->GetOrientation( p, q, r );
368  GFXTRUE,
369  GFXFALSE,
370  GFXTRUE,
371  zfloor,
372  zfloor+zrange );
373 
375  for (int i = 0; i < NAVTOTALMESHCOUNT; i++) {
376  float screen_x = 0.0;
377  float screen_y = 0.0;
378  float screen_z = 0.0;
379 
380  screen_x = meshcoordinate_x[i];
381  screen_y = meshcoordinate_y[i];
382  screen_z = meshcoordinate_z[i];
383  if ( checkbit( buttonstates, (i-1) ) ) //button1 = 0, starts at -1, returning 0, no addition done
384  screen_z += meshcoordinate_z_delta[i];
386 
387  //offset horizontal
388  //***************
389  pos = (p.Cast()*screen_x)+pos;
390  //***************
391 
392  //offset vertical
393  //***************
394  pos = (q.Cast()*screen_y)+pos;
395  //***************
396 
397  //offset sink
398  //***************
399  pos = (r.Cast()*screen_z)+pos;
400  //***************
401 
402  Matrix mat( p, q, r, pos );
403  if (mesh[i]) {
404  mesh[i]->Draw(
405  FLT_MAX, // lod
406  mat );
407  }
408  }
410  Mesh::ProcessUndrawnMeshes(false,true);
412  GFXColor4f( 1, 1, 1, 1 );
413  GFXDisable( TEXTURE0 );
414  GFXDisable( TEXTURE1 );
415  GFXDisable( LIGHTING );
416 
417  GFXHudMode( true );
420  //**********************************
421 
422  screenoccupation->reset();
423 
424  //Save current mouse location
425  //**********************************
426  mouse_x_current = ( -1+float(mousex)/(.5*g_game.x_resolution) );
427  mouse_y_current = ( 1+float(-1*mousey)/(.5*g_game.y_resolution) );
428  //**********************************
429 
430  //Set Mouse
431  //**********************************
432  SetMouseFlipStatus(); //define bools 'mouse_wentdown[]' 'mouse_wentup[]'
433  //**********************************
434  //Draw the Navscreen Functions
435  //**********************************
436  if ( checkbit( whattodraw, 1 ) ) {
437  if ( checkbit( whattodraw, 2 ) ) {
438  if (galaxy_view == VIEW_3D) {
439  DrawNavCircle( ( (screenskipby4[0]+screenskipby4[1])/2.0 ), ( (screenskipby4[2]+screenskipby4[3])/2.0 ),
440  0.6,
441  rx, ry, GFXColor( 1, 1, 1,
442  0.2 ) );
443  } else {
444  DrawGrid( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], GFXColor( 1, 1, 1, 0.2 ) );
445  }
446  DrawGalaxy();
447  } else {
448  if (system_view == VIEW_3D) {
449  DrawNavCircle( ( (screenskipby4[0]+screenskipby4[1])/2.0 ), ( (screenskipby4[2]+screenskipby4[3])/2.0 ),
450  0.6,
451  rx_s, ry_s, GFXColor( 1, 1, 1,
452  0.2 ) );
453  } else {
454  DrawGrid( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], GFXColor( 1, 1, 1, 0.2 ) );
455  }
456  DrawSystem();
457  }
458  } else {
459  if ( checkbit( whattodraw, 3 ) )
460  DrawSectorList();
461  else if ( checkbit( whattodraw, 2 ) )
462  DrawShip();
463  else
464  DrawMission();
465  }
466  //**********************************
467 
468  DrawObjectives();
469 
470  //Draw Button Outlines
471  //**********************************
472  bool outlinebuttons = 0;
473  if (configmode > 0)
474  outlinebuttons = 1;
475  DrawButton( buttonskipby4_1[0], buttonskipby4_1[1], buttonskipby4_1[2], buttonskipby4_1[3], 1, outlinebuttons );
476  DrawButton( buttonskipby4_2[0], buttonskipby4_2[1], buttonskipby4_2[2], buttonskipby4_2[3], 2, outlinebuttons );
477  DrawButton( buttonskipby4_3[0], buttonskipby4_3[1], buttonskipby4_3[2], buttonskipby4_3[3], 3, outlinebuttons );
478  DrawButton( buttonskipby4_4[0], buttonskipby4_4[1], buttonskipby4_4[2], buttonskipby4_4[3], 4, outlinebuttons );
479  DrawButton( buttonskipby4_5[0], buttonskipby4_5[1], buttonskipby4_5[2], buttonskipby4_5[3], 5, outlinebuttons );
480  DrawButton( buttonskipby4_6[0], buttonskipby4_6[1], buttonskipby4_6[2], buttonskipby4_6[3], 6, outlinebuttons );
481  DrawButton( buttonskipby4_7[0], buttonskipby4_7[1], buttonskipby4_7[2], buttonskipby4_7[3], 7, outlinebuttons );
482  //**********************************
483 
484  //Draw the screen basics
485  //**********************************
486  DrawCursor( mouse_x_current, mouse_y_current, .1, .2, GFXColor( 1, 1, 1, 0.5 ) );
487  //**********************************
488 
489  //Save current mouse location as previous for next cycle
490  //**********************************
491  mouse_x_previous = ( -1+float(mousex)/(.5*g_game.x_resolution) );
492  mouse_y_previous = ( 1+float(-1*mousey)/(.5*g_game.y_resolution) );
493  //**********************************
494 
495  GFXEnable( TEXTURE0 );
496  GFXHudMode( false );
497 }
498 //**********************************
499 
500 //This is the mission info screen
501 //**********************************
503 {
504  GFXDisable( TEXTURE0 );
505  GFXDisable( LIGHTING );
507 
508  navdrawlist factionlist( 0, screenoccupation, factioncolours );
509 
510  float deltax = screenskipby4[1]-screenskipby4[0];
511  float deltay = screenskipby4[3]-screenskipby4[2];
512  float originx = screenskipby4[0]; //left
513  float originy = screenskipby4[3]; //top
514  vector< float > *killlist = &_Universe->AccessCockpit()->savegame->getMissionData( string( "kills" ) );
515  string relationskills = "Relations";
516  if (killlist->size() > 0)
517  relationskills += " | Kills";
518  drawdescription( relationskills, ( originx+(0.1*deltax) ), (originy), 1, 1, 0, screenoccupation, GFXColor( .3, 1, .3, 1 ) );
519  drawdescription( " ", ( originx+(0.1*deltax) ), (originy), 1, 1, 0, screenoccupation, GFXColor( .3, 1, .3, 1 ) );
520 
521  drawdescription( " ", ( originx+(0.3*deltax) ), (originy), 1, 1, 0, screenoccupation, GFXColor( .3, 1, .3, 1 ) );
522  drawdescription( " ", ( originx+(0.3*deltax) ), (originy), 1, 1, 0, screenoccupation, GFXColor( .3, 1, .3, 1 ) );
523 
524  size_t numfactions = FactionUtil::GetNumFactions();
525  size_t i = 0;
526  string factionname = "factionname";
527  float relation = 0.0;
528  static string disallowedFactions = vs_config->getVariable( "graphics", "unprintable_factions", "" );
529  static string disallowedExtension = vs_config->getVariable( "graphics", "unprintable_faction_extension", "citizen" );
530  int totkills = 0;
531  size_t fac_loc_before = 0, fac_loc = 0, fac_loc_after = 0;
532  for (; i < numfactions; ++i) {
533  factionname = FactionUtil::GetFactionName( i );
534  if (factionname != "neutral" && factionname != "privateer" && factionname != "planets" && factionname != "upgrades") {
535  if ( i < killlist->size() )
536  totkills += (int) (*killlist)[i];
537  if (factionname.find( disallowedExtension ) != string::npos)
538  continue;
539  fac_loc_after = 0;
540  fac_loc = disallowedFactions.find( factionname, fac_loc_after );
541  while (fac_loc != string::npos) {
542  fac_loc_before = fac_loc-1;
543  if (fac_loc_before < 0)
544  fac_loc_before = 0;
545  fac_loc_after = fac_loc+factionname.size();
546  if ( (fac_loc == 0 || disallowedFactions[fac_loc_before] == ' ' || disallowedFactions[fac_loc_before]
547  == '\t')
548  && (disallowedFactions[fac_loc_after] == ' ' || disallowedFactions[fac_loc_after] == '\t'
549  || disallowedFactions[fac_loc_after] == '\0') )
550  break;
551  fac_loc = disallowedFactions.find( factionname, fac_loc_after );
552  }
553  if (fac_loc != string::npos)
554  continue;
556 
557  //draw faction name
558  const float *colors = FactionUtil::GetSparkColor( i );
560  i ), ( originx+(0.1*deltax) ), (originy), 1, 1, 0, screenoccupation,
561  GFXColor( colors[0], colors[1], colors[2], 1. ) );
562 
563  float relation01 = relation*0.5+0.5;
564  relation = ( (relation > 1 ? 1 : relation) < -1 ? -1 : relation );
565  int percent = (int) (relation*100.0);
566  string relationtext( XMLSupport::tostring( percent ) );
567  if ( i < killlist->size() ) {
568  relationtext += " | ";
569  relationtext += XMLSupport::tostring( (int) (*killlist)[i] );
570  }
571  drawdescription( relationtext, ( originx+(0.3*deltax) ), (originy), 1, 1, 0, screenoccupation,
572  GFXColor( (1.0-relation01), (relation01), ( 1.0-( 2.0*Delta( relation01, 0.5 ) ) ), 1 ) );
573  }
574  }
575  string relationtext( "Total Kills: " );
576  relation = 1;
577 
578  relationtext += XMLSupport::tostring( totkills );
579  drawdescription( relationtext, ( originx+(0.2*deltax) ), ( originy-(0.95*deltay) ), 1, 1, 0, screenoccupation,
580  GFXColor( (1.0-relation), relation, ( 1.0-( 2.0*Delta( relation, 0.5 ) ) ), 1 ) );
581 
582 //drawdescription(" Terran : ", (originx + (0.1*deltax)),(originy - (0.1*deltay)), 1, 1, 0, screenoccupation, GFXColor(.3,1,.3,1));
583 //drawdescription(" Rlaan : ", (originx + (0.1*deltax)),(originy - (0.1*deltay)), 1, 1, 0, screenoccupation, GFXColor(1,.3,.3,1));
584 //drawdescription(" Aera : ", (originx + (0.1*deltax)),(originy - (0.1*deltay)), 1, 1, 0, screenoccupation, GFXColor(.3,.3,1,1));
585 
586 //float love_from_terran = FactionUtil::getRelation(1);
587 //float love_from_rlaan = FactionUtil::getRelation(2);
588 //float love_from_aera = FactionUtil::getRelation(3);
589 
590  TextPlane displayname;
591  displayname.col = GFXColor( 1, 1, 1, 1 );
592  displayname.SetSize( .42, -.7 );
593  displayname.SetPos( originx+(.1*deltax)+.37, originy /*+(1*deltay)*/ );
594  std::string text;
595  if (active_missions.size() > 1) {
596  for (unsigned int i = 1; i < active_missions.size(); ++i) {
597  text += active_missions[i]->mission_name+":\n";
598  for (unsigned int j = 0; j < active_missions[i]->objectives.size(); ++j)
599  text += active_missions[i]->objectives[j].objective+": "
600  +XMLSupport::tostring( (int) (active_missions[i]->objectives[j].completeness*100) )+"%\n";
601  }
602  text += "\n";
603  }
604  text +=
605  "#FFA000 PRESS SHIFT-M TO TOGGLE THIS MENU \n\n\n\n#000000*******#00a6FFVega Strike 0.5#000000*********\nWelcome to VS. Your ship undocks stopped; #8080FFArrow keys/mouse/joystick#000000 steer your ship. Use #8080FF+#000000 & #8080FF-#000000 to adjust cruise control, or #8080FF/#000000 & #8080FF[backspace]#000000 to go to max governor setting or full-stop, respectively. Use #8080FFy#000000 to toggle between maneuver and travel settings for your relative velocity governors. Use #8080ff[home]#000000 & #8080FF[end]#000000 to set and unset velocity reference point to the current target (non-hostile targets only). Use #8080FFTab#000000 to activate Overdrive(if present).\n\nPress #8080FFn#000000 to cycle nav points, #8080FFt#000000 to cycle targets, and #8080FFp#000000 to target objects in front of you.\n\n#8080FF[space]#000000 fires guns, and #8080ff[Enter]#000000 fires missiles.\n\nThe #8080FFa#000000 key activates SPEC drive for insystem FTL.\nInterstellar Travel requires a #FFBB11 jump drive#000000 and #FFBB11FTL Capacitors#000000 to be installed. To jump, fly into the green wireframe nav-marker; hit #8080FFj#000000 to jump to the linked system.\n\nTo dock, target a base, planet or large vessel and hail with #8080FF0#000000 to request docking clearance. When you get close, a green box will appear. Fly to the box. When inside the box, #8080FFd#000000 will dock.\n\n#FF0000If Vega Strike halts or acts oddly,#000000\n#FFFF00immediately#000000 post stderr.txt & stdout.txt\nto http://vegastrike.sourceforge.net/forums\nbefore you restart Vega Strike.\n";
606  displayname.SetText( text );
607  displayname.SetCharSize( 1, 1 );
608  displayname.Draw();
609 /*
610  * string exitinfo("To exit help press #8080FFshift-M#000000\n#8080FFShift-M#000000 will bring up this\nhelp menu any time.\nThe right buttons access the galaxy and system maps");
611  *
612  * displayname.SetSize (.6,-.8);
613  * displayname.SetPos(originx-.02, originy-1.2);
614  * displayname.SetText (exitinfo);
615  * displayname.SetCharSize (1,1);
616  * displayname.Draw();*/
617  GFXEnable( TEXTURE0 );
618 }
619 //**********************************
620 
621 //This is the mission info screen
622 //**********************************
623 extern string MakeUnitXMLPretty( string str, Unit *un );
625 {
626  GFXDisable( TEXTURE0 );
627  GFXDisable( LIGHTING );
629 
630  navdrawlist factionlist( 0, screenoccupation, factioncolours );
631 
632  float deltax = screenskipby4[1]-screenskipby4[0];
633  float deltay = screenskipby4[3]-screenskipby4[2];
634  float originx = screenskipby4[0]; //left
635  float originy = screenskipby4[3]; //top
636  string writethis;
637  Unit *par;
638  int foundpos = 0;
639  if ( ( par = _Universe->AccessCockpit()->GetParent() ) )
640  writethis = MakeUnitXMLPretty( par->WriteUnitString(), par );
641  TextPlane displayname;
642  displayname.col = GFXColor( .3, 1, .3, 1 );
643  displayname.SetSize( .7, -.8 );
644  displayname.SetPos( originx-(.1*deltax), originy /*+(1*deltay)*/ );
645  displayname.SetText( writethis );
646  displayname.SetCharSize( 1, 1 );
647  static float background_alpha =
648  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
649  GFXColor tpbg = displayname.bgcol;
650  bool automatte = (0 == tpbg.a);
651  if (automatte) displayname.bgcol = GFXColor( 0, 0, 0, background_alpha );
652  displayname.Draw( writethis, 0, true, false, automatte );
653  displayname.bgcol = tpbg;
654 
655 //factionlist.drawdescription(writethis, (originx + (0.1*deltax)),(originy - (0.1*deltay)), 1, 1, 1, GFXColor(1,1,1,1));
656 
657  GFXEnable( TEXTURE0 );
658 }
659 
661 {
662  GFXDisable( TEXTURE0 );
663  GFXDisable( LIGHTING );
665 
666  float deltax = screenskipby4[1]-screenskipby4[0];
667  float deltay = screenskipby4[3]-screenskipby4[2];
668  float originx = screenskipby4[0]; //left
669  float originy = screenskipby4[3]; //top
670  float width = (deltax/6);
671  float height = (0.031*deltay);
672  const unsigned numRows = 26;
673  float the_x, the_y, the_x1, the_y1, the_x2, the_y2;
674  GFXColor color;
675  unsigned count, index, row;
676 
677  //Draw Title of Column
678  drawdescription( "Sectors", originx+(0.5*width), originy-(0.0*deltay), 1, 1, 1, screenoccupation,
679  GFXColor( .3, 1, .3, 1 ) );
680 
681  //Draw Scroll Pieces
682  color = GFXColor( 0.7, 0.3, 0.3, 1.0 );
683 
684  the_x = width*(0.5)+originx;
685  the_y = originy-(0.05*deltay);
686  the_x1 = the_x-width/2;
687  the_y1 = the_y-height;
688  the_x2 = the_x+width/2;
689  the_y2 = the_y;
690  if ( TestIfInRange( the_x1, the_x2, the_y1, the_y2, mouse_x_current, mouse_y_current ) ) {
691  if (mouse_wentdown[0] == 1) //mouse button went down for mouse button 1
692  if (sectorOffset > 0)
693  --sectorOffset;
694  }
695  drawdescription( "Up", the_x, the_y, 1, 1, 1, screenoccupation, color );
696 
697  the_x = width*(0.5)+originx;
698  the_y = originy-(0.05*deltay)-height*(29);
699  the_x1 = the_x-width/2;
700  the_y1 = the_y-height;
701  the_x2 = the_x+width/2;
702  the_y2 = the_y;
703  if ( TestIfInRange( the_x1, the_x2, the_y1, the_y2, mouse_x_current, mouse_y_current ) ) {
704  if (mouse_wentdown[0] == 1) //mouse button went down for mouse button 1
705  if ( sectorOffset < (sectorIter.size()-numRows) )
706  ++sectorOffset;
707  }
708  drawdescription( "Down", the_x, the_y, 1, 1, 1, screenoccupation, color );
709 
710  count = 0;
711  for (sectorIter.seek(); !sectorIter.done(); ++sectorIter) {
712  bool drawable = false;
713  for (unsigned i = 0; i < sectorIter->GetSubsystemSize(); i++)
714  if ( systemIter[sectorIter->GetSubsystemIndex( i )].isDrawable() ) {
715  drawable = true;
716  break;
717  }
718  if (!drawable)
719  continue;
720  if ( ( (count-sectorOffset) < 0 ) || ( (count-sectorOffset) >= numRows ) ) {
721  ++count;
722  continue;
723  }
724  row = (count-sectorOffset)%numRows;
725  the_x = width*(0.5)+originx;
726  the_y = originy-(0.05*deltay)-height*(row+2);
727  the_x1 = the_x-width/2;
728  the_y1 = the_y-height;
729  the_x2 = the_x+width/2;
730  the_y2 = the_y;
731  if ( TestIfInRange( the_x1, the_x2, the_y1, the_y2, mouse_x_current, mouse_y_current ) ) {
732  if (mouse_wentdown[0] == 1) {
733  //mouse button went down for mouse button 1
734  sectorselectionindex = sectorIter.getIndex();
735  systemOffset = 0;
736  }
737  }
738  if (sectorIter.getIndex() == sectorselectionindex)
739  color = selectcol;
740  else
741  color = GFXColor( 0.7, 0.3, 0.3, 1.0 );
742  drawdescription( sectorIter->GetName(), the_x, the_y, 1, 1, 1, screenoccupation, color );
743  ++count;
744  }
745  drawdescription( "Systems", originx+(1.5)*width, originy-(0.0*deltay), 1, 1, 1, screenoccupation,
746  GFXColor( .3, 1, .3, 1 ) );
747 
748  //Draw Scroll Pieces
749  color = GFXColor( 0.7, 0.3, 0.3, 1.0 );
750 
751  the_x = width*(1.5)+originx;
752  the_y = originy-(0.05*deltay);
753  the_x1 = the_x-width/2;
754  the_y1 = the_y-height;
755  the_x2 = the_x+width/2;
756  the_y2 = the_y;
757  if ( TestIfInRange( the_x1, the_x2, the_y1, the_y2, mouse_x_current, mouse_y_current ) ) {
758  if (mouse_wentdown[0] == 1) //mouse button went down for mouse button 1
759  if (systemOffset > 0)
760  --systemOffset;
761  }
762  drawdescription( "Up", the_x, the_y, 1, 1, 1, screenoccupation, color );
763 
764  the_x = width*(1.5)+originx;
765  the_y = originy-(0.05*deltay)-height*(29);
766  the_x1 = the_x-width/2;
767  the_y1 = the_y-height;
768  the_x2 = the_x+width/2;
769  the_y2 = the_y;
770  if ( TestIfInRange( the_x1, the_x2, the_y1, the_y2, mouse_x_current, mouse_y_current ) ) {
771  if (mouse_wentdown[0] == 1) //mouse button went down for mouse button 1
772  if ( systemOffset < (sectorIter[sectorselectionindex].GetSubsystemSize()-numRows) )
773  ++systemOffset;
774  }
775  drawdescription( "Down", the_x, the_y, 1, 1, 1, screenoccupation, color );
776 
777  count = 0;
778  sectorIter.seek( sectorselectionindex );
779  for (unsigned i = 0; i < sectorIter->GetSubsystemSize(); ++i) {
780  index = sectorIter->GetSubsystemIndex( i );
781  if ( !systemIter[index].isDrawable() )
782  continue;
783  if ( ( (count-systemOffset) < 0 ) || ( (count-systemOffset) >= numRows ) ) {
784  ++count;
785  continue;
786  }
787  row = (count-systemOffset)%numRows;
788  the_x = width*(1.5)+originx;
789  the_y = originy-(0.05*deltay)-height*(row+2);
790  the_x1 = the_x-width/2;
791  the_y1 = the_y-height;
792  the_x2 = the_x+width/2;
793  the_y2 = the_y;
794  if ( TestIfInRange( the_x1, the_x2, the_y1, the_y2, mouse_x_current, mouse_y_current ) ) {
795  if (mouse_wentdown[0] == 1) {
796  //mouse button went down for mouse button 1
797  unsigned oldselection = systemselectionindex;
798  systemselectionindex = index;
799  if (systemselectionindex == oldselection)
800  setFocusedSystemIndex( systemselectionindex );
801  }
802  }
803  if (index == destinationsystemindex)
804  color = destinationcol;
805  else if (index == focusedsystemindex)
806  color = currentcol;
807  else if (index == systemselectionindex)
808  color = selectcol;
809  else
810  color = GFXColor( 0.7, 0.3, 0.3, 1.0 );
811  string csector, csystem;
812  Beautify( systemIter[index].GetName(), csector, csystem );
813 
814  drawdescription( csystem, the_x, the_y, 1, 1, 1, screenoccupation, color );
815  ++count;
816  }
817 }
818 
820 {
821  if ( checkbit( whattodraw, 4 ) )
822  //Draw the objectives screen!
823  DrawObjectivesTextPlane( &screen_objectives, scrolloffset, _Universe->AccessCockpit()->GetParent() );
824 }
825 
826 //this sets weather to draw the screen or not
827 //**********************************
829 {
830  if (draw == -1) {
831  Setup();
832  draw = 0;
833  }
834  if ( n != (draw == 1) ) {
835  ClearPriorities();
836  scrolloffset = 0;
837  draw = n ? 1 : 0;
838  }
839 }
840 //**********************************
841 
842 //this gets rid of states that could be damaging
843 //**********************************
845 {
846  unsetbit( buttonstates, 1 );
847  currentselection = NULL;
848 //rx = 1.0; // resetting rotations is up to hitting the 2d/3d button
849 //ry = 1.0;
850 //rz = 0.0;
851 //rx_s = 1.0;
852 //ry_s = 1.0;
853 //rz_s = 0.0;
854 }
855 //**********************************
856 
857 //This will set a wentdown and wentup flag just for the event of mouse button going down or up
858 //this is an FF test. not a state test.
859 //**********************************
861 {
862 //getMouseButtonStatus()&1 = mouse button 1 standard = button 1 VS
863 //getMouseButtonStatus()&2 = mouse button 3 standard = button 2 VS
864 //getMouseButtonStatus()&4 = mouse button 2 standard = button 3 VS
865 //getMouseButtonStatus()&8 = mouse wheel up
866 //getMouseButtonStatus()&16 = mouse wheel down
867 
868  //use the VS scheme, (1 2 3 4 5) , instead of standard (1 3 2 4 5)
869  //state 0 = up
870  //state 1 = down
871 
872  bool status = 0;
873  int i;
874  for (i = 0; i < 5; i++) {
875  status = ( getMouseButtonStatus()&(1<<i) ) ? 1 : 0;
876  if ( (status == 1) && (mouse_previous_state[i] == 0) ) {
877  mouse_wentdown[i] = 1;
878  mouse_wentup[i] = 0;
879  } else if ( (status == 0) && (mouse_previous_state[i] == 1) ) {
880  mouse_wentup[i] = 1;
881  mouse_wentdown[i] = 0;
882  } else {
883  mouse_wentup[i] = 0;
884  mouse_wentdown[i] = 0;
885  if (i == 3 || i == 4)
886  mousestat &= ( ~(1<<i) );
887  }
888  }
889  for (i = 0; i < 5; i++)
890  mouse_previous_state[i] = ( getMouseButtonStatus()&(1<<i) ); //button 'i+1' state VS
891 }
892 
893 //**********************************
894 
895 //returns a modified vector rotated by x y z radians
896 //**********************************
897 QVector NavigationSystem::dxyz( QVector vector, double x_, double y_, double z_ )
898 {
899 /*
900  * void Roll (QFLOAT rad){
901  * QFLOAT theta = atan2 (j,i)+rad;
902  * QFloat len = XSQRT (j*j+i*i);
903  * j = sin (theta)*len;
904  * i = cos (theta)*len;
905  * }
906  */
907  if (x_ != 0) {
908  float distance_yz = sqrt( (vector.j*vector.j)+(vector.k*vector.k) );
909  float current_angle = atan2( vector.k, vector.j );
910  current_angle += x_;
911  vector.j = cos( current_angle )*distance_yz;
912  vector.k = sin( current_angle )*distance_yz;
913  }
914  if (y_ != 0) {
915  float distance_xz = sqrt( (vector.i*vector.i)+(vector.k*vector.k) );
916  float current_angle = atan2( vector.k, vector.i );
917  current_angle += y_;
918  vector.i = cos( current_angle )*distance_xz;
919  vector.k = sin( current_angle )*distance_xz;
920  }
921  if (z_ != 0) {
922  float distance_xy = sqrt( (vector.i*vector.i)+(vector.j*vector.j) );
923  float current_angle = atan2( vector.j, vector.i );
924  current_angle += z_;
925  vector.i = cos( current_angle )*distance_xy;
926  vector.j = sin( current_angle )*distance_xy;
927  }
928  return vector;
929 }
930 
931 //**********************************
932 
933 void NavigationSystem::setCurrentSystem( string newSystem )
934 {
935  for (unsigned i = 0; i < systemIter.size(); ++i)
936  if (systemIter[i].GetName() == newSystem) {
937  setCurrentSystemIndex( i );
938  break;
939  }
940 }
941 
942 void NavigationSystem::setFocusedSystemIndex( unsigned newSystemIndex )
943 {
944  focusedsystemindex = newSystemIndex;
945  themaxvalue = 0;
946  if (galaxy_view != VIEW_3D) {
947  //This resets the panning position when not in 3d view.
948  //Otehrwise, the focused system may end up off screen which will cause a lot of confusion.
949  rx = -0.5; //galaxy mode settings
950  ry = 0.5;
951  rz = 0.0;
952  }
953  camera_z = 0; //calculate camera distance again... it may have changed.
954 }
955 
956 void NavigationSystem::setCurrentSystemIndex( unsigned newSystemIndex )
957 {
958  currentsystemindex = newSystemIndex;
959  static bool AlwaysUpdateNavMap =
960  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "update_nav_after_jump", "false" ) ); //causes occasional crash--only may have tracked it down
961  if (AlwaysUpdateNavMap)
963 }
964 
965 void NavigationSystem::setDestinationSystemIndex( unsigned newSystemIndex )
966 {
967  destinationsystemindex = newSystemIndex;
969 }
970 
972 {
973  if ( factioncolours == NULL || focusedsystemindex >= systemIter.size() )
975  return systemIter[currentsystemindex].GetName();
976 }
978 {
979  if ( factioncolours == NULL || focusedsystemindex >= systemIter.size() )
981  return systemIter[systemselectionindex].GetName();
982 }
984 {
985  if ( factioncolours == NULL || focusedsystemindex >= systemIter.size() )
987  return systemIter[destinationsystemindex].GetName();
988 }
990 {
991  if ( factioncolours == NULL || focusedsystemindex >= systemIter.size() )
993  return systemIter[focusedsystemindex].GetName();
994 }
995 
996 //Passes a draw button command, with colour
997 //Tests for a mouse over, to set colour
998 //**********************************
999 //1 = nav/mission
1000 //2 = select currentselection
1001 //3 = up
1002 //4 = down
1003 //5 = toggle prespective rezoom
1004 //6 = toggle 2d/3d mode
1005 int NavigationSystem::mousey = 0;
1006 int NavigationSystem::mousex = 0;
1008 
1009 void NavigationSystem::DrawButton( float &x1, float &x2, float &y1, float &y2, int button_number, bool outline )
1010 {
1011  float mx = mouse_x_current;
1012  float my = mouse_y_current;
1013  bool inrange = TestIfInRange( x1, x2, y1, y2, mx, my );
1014 
1015  string label;
1016  if (button_number == 1) {
1017  label = "Nav/Info";
1018  } else if (button_number == 3) {
1019  label = "Target Selected";
1020  } else if (button_number == 7) {
1021  label = "2D/Ortho/3D";
1022  } else if ( checkbit( whattodraw, 1 ) ) {
1023  if (button_number == 2)
1024  label = "Path On/Off/Only";
1025  else if (button_number == 4)
1026  label = "Up";
1027  else if (button_number == 5)
1028  label = "Down";
1029  else if (button_number == 6)
1030  label = "Axis Swap";
1031  } else {
1032  if (button_number == 2)
1033  label = "Sectors";
1034  else if (button_number == 4)
1035  label = "Ship";
1036  else if (button_number == 5)
1037  label = "Mission";
1038  else if (button_number == 6)
1039  label = "Nav Comp";
1040  }
1041  TextPlane a_label;
1042  a_label.col = GFXColor( 1, 1, 1, 1 );
1043  int length = label.size();
1044  float offset = (float(length)*0.0065);
1045  float xl = (x1+x2)/2.0;
1046  float yl = (y1+y2)/2.0;
1047  a_label.SetPos( (xl-offset)-(checkbit( buttonstates, button_number-1 ) ? 0.006 : 0), (yl+0.025) );
1048  a_label.SetText( label );
1049  static bool nav_button_labels =
1050  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_nav_button_labels", "true" ) );
1051  if (nav_button_labels) {
1052  static float background_alpha =
1053  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1054  GFXColor tpbg = a_label.bgcol;
1055  bool automatte = (0 == tpbg.a);
1056  if (automatte) a_label.bgcol = GFXColor( 0, 0, 0, background_alpha );
1057  a_label.Draw( label, 0, true, false, automatte );
1058  a_label.bgcol = tpbg;
1059  }
1061  if ( (inrange == 1) && (mouse_wentdown[0] == 1) ) {
1062  currentselection = NULL; //any new button depression means no depression on map, no selection made
1063 
1064  //******************************************************
1065  //** DEPRESS FUNCTION ** DEPRESS ALL
1066  //******************************************************
1067 
1068  dosetbit( buttonstates, (button_number-1) ); //all buttons go down
1069 
1070  //******************************************************
1071  }
1073  if ( (inrange == 1) && ( checkbit( buttonstates, (button_number-1) ) ) && (mouse_wentup[0]) ) {
1074  //******************************************************
1075  //** MISSION MODE ** UNSET BITS WHEN ENTERING MISSION MODE
1076  //******************************************************
1077  if ( !checkbit( whattodraw, 1 ) )
1078  unsetbit( buttonstates, (button_number-1) ); //all are up in mission mode
1079  else
1080  unsetbit( buttonstates, (button_number-1) ); //all are up in navigation mode
1081  //******************************************************
1082  //******************************************************
1083  //** BUTTON 1 FUNCTION ** NAV-INFO vs STATUS-INFO
1084  //******************************************************
1085  if (button_number == 1) //releasing #1, toggle the draw (nav / mission)
1086  flipbit( whattodraw, 1 );
1087  //******************************************************
1088  //******************************************************
1089  //** BUTTON 2 FUNCTION ** PATH options
1090  //******************************************************
1091  if (button_number == 2) {
1092  //releasing #2, toggle the path viewing settings(off/on/only)
1093  if ( ( checkbit( whattodraw, 1 ) ) && ( checkbit( whattodraw, 2 ) ) )
1094  path_view = (path_view+1)%PATH_MAXIMUM;
1095  else if ( !checkbit( whattodraw, 1 ) )
1096  dosetbit( whattodraw, 3 );
1097  }
1098  //******************************************************
1099  //******************************************************
1100  //** BUTTON 3 FUNCTION ** TARGET SELECTED SYSTEM
1101  //******************************************************
1102  if (button_number == 3) {
1103  //hit --TARGET--
1104  if ( ( ( checkbit( whattodraw, 1 ) ) && ( checkbit( whattodraw, 2 ) ) ) //Nav-Galaxy Mode
1105  || ( ( !checkbit( whattodraw, 1 ) ) && ( checkbit( whattodraw, 3 ) ) ) ) //Mission-Sector Mode
1106  setDestinationSystemIndex( systemselectionindex );
1107  }
1108  //******************************************************
1109  //******************************************************
1110  //** BUTTON 4 FUNCTION ** UP
1111  //******************************************************
1112  if (button_number == 4) {
1113  //hit --UP--
1114  if ( checkbit( whattodraw, 1 ) ) {
1115  //if in nav system NOT mission
1116  dosetbit( whattodraw, 2 ); //draw galaxy
1117  setFocusedSystemIndex( currentsystemindex );
1118  systemselectionindex = currentsystemindex;
1119  } else {
1120  //if in mission mode
1121  unsetbit( whattodraw, 3 );
1122  dosetbit( whattodraw, 2 ); //draw shipstats
1123  }
1124  }
1125  //******************************************************
1126  //******************************************************
1127  //** BUTTON 5 FUNCTION ** DOWN
1128  //******************************************************
1129  if (button_number == 5) {
1130  //hit --DOWN--
1131  if ( checkbit( whattodraw, 1 ) ) {
1132  //if in nav system NOT mission
1133 
1134  unsetbit( whattodraw, 2 ); //draw system
1135  } else {
1136  //if in mission mode
1137  unsetbit( whattodraw, 3 );
1138  unsetbit( whattodraw, 2 ); //draw mission
1139  }
1140  }
1141  //******************************************************
1142  //******************************************************
1143  //** BUTTON 6 FUNCTION ** AXIS
1144  //******************************************************
1145  if (button_number == 6) {
1146  //releasing #1, toggle the draw (nav / mission)
1147  if ( checkbit( whattodraw, 1 ) ) {
1148  //if in nav system NOT mission
1149  zoom = 1.8;
1150  zoom_s = 1.8;
1151 
1152  axis = axis-1;
1153  if (axis == 0)
1154  axis = 3;
1155  camera_z = 0;
1156  } else {
1157  //if in mission mode
1158 
1159  navcomp->run();
1160  }
1161  }
1162  //******************************************************
1163  //******************************************************
1164  //** BUTTON 7 FUNCTION ** 2D/3D
1165  //******************************************************
1166  if (button_number == 7) {
1167  if ( ( checkbit( whattodraw, 1 ) ) && ( checkbit( whattodraw, 2 ) ) && galaxy_multi_dimensional ) {
1168  galaxy_view = (galaxy_view+1)%VIEW_MAX;
1169  rx = -0.5;
1170  ry = 0.5;
1171  rz = 0.0;
1172  }
1173  if ( ( checkbit( whattodraw, 1 ) ) && ( !checkbit( whattodraw, 2 ) ) && system_multi_dimensional ) {
1174  system_view = (system_view+1)%VIEW_MAX;
1175  rx_s = -0.5;
1176  ry_s = 0.5;
1177  rz_s = 0.0;
1178  }
1179  camera_z = 0;
1180  }
1181  //******************************************************
1182  }
1184  //******************************************************
1185  //** OUT OF RANGE ** ALL DIE
1186  //******************************************************
1187  if (inrange == 0)
1188  unsetbit( buttonstates, (button_number-1) );
1189  //******************************************************
1190  //******************************************************
1191  //** TRACE OUTLINES FOR EZ SETUP ** ARTIST DEV UTIL
1192  //******************************************************
1193  if (outline == 1) {
1194  if (inrange == 1) {
1195  if ( checkbit( buttonstates, (button_number-1) ) )
1196  DrawButtonOutline( x1, x2, y1, y2, GFXColor( 1, 0, 0, 1 ) );
1197 
1198  else
1199  DrawButtonOutline( x1, x2, y1, y2, GFXColor( 1, 1, 0, 1 ) );
1200  } else {
1201  if ( checkbit( buttonstates, (button_number-1) ) )
1202  DrawButtonOutline( x1, x2, y1, y2, GFXColor( 1, 0, 0, 1 ) );
1203  else
1204  DrawButtonOutline( x1, x2, y1, y2, GFXColor( 1, 1, 1, 1 ) );
1205  }
1206  }
1207  //******************************************************
1208 }
1209 //**********************************
1210 
1211 //Draws the actual button outline
1212 //**********************************
1213 void NavigationSystem::DrawButtonOutline( float &x1, float &x2, float &y1, float &y2, const GFXColor &col )
1214 {
1215  GFXColorf( col );
1216  GFXDisable( TEXTURE0 );
1217  GFXDisable( LIGHTING );
1219 
1220  GFXBegin( GFXLINE );
1221  GFXVertex3f( x1, y1, 0 );
1222  GFXVertex3f( x1, y2, 0 );
1223  GFXVertex3f( x2, y1, 0 );
1224  GFXVertex3f( x2, y2, 0 );
1225  GFXVertex3f( x1, y1, 0 );
1226  GFXVertex3f( x2, y1, 0 );
1227  GFXVertex3f( x1, y2, 0 );
1228  GFXVertex3f( x2, y2, 0 );
1229  GFXEnd();
1230 
1231  GFXEnable( TEXTURE0 );
1232 }
1233 //**********************************
1234 
1235 template < class T >
1236 static inline bool intersect( T x0, T y0, T x1, T y1, T sx0, T sy0, T sx1, T sy1, T &ansx, T &ansy )
1237 {
1238  bool fxy = false;
1239  if ( ( (x1 == x0) && (sx1 == sx0) ) || ( (x1 == x0) && (y1 == y0) ) || ( (sx1 == sx0) && (sy1 == sy0) ) ) {
1240  //If both lines are vertical, then act as if they don't intersect.
1241  //If either one is a point, then for all practical purposes they do not intersect.
1242  return false;
1243  }
1244  if ( (x1 == x0) && (sy1 == sy0) ) {
1245  //Line 1 vertical, line 2 horizontal.
1246  ansx = x1;
1247  ansy = sy1;
1248  return ( (sx0 <= x1
1249  && x1 <= sx1) || (sx1 <= x1 && x1 <= sx0) ) && ( (y0 <= sy1 && sy1 <= y1) || (y1 <= sy1 && sy1 <= y0) );
1250  }
1251  if ( (sx1 == sx0) && (y1 == y0) ) {
1252  //line 1 horizontal, Line 2 vertical.
1253  ansx = sx1;
1254  ansy = y1;
1255  return ( (x0 <= sx1
1256  && sx1 <= x1) || (x1 <= sx1 && sx1 <= x0) ) && ( (sy0 <= y1 && y1 <= sy1) || (sy1 <= y1 && y1 <= sy0) );
1257  }
1258  //If either line is vertical (both was handled above), then flip the coordinate plane to prevent division by zero.
1259  if ( (x1 == x0) || (sx1 == sx0) ) {
1260  T temp = x0;
1261  x0 = y0;
1262  y0 = temp;
1263  temp = x1;
1264  x1 = y1;
1265  y1 = temp;
1266  fxy = true;
1267  temp = sx0;
1268  sx0 = sy0;
1269  sy0 = temp;
1270  temp = sx1;
1271  sx1 = sy1;
1272  sy1 = temp;
1273  fxy = true;
1274  }
1275  //Now we can be sure that no vertical lines exist.
1276  //Proceed with the operation.
1277  T m = (y1-y0)/(x1-x0);
1278  T sm = (sy1-sy0)/(sx1-sx0);
1279  if (m == sm)
1280  //Parallel Lines
1281  return false;
1282  ansx = (m*x1-sm*sx1-y1+sy1)/(m-sm);
1283  ansy = (y1-m*x1+m*ansx);
1284  if ( ( (x0 <= ansx
1285  && ansx <= x1)
1286  || (x1 <= ansx && ansx <= x0) ) && ( (sx0 <= ansx && ansx <= sx1) || (sx1 <= ansx && ansx <= sx0) ) ) {
1287  //Inside the line segment.
1288  if (fxy) {
1289  //Deswapify them!
1290  T temp = ansx;
1291  ansx = ansy;
1292  ansy = temp;
1293  }
1294  return true;
1295  }
1296  //Too bad. They are outside the line segment
1297  return false;
1298 }
1299 
1300 void NavigationSystem::IntersectBorder( float &x, float &y, const float &x1, const float &y1 ) const
1301 {
1302  float ansx;
1303  float ansy;
1304  if ( intersect( x, y, x1, y1, screenskipby4[1], screenskipby4[3], screenskipby4[0], screenskipby4[3], ansx, ansy )
1305  || intersect( x, y, x1, y1, screenskipby4[0], screenskipby4[2], screenskipby4[0], screenskipby4[3], ansx, ansy )
1306  || intersect( x, y, x1, y1, screenskipby4[0], screenskipby4[2], screenskipby4[1], screenskipby4[2], ansx, ansy )
1307  || intersect( x, y, x1, y1, screenskipby4[1], screenskipby4[3], screenskipby4[1], screenskipby4[2], ansx, ansy ) ) {
1308  x = ansx;
1309  y = ansy;
1310  }
1311 }
1312 
1313 //tests if given are in the range
1314 //**********************************
1315 bool NavigationSystem::TestIfInRange( float &x1, float &x2, float &y1, float &y2, float tx, float ty )
1316 {
1317  if ( ( (tx < x2) && (tx > x1) ) && ( (ty < y2) && (ty > y1) ) )
1318  return 1;
1319  else
1320  return 0;
1321 }
1322 //**********************************
1323 
1324 //tests if given are in the circle range
1325 //**********************************
1326 bool NavigationSystem::TestIfInRangeRad( float &x, float &y, float size, float tx, float ty )
1327 {
1328  if ( ( ( (x-tx)*(x-tx) )+( (y-ty)*(y-ty) ) ) < ( (0.5*size)*(0.5*size) ) )
1329  return 1;
1330  else
1331  return 0;
1332 }
1333 
1334 //**********************************
1335 
1336 //Tests if given are in block range
1337 //**********************************
1338 bool NavigationSystem::TestIfInRangeBlk( float &x, float &y, float size, float tx, float ty )
1339 {
1340  if ( ( Delta( tx, x ) < (0.5*size) ) && ( Delta( ty, y ) < (0.5*size) ) )
1341  return 1;
1342  else
1343  return 0;
1344 }
1345 //**********************************
1346 
1347 /*
1348  * // Gived the delta of 2 items
1349  * // **********************************
1350  * float NavigationSystem::Delta(float a, float b)
1351  * {
1352  *
1353  * float ans = a-b;
1354  * if(ans < 0)
1355  * return (-1.0 * ans);
1356  * else
1357  * return ans;
1358  * }
1359  * // **********************************
1360  */
1361 
1362 //converts the % of screen system to 0-center system
1363 //**********************************
1365 {
1366  x -= .5;
1367  x *= 2;
1368 }
1369 //**********************************
1370 
1371 //checks if the draw flag is 1
1372 //**********************************
1374 {
1375  return draw == 1;
1376 }
1377 //**********************************
1378 
1379 void NavigationSystem::Adjust3dTransformation( bool three_d, bool system_vs_galaxy )
1380 {
1381  //Adjust transformation
1382  //**********************************
1383  if ( (mouse_previous_state[0] == 1)
1384  && TestIfInRange( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], mouse_x_current,
1385  mouse_y_current ) ) {
1386  if (system_vs_galaxy) {
1387  if (three_d) {
1388  float ndx = -1.0*(mouse_y_current-mouse_y_previous);
1389  float ndy = -4.0*(mouse_x_current-mouse_x_previous);
1390  float ndz = 0.0;
1391 
1392  rx_s = rx_s += ndx;
1393  ry_s = ry_s += ndy;
1394  rz_s = rz_s += ndz;
1395  if (rx_s > 0.0/2) rx_s = 0.0/2;
1396  if (rx_s < -6.28/2) rx_s = -6.28/2;
1397  if (ry_s >= 6.28) ry_s -= 6.28;
1398  if (ry_s <= -6.28) ry_s += 6.28;
1399  if (rz_s >= 6.28) rz_s -= 6.28;
1400  if (rz_s <= -6.28) rz_s += 6.28;
1401  } else {
1402  //rotation switches to panning
1403  float ndy = -1.0*(mouse_y_current-mouse_y_previous);
1404  float ndx = -1.0*(mouse_x_current-mouse_x_previous);
1405  float ndz = 0.0;
1406 
1407  //shift less when zoomed in more
1408  //float zoom_modifier = ( (1-(((zoom_s-0.5*MAXZOOM)/MAXZOOM)*(0.85))) / 1 );
1409 //float _l2 = log(2.0);
1410  float zoom_modifier = 1.; //(log(zoom_s)/_l2);
1411 
1412  rx_s = rx_s -= ( (ndx*camera_z)/zoom_modifier );
1413  ry_s = ry_s -= ( (ndy*camera_z)/zoom_modifier );
1414  rz_s = rz_s -= ( (ndz*camera_z)/zoom_modifier );
1415  }
1416  } else {
1417  //galaxy
1418  if (three_d) {
1419  float ndx = -1.0*(mouse_y_current-mouse_y_previous);
1420  float ndy = -4.0*(mouse_x_current-mouse_x_previous);
1421  float ndz = 0.0;
1422 
1423  rx = rx += ndx;
1424  ry = ry += ndy;
1425  rz = rz += ndz;
1426  if (rx > 0.0/2) rx = 0.0/2;
1427  if (rx < -6.28/2) rx = -6.28/2;
1428  if (ry >= 6.28) ry -= 6.28;
1429  if (ry <= -6.28) ry += 6.28;
1430  if (rz >= 6.28) rz -= 6.28;
1431  if (rz <= -6.28) rz += 6.28;
1432  } else {
1433  //rotation switches to panning
1434  float ndy = -1.0*(mouse_y_current-mouse_y_previous);
1435  float ndx = -1.0*(mouse_x_current-mouse_x_previous);
1436  float ndz = 0.0;
1437 
1438  //shift less when zoomed in more
1439  //float zoom_modifier = ( (1-(((zoom-0.5*MAXZOOM)/MAXZOOM)*(0.85))) / 1 );
1440 //float _l2 = log(2.0);
1441  float zoom_modifier = 1.; //(log(zoom)/_l2);
1442 
1443  rx = rx -= ( (ndx*camera_z)/zoom_modifier );
1444  ry = ry -= ( (ndy*camera_z)/zoom_modifier );
1445  rz = rz -= ( (ndz*camera_z)/zoom_modifier );
1446  }
1447  }
1448  }
1449  //**********************************
1450  //Set the prespective zoom level
1451  //**********************************
1452  if ( ( (mouse_previous_state[1] == 1)
1453  && TestIfInRange( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], mouse_x_current,
1454  mouse_y_current ) ) || (mouse_wentdown[3] || mouse_wentdown[4]) ) {
1455  static float wheel_zoom_level = XMLSupport::parse_float( vs_config->getVariable( "graphics", "wheel_zoom_amount", "0.1" ) );
1456  if (system_vs_galaxy) {
1457  if (mouse_wentdown[3])
1458  zoom_s += wheel_zoom_level;
1459  else if (mouse_wentdown[4])
1460  zoom_s -= wheel_zoom_level;
1461  else
1462  zoom_s = zoom_s+( /*1.0 +*/ 8*(mouse_y_current-mouse_y_previous) );
1463  //if(zoom < 1.0)
1464  //zoom = 1.0;
1465 //static float zoommax = XMLSupport::parse_float (vs_config->getVariable("graphics","nav_zoom_max","100"));
1466  if (zoom_s < 1.2)
1467  zoom_s = 1.2;
1468  if (zoom_s > MAXZOOM)
1469  zoom_s = MAXZOOM;
1470  } else {
1471  if (mouse_wentdown[3])
1472  zoom += wheel_zoom_level;
1473  else if (mouse_wentdown[4])
1474  zoom -= wheel_zoom_level;
1475  else
1476  zoom = zoom+( /*1.0 +*/ 8*(mouse_y_current-mouse_y_previous) );
1477  //if(zoom < 1.0)
1478  //zoom = 1.0;
1479 //static float zoommax = XMLSupport::parse_float (vs_config->getVariable("graphics","nav_zoom_max","100"));
1480  if (zoom < .5)
1481  zoom = .5;
1482  if (zoom > MAXZOOM/2)
1483  zoom = MAXZOOM/2;
1484  }
1485  }
1486  //**********************************
1487 }
1488 
1489 void NavigationSystem::ReplaceAxes( QVector &pos )
1490 {
1491  //replace axes
1492  //*************************
1493  if (axis != 3) {
1494  //3 == z == default
1495  if (axis == 2) {
1496  float old_i = pos.i;
1497  float old_j = pos.j;
1498  float old_k = pos.k;
1499  pos.i = old_i;
1500  pos.j = -old_k;
1501  pos.k = old_j;
1502  } else {
1503  //(axis == 1)
1504  float old_i = pos.i;
1505  float old_j = pos.j;
1506  float old_k = pos.k;
1507  pos.i = old_j;
1508  pos.j = -old_k;
1509  pos.k = old_i;
1510  }
1511  }
1512  //*************************
1513 }
1514 
1515 void NavigationSystem::RecordMinAndMax( const QVector &pos,
1516  float &min_x,
1517  float &max_x,
1518  float &min_y,
1519  float &max_y,
1520  float &min_z,
1521  float &max_z,
1522  float &max_all )
1523 {
1524  //Record min and max
1525  //**********************************
1526  if ( (float) pos.i > max_x )
1527  max_x = (float) pos.i;
1528  if ( (float) pos.i < min_x )
1529  min_x = (float) pos.i;
1530 //if( fabs((float)pos.i) > max_all )
1531 //max_all = fabs((float)pos.i);
1532  if ( ( fabs( max_x-min_x ) ) > max_all )
1533  max_all = 0.5*( fabs( max_x-min_x ) );
1534  if ( (float) pos.j > max_y )
1535  max_y = (float) pos.j;
1536  if ( (float) pos.j < min_y )
1537  min_y = (float) pos.j;
1538 //if( fabs((float)pos.j) > max_all )
1539 //max_all = fabs((float)pos.j);
1540  if ( ( fabs( max_y-min_y ) ) > max_all )
1541  max_all = 0.5*( fabs( max_y-min_y ) );
1542  if ( (float) pos.k > max_z )
1543  max_z = (float) pos.k;
1544  if ( (float) pos.k < min_z )
1545  min_z = (float) pos.k;
1546 //if( fabs((float)pos.k) > max_all )
1547 //max_all = fabs((float)pos.k);
1548  if ( ( fabs( max_z-min_z ) ) > max_all )
1549  max_all = 0.5*( fabs( max_z-min_z ) );
1550  //**********************************
1551 }
1552 
1553 void NavigationSystem::DrawOriginOrientationTri( float center_nav_x, float center_nav_y, bool system_not_galaxy )
1554 {
1555  //Draw Origin Orientation Tri
1556  //**********************************
1557  QVector directionx;
1558  QVector directiony;
1559  QVector directionz;
1560  if (axis == 2) {
1561  directionx.i = 0.1;
1562  directionx.j = 0.0;
1563  directionx.k = 0.0;
1564 
1565  directionz.i = 0.0;
1566  directionz.j = 0.1;
1567  directionz.k = 0.0;
1568 
1569  directiony.i = 0.0;
1570  directiony.j = 0.0;
1571  directiony.k = 0.1;
1572  } else if (axis == 1) {
1573  directiony.i = 0.1;
1574  directiony.j = 0.0;
1575  directiony.k = 0.0;
1576 
1577  directionz.i = 0.0;
1578  directionz.j = 0.1;
1579  directionz.k = 0.0;
1580 
1581  directionx.i = 0.0;
1582  directionx.j = 0.0;
1583  directionx.k = 0.1;
1584  } else {
1585  //(axis == 3)
1586  directionx.i = 0.1;
1587  directionx.j = 0.0;
1588  directionx.k = 0.0;
1589 
1590  directiony.i = 0.0;
1591  directiony.j = 0.1;
1592  directiony.k = 0.0;
1593 
1594  directionz.i = 0.0;
1595  directionz.j = 0.0;
1596  directionz.k = 0.1;
1597  }
1598  if (system_not_galaxy) {
1599  if (system_view == VIEW_3D) {
1600  directionx = dxyz( directionx, 0, 0, ry_s );
1601  directionx = dxyz( directionx, rx_s, 0, 0 );
1602 
1603  directiony = dxyz( directiony, 0, 0, ry_s );
1604  directiony = dxyz( directiony, rx_s, 0, 0 );
1605 
1606  directionz = dxyz( directionz, 0, 0, ry_s );
1607  directionz = dxyz( directionz, rx_s, 0, 0 );
1608  }
1609  } else if (galaxy_view == VIEW_3D) {
1610  directionx = dxyz( directionx, 0, 0, ry );
1611  directionx = dxyz( directionx, rx, 0, 0 );
1612 
1613  directiony = dxyz( directiony, 0, 0, ry );
1614  directiony = dxyz( directiony, rx, 0, 0 );
1615 
1616  directionz = dxyz( directionz, 0, 0, ry );
1617  directionz = dxyz( directionz, rx, 0, 0 );
1618  }
1619  GFXDisable( TEXTURE0 );
1620  GFXDisable( LIGHTING );
1622 
1623  float where_x = center_nav_x-0.8*( (screenskipby4[1]-screenskipby4[0])/2 );
1624  float where_y = center_nav_y-0.8*( (screenskipby4[3]-screenskipby4[2])/2 );
1625 
1626  GFXBegin( GFXLINE );
1627 
1628  GFXColorf( GFXColor( 1, 0, 0, 0.5 ) );
1629  GFXVertex3f( where_x, where_y, 0 );
1630  GFXVertex3f( where_x+( directionx.i*( 0.3/(0.3-directionx.k) ) ),
1631  where_y+( directionx.j*( 0.3/(0.3-directionx.k) ) ),
1632  0 );
1633 
1634  GFXColorf( GFXColor( 0, 1, 0, 0.5 ) );
1635  GFXVertex3f( where_x, where_y, 0 );
1636  GFXVertex3f( where_x+( directiony.i*( 0.3/(0.3-directiony.k) ) ),
1637  where_y+( directiony.j*( 0.3/(0.3-directiony.k) ) ),
1638  0 );
1639 
1640  GFXColorf( GFXColor( 0, 0, 1, 0.5 ) );
1641  GFXVertex3f( where_x, where_y, 0 );
1642  GFXVertex3f( where_x+( directionz.i*( 0.3/(0.3-directionz.k) ) ),
1643  where_y+( directionz.j*( 0.3/(0.3-directionz.k) ) ),
1644  0 );
1645 
1646  GFXEnd();
1647  GFXEnable( TEXTURE0 );
1648  //**********************************
1649 }
1650 
1651 float NavigationSystem::CalculatePerspectiveAdjustment( float &zscale,
1652  float &zdistance,
1653  QVector &pos,
1654  QVector &pos_flat,
1655  float &system_item_scale_temp,
1656  bool system_not_galaxy )
1657 {
1658  pos_flat.i = pos.i;
1659  pos_flat.j = pos.j;
1660  pos_flat.k = center_z;
1661 
1662  //Modify by rotation amount
1663  //*************************
1664 
1665  pos.i -= center_x;
1666  pos.j -= center_y;
1667  pos.k -= center_z;
1668 
1669  pos_flat.i -= center_x;
1670  pos_flat.j -= center_y;
1671  pos_flat.k -= center_z;
1672  if (system_not_galaxy) {
1673  if (system_view == VIEW_3D) {
1674  //3d = rotate
1675  pos = dxyz( pos, 0, 0, ry_s );
1676  pos = dxyz( pos, rx_s, 0, 0 );
1677 
1678  pos_flat = dxyz( pos_flat, 0, 0, ry_s );
1679  pos_flat = dxyz( pos_flat, rx_s, 0, 0 );
1680  } else {
1681  //2d = pan
1682  pos.i += rx_s;
1683  pos.j += ry_s;
1684 
1685  pos_flat.i += rx_s;
1686  pos_flat.j += ry_s;
1687  }
1688  } else {
1689  if (galaxy_view == VIEW_3D) {
1690  //3d = rotate
1691  pos = dxyz( pos, 0, 0, ry );
1692  pos = dxyz( pos, rx, 0, 0 );
1693 
1694  pos_flat = dxyz( pos_flat, 0, 0, ry );
1695  pos_flat = dxyz( pos_flat, rx, 0, 0 );
1696  } else {
1697  //2d = pan
1698  pos.i += rx;
1699  pos.j += ry;
1700 
1701  pos_flat.i += rx;
1702  pos_flat.j += ry;
1703  }
1704  }
1705  //*************************
1706 
1707  //CALCULATE PRESPECTIVE ADJUSTMENT
1708  //**********************************
1709 
1710  float standard_unit = 0.25*camera_z; //maxvalue=X, camera_z=4X
1711 
1712  zdistance = (camera_z-pos.k); //3-5 standard_unit
1713  double zdistance_flat = (camera_z-pos_flat.k);
1714 
1715  zscale = standard_unit/zdistance; //1 / (zdistance/standard_unit)
1716  double zscale_flat = standard_unit/zdistance_flat;
1717 
1718  double real_zoom = 0.0;
1719  double real_zoom_flat = 0.0;
1720 //float _l2 = log(2.0f);
1721  if (system_not_galaxy) {
1722  real_zoom = zoom_s*zoom_s*zscale;
1723  real_zoom_flat = zoom_s*zoom_s*zscale_flat;
1724 //real_zoom = zoom_s*zscale;
1725 //real_zoom_flat = zoom_s*zscale_flat;
1728  } else {
1729  real_zoom = zoom*zoom*zscale;
1730  real_zoom_flat = zoom*zoom*zscale_flat;
1731 //real_zoom = (log(zoom)/_l2)*zscale;
1732 //real_zoom_flat = (log(zoom)/_l2)*zscale_flat;
1733  }
1734  pos.i *= real_zoom;
1735  pos.j *= real_zoom;
1736  pos.k *= real_zoom;
1737 
1738  pos_flat.i *= real_zoom_flat;
1739  pos_flat.j *= real_zoom_flat;
1740  pos_flat.k *= real_zoom_flat;
1741 
1742  float itemscale = real_zoom*item_zscalefactor;
1743  if (itemscale < minimumitemscaledown) //dont shrink into nonexistance
1744  itemscale = minimumitemscaledown;
1745  if (itemscale > maximumitemscaleup) //dont expand too far
1746  itemscale = maximumitemscaleup;
1747  system_item_scale_temp = system_item_scale*itemscale;
1748  //**********************************
1749  return itemscale;
1750 }
1751 
1752 void NavigationSystem::TranslateCoordinates( QVector &pos,
1753  QVector &pos_flat,
1754  float center_nav_x,
1755  float center_nav_y,
1756  float themaxvalue,
1757  float &zscale,
1758  float &zdistance,
1759  float &the_x,
1760  float &the_y,
1761  float &the_x_flat,
1762  float &the_y_flat,
1763  float &system_item_scale_temp,
1764  bool system_not_galaxy )
1765 {
1766  float itemscale = CalculatePerspectiveAdjustment( zscale,
1767  zdistance,
1768  pos,
1769  pos_flat,
1770  system_item_scale_temp,
1771  system_not_galaxy );
1772 
1773  //TRANSLATE INTO SCREEN DISPLAY COORDINATES
1774  //**********************************
1775  the_x = (float) pos.i;
1776  the_y = (float) pos.j;
1777  the_x_flat = (float) pos_flat.i;
1778  the_y_flat = (float) pos_flat.j;
1779 
1780  the_x = ( the_x/(themaxvalue) );
1781  the_y = ( the_y/(themaxvalue) );
1782 
1783  the_x_flat = ( the_x_flat/(themaxvalue) );
1784  the_y_flat = ( the_y_flat/(themaxvalue) );
1785 
1786  float navscreen_width_delta = (screenskipby4[1]-screenskipby4[0]);
1787  float navscreen_height_delta = (screenskipby4[3]-screenskipby4[2]);
1788  float navscreen_small_delta = std::min( navscreen_width_delta, navscreen_height_delta );
1789 
1790  the_x = (the_x*navscreen_small_delta);
1791  the_x = the_x+center_nav_x;
1792  the_y = (the_y*navscreen_small_delta);
1793  the_y = the_y+center_nav_y;
1794 
1795  the_x_flat = (the_x_flat*navscreen_small_delta);
1796  the_x_flat = the_x_flat+center_nav_x;
1797  the_y_flat = (the_y_flat*navscreen_small_delta);
1798  the_y_flat = the_y_flat+center_nav_y;
1799  //**********************************
1800  if ( (system_not_galaxy ? system_view : galaxy_view) == VIEW_ORTHO ) {
1801  the_x = the_x_flat;
1802  the_y = the_y_flat;
1803  pos = pos_flat;
1804  }
1805 }
1806 
1807 void NavigationSystem::TranslateAndDisplay( QVector &pos,
1808  QVector &pos_flat,
1809  float center_nav_x,
1810  float center_nav_y,
1811  float themaxvalue,
1812  float &zscale,
1813  float &zdistance,
1814  float &the_x,
1815  float &the_y,
1816  float &system_item_scale_temp,
1817  bool system_not_galaxy )
1818 {
1819  float the_x_flat;
1820  float the_y_flat;
1821  if ( (system_not_galaxy ? system_view : galaxy_view) == VIEW_ORTHO ) {
1822  TranslateCoordinates( pos, pos_flat, center_nav_x, center_nav_y, themaxvalue, zscale, zdistance,
1823  the_x, the_y, the_x_flat, the_y_flat, system_item_scale_temp, system_not_galaxy );
1824  return;
1825  } else {
1826  TranslateCoordinates( pos, pos_flat, center_nav_x, center_nav_y, themaxvalue, zscale, zdistance,
1827  the_x, the_y, the_x_flat, the_y_flat, system_item_scale_temp, system_not_galaxy );
1828  }
1829  DisplayOrientationLines( the_x, the_y, the_x_flat, the_y_flat, system_not_galaxy );
1830 }
1831 
1832 void NavigationSystem::DisplayOrientationLines( float the_x,
1833  float the_y,
1834  float the_x_flat,
1835  float the_y_flat,
1836  bool system_not_galaxy )
1837 {
1838  if ( (system_not_galaxy ? system_view : galaxy_view) == VIEW_ORTHO )
1839  return;
1840  //Draw orientation lines
1841  //**********************************
1842  GFXDisable( TEXTURE0 );
1843  GFXDisable( LIGHTING );
1845 
1846  GFXBegin( GFXLINE );
1847 
1848  GFXColorf( GFXColor( 0.5, 0.5, 0.5, .15 ) );
1849 
1850  bool display_flat_circle = true;
1851  if ( (the_y_flat > screenskipby4[3])
1852  || (the_y_flat < screenskipby4[2])
1853  || (the_x_flat > screenskipby4[1])
1854  || (the_x_flat < screenskipby4[0]) ) {
1855  GFXColorf( GFXColor( 0, 1, 1, .05 ) );
1856  display_flat_circle = false;
1857  }
1858  bool display_flat = true;
1859  if ( (the_x > screenskipby4[1])
1860  || (the_x < screenskipby4[0])
1861  || (the_y > screenskipby4[3])
1862  || (the_y < screenskipby4[2]) ) {
1863  GFXColorf( GFXColor( 1, 1, 0, .05 ) );
1864  display_flat = false;
1865  }
1866  if (display_flat) {
1867  IntersectBorder( the_x_flat, the_y_flat, the_x, the_y );
1868  GFXVertex3f( the_x_flat, the_y_flat, 0 );
1869  GFXVertex3f( the_x, the_y, 0 );
1870  if (display_flat_circle)
1871  DrawCircle( the_x_flat, the_y_flat, (.005*system_item_scale), GFXColor( 1, 1, 1, .2 ) );
1872  }
1873  GFXEnd();
1874  GFXEnable( TEXTURE0 );
1875  //**********************************
1876 }
1877 
1878 void Beautify( string systemfile, string &sector, string &system )
1879 {
1880  string::size_type slash = systemfile.find( "/" );
1881  if (slash == string::npos) {
1882  sector = "";
1883  system = systemfile;
1884  } else {
1885  sector = systemfile.substr( 0, slash );
1886  system = systemfile.substr( slash+1 );
1887  }
1888  if ( sector.size() )
1889  sector[0] = toupper( sector[0] );
1890  if ( system.size() )
1891  system[0] = toupper( system[0] );
1892 }
1893