Pioneer
SystemView.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _SYSTEMVIEW_H
5 #define _SYSTEMVIEW_H
6 
7 #include "Color.h"
8 #include "DeleteEmitter.h"
9 #include "Frame.h"
10 #include "Input.h"
11 #include "TransferPlanner.h"
12 #include "enum_table.h"
13 #include "graphics/Drawables.h"
14 #include "matrix4x4.h"
15 #include "pigui/PiGuiView.h"
16 #include "vector3.h"
17 
18 class StarSystem;
19 class SystemBody;
20 class Orbit;
21 class Ship;
22 class Game;
23 class Body;
24 
28  OFF
29 };
30 
31 enum class GridDrawing {
32  GRID,
34  OFF
35 };
36 
40  LAG_OFF
41 };
42 
43 struct Projectable {
44  enum types { // <enum name=ProjectableTypes scope='Projectable' public>
45  NONE = 0, // empty projectable, don't try to get members
46  OBJECT = 1, // clickable space object, may be without phys.body (other starsystem)
47  L4 = 2,
48  L5 = 3,
49  APOAPSIS = 4,
50  PERIAPSIS = 5
51  } type;
52  enum bases { // <enum name=ProjectableBases scope='Projectable' public>
53  SYSTEMBODY = 0, // ref class SystemBody, may not have a physical body
54  BODY = 1, // generic body
55  SHIP = 2,
56  PLAYER = 3, // player's ship
57  PLANNER = 4 // player's ship planned by transfer planner, refers to player's object
58  } base;
59  union {
60  const Body *body;
61  const SystemBody *sbody;
62  } ref;
63  vector3d screenpos; // x,y - screen coordinate, z - in NDC
65 
66  Projectable(const types t, const bases b, const Body *obj) :
67  type(t), base(b)
68  {
69  ref.body = obj;
70  }
71  Projectable(const types t, const bases b, const SystemBody *obj) :
72  type(t), base(b)
73  {
74  ref.sbody = obj;
75  }
77  type(NONE) {}
78 };
79 
80 class SystemView : public PiGuiView, public DeleteEmitter {
81 public:
82  SystemView(Game *game);
83  ~SystemView() override;
84  void Update() override;
85  void Draw3D() override;
86  void OnSwitchFrom() override;
87 
91  TransferPlanner *GetTransferPlanner() const { return m_planner; }
92  double GetOrbitPlannerStartTime() const { return m_planner->GetStartTime(); }
93  double GetOrbitPlannerTime() const { return m_time; }
94  void AccelerateTime(float step);
95  void SetRealTime();
96  std::vector<Projectable> GetProjected() const { return m_projected; }
97  void SetVisibility(std::string param);
98  void SetZoomMode(bool enable);
99  void SetRotateMode(bool enable);
100  double ProjectedSize(double size, vector3d pos);
101 
102  // all used colors. defined in system-view-ui.lua
103  enum ColorIndex { // <enum name=SystemViewColorIndex scope='SystemView' public>
104  GRID = 0,
105  GRID_LEG = 1,
111  SHIP_ORBIT = 7
112  };
113 
115  void SetColor(ColorIndex color_index, Color *color_value) { svColor[color_index] = *color_value; }
116 
117 private:
118  struct InputBindings : public Input::InputFrame {
119  using InputFrame::InputFrame;
120  void RegisterBindings() override;
121 
122  Axis *mapViewPitch;
123  Axis *mapViewYaw;
124  Axis *mapViewZoom;
125  } m_input;
126 
127  bool m_rotateWithMouseButton = false;
128  bool m_rotateView = false;
129  bool m_zoomView = false;
130  std::vector<Projectable> m_projected;
131  static const double PICK_OBJECT_RECT_SIZE;
132  static const Uint16 N_VERTICES_MAX;
133  const float CAMERA_FOV = 50.f;
134  const float CAMERA_FOV_RADIANS = CAMERA_FOV / 57.295779f;
135  matrix4x4f m_cameraSpace;
136  template <typename RefType>
137  void PutOrbit(Projectable::bases base, RefType *ref, const Orbit *orb, const vector3d &offset, const Color &color, const double planetRadius = 0.0, const bool showLagrange = false);
138  void PutBody(const SystemBody *b, const vector3d &offset, const matrix4x4f &trans);
139  void GetTransformTo(const SystemBody *b, vector3d &pos);
140  void GetTransformTo(Projectable &p, vector3d &pos);
141  void ResetViewpoint();
142  void MouseWheel(bool up);
143  void RefreshShips(void);
144  void DrawShips(const double t, const vector3d &offset);
145  void DrawGrid();
146 
147  // Project a position in the current renderer project to screenspace and add it to the list of projected objects
148  template <typename T>
149  void AddProjected(Projectable::types type, Projectable::bases base, T *ref, const vector3d &worldpos);
150  void CalculateShipPositionAtTime(const Ship *s, Orbit o, double t, vector3d &pos);
151  void CalculateFramePositionAtTime(FrameId frameId, double t, vector3d &pos);
152  double GetOrbitTime(double t, const SystemBody *b);
153  double GetOrbitTime(double t, const Body *b);
154 
155  Game *m_game;
156  RefCountedPtr<StarSystem> m_system;
157  Projectable m_selectedObject;
158  std::vector<SystemBody *> m_displayed_sbody;
159  bool m_unexplored;
160  ShowLagrange m_showL4L5;
161  TransferPlanner *m_planner;
162  std::list<std::pair<Ship *, Orbit>> m_contacts;
163  ShipDrawing m_shipDrawing;
164  GridDrawing m_gridDrawing;
165  int m_grid_lines;
166  float m_rot_x, m_rot_y;
167  float m_rot_x_to, m_rot_y_to;
168  float m_zoom, m_zoomTo;
169  int m_animateTransition;
170  vector3d m_trans;
171  vector3d m_transTo;
172  double m_time;
173  bool m_realtime;
174  double m_timeStep;
175  sigc::connection m_onMouseWheelCon;
176 
177  std::unique_ptr<Graphics::Drawables::Disk> m_bodyIcon;
178  Graphics::RenderState *m_lineState;
180  Graphics::Drawables::Lines m_selectBox;
181 
182  std::unique_ptr<vector3f[]> m_orbitVts;
183  std::unique_ptr<Color[]> m_orbitColors;
184 
185  std::unique_ptr<Graphics::VertexArray> m_lineVerts;
187 };
188 
189 #endif /* _SYSTEMVIEW_H */
ShowLagrange
Definition: SystemView.h:37
@ LAG_ICONTEXT
Definition: SystemView.h:39
@ LAG_ICON
Definition: SystemView.h:38
@ LAG_OFF
Definition: SystemView.h:40
ShipDrawing
Definition: SystemView.h:25
@ ORBITS
Definition: SystemView.h:27
@ BOXES
Definition: SystemView.h:26
@ OFF
Definition: SystemView.h:28
GridDrawing
Definition: SystemView.h:31
Definition: Body.h:54
Definition: DeleteEmitter.h:16
Definition: Game.h:39
Definition: Drawables.h:79
Definition: RenderState.h:25
Definition: Orbit.h:11
Definition: PiGuiView.h:11
Definition: Ship.h:64
Definition: StarSystem.h:27
Definition: SystemBody.h:19
Definition: SystemView.h:80
Projectable * GetSelectedObject()
Definition: SystemView.cpp:652
void Draw3D() override
Definition: SystemView.cpp:325
Color svColor[8]
Definition: SystemView.h:114
~SystemView() override
Definition: SystemView.cpp:85
void SetSelectedObject(Projectable::types type, Projectable::bases base, SystemBody *sb)
Definition: SystemView.cpp:657
double ProjectedSize(double size, vector3d pos)
Definition: SystemView.cpp:681
void SetRotateMode(bool enable)
Definition: SystemView.cpp:643
TransferPlanner * GetTransferPlanner() const
Definition: SystemView.h:91
void OnSwitchFrom() override
Definition: SystemView.cpp:691
double GetOrbitPlannerTime() const
Definition: SystemView.h:93
double GetOrbitPlannerStartTime() const
Definition: SystemView.h:92
void Update() override
Definition: SystemView.cpp:462
void AccelerateTime(float step)
Definition: SystemView.cpp:91
void SetRealTime()
Definition: SystemView.cpp:97
std::vector< Projectable > GetProjected() const
Definition: SystemView.h:96
void SetVisibility(std::string param)
Definition: SystemView.cpp:605
SystemView(Game *game)
Definition: SystemView.cpp:50
void SetZoomMode(bool enable)
Definition: SystemView.cpp:634
void SetColor(ColorIndex color_index, Color *color_value)
Definition: SystemView.h:115
ColorIndex
Definition: SystemView.h:103
@ GRID_LEG
Definition: SystemView.h:105
@ GRID
Definition: SystemView.h:104
@ SELECTED_SHIP_ORBIT
Definition: SystemView.h:110
@ SYSTEMBODY_ORBIT
Definition: SystemView.h:107
@ PLAYER_ORBIT
Definition: SystemView.h:108
@ PLANNER_ORBIT
Definition: SystemView.h:109
@ SYSTEMBODY
Definition: SystemView.h:106
@ SHIP_ORBIT
Definition: SystemView.h:111
Definition: TransferPlanner.h:8
double GetStartTime() const
Definition: TransferPlanner.cpp:71
Definition: InputBindings.h:14
Definition: Color.h:66
Definition: FrameId.h:9
Definition: Input.h:45
Definition: SystemView.h:43
enum Projectable::bases base
Projectable(const types t, const bases b, const Body *obj)
Definition: SystemView.h:66
vector3d screenpos
Definition: SystemView.h:63
const SystemBody * sbody
Definition: SystemView.h:61
union Projectable::@12 ref
const Body * body
Definition: SystemView.h:60
bases
Definition: SystemView.h:52
@ BODY
Definition: SystemView.h:54
@ SHIP
Definition: SystemView.h:55
@ PLAYER
Definition: SystemView.h:56
@ PLANNER
Definition: SystemView.h:57
@ SYSTEMBODY
Definition: SystemView.h:53
Projectable(const types t, const bases b, const SystemBody *obj)
Definition: SystemView.h:71
Projectable()
Definition: SystemView.h:76
types
Definition: SystemView.h:44
@ L5
Definition: SystemView.h:48
@ L4
Definition: SystemView.h:47
@ PERIAPSIS
Definition: SystemView.h:50
@ OBJECT
Definition: SystemView.h:46
@ APOAPSIS
Definition: SystemView.h:49
@ NONE
Definition: SystemView.h:45
vector3d worldpos
Definition: SystemView.h:64
enum Projectable::types type