Added grid and legs display and a reset orient to SystemView

master
mike-f1 2019-08-21 18:34:40 +02:00
parent 2abca7730b
commit e1c389c12d
8 changed files with 130 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -479,6 +479,10 @@
"description": "like wheat or barley",
"message": "Grain"
},
"GRID_DISPLAY_MODE_TOGGLE": {
"description": "Switch show no grid",
"message": "Switch between grid display modes."
},
"HAND_WEAPONS": {
"description": "",
"message": "Hand weapons"

View File

@ -441,3 +441,4 @@ DECLARE_STRING(LONGITUDE)
DECLARE_STRING(NOW)
DECLARE_STRING(TOGGLE_RADAR_VIEW)
DECLARE_STRING(TOGGLE_EQUIPMENT_VIEW)
DECLARE_STRING(GRID_DISPLAY_MODE_TOGGLE)

View File

@ -2,6 +2,7 @@
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "SystemView.h"
#include "AnimationCurves.h"
#include "Frame.h"
#include "Game.h"
@ -210,7 +211,10 @@ void TransferPlanner::SetPosition(const vector3d &position) { m_position = posit
SystemView::SystemView(Game *game) :
UIView(),
m_game(game)
m_game(game),
m_gridDrawing(GridDrawing::OFF),
m_shipDrawing(OFF),
m_showL4L5(LAG_OFF)
{
SetTransparency(true);
@ -264,6 +268,18 @@ SystemView::SystemView(Game *game) :
Add(m_toggleL4L5Button, 628, 5);
m_toggleL4L5Button->SetActiveState(LAG_OFF);
m_toggleGridButton = new Gui::ImageButton("icons/toggle_grid_display.png");
m_toggleGridButton->SetToolTip(Lang::GRID_DISPLAY_MODE_TOGGLE);
m_toggleGridButton->SetRenderDimensions(30, 22);
m_toggleGridButton->onClick.connect(sigc::mem_fun(this, &SystemView::OnToggleGridButtonClick));
Add(m_toggleGridButton, 596, 5);
m_ResetOrientButton = new Gui::ImageButton("icons/reset_orient_and_zoom.png");
m_ResetOrientButton->SetToolTip(Lang::RESET_ORIENTATION_AND_ZOOM);
m_ResetOrientButton->SetRenderDimensions(30, 22);
m_ResetOrientButton->onClick.connect(sigc::mem_fun(this, &SystemView::ResetViewpoint));
Add(m_ResetOrientButton, 564, 5);
// orbital transfer planner UI
int dx = 670;
int dy = 40;
@ -411,8 +427,6 @@ SystemView::SystemView(Game *game) :
ResetViewpoint();
RefreshShips();
m_shipDrawing = OFF;
m_showL4L5 = LAG_OFF;
m_planner = Pi::planner;
m_orbitVts.reset(new vector3f[N_VERTICES_MAX]);
@ -453,6 +467,22 @@ void SystemView::OnToggleShipsButtonClick(void)
}
}
void SystemView::OnToggleGridButtonClick()
{
//printf("OnToggleGridButtonClick %i\n", static_cast<std::underlying_type<GridDrawing>::type>(m_gridDrawing));
switch (m_gridDrawing) {
case GridDrawing::OFF:
m_gridDrawing = GridDrawing::GRID;
break;
case GridDrawing::GRID:
m_gridDrawing = GridDrawing::GRID_AND_LEGS;
break;
case GridDrawing::GRID_AND_LEGS:
m_gridDrawing = GridDrawing::OFF;
break;
}
}
void SystemView::OnToggleL4L5ButtonClick(Gui::MultiStateImageButton *b)
{
switch (m_showL4L5) {
@ -878,6 +908,10 @@ void SystemView::Draw3D()
DrawShips(m_time - m_game->GetTime(), pos);
}
if (m_gridDrawing != GridDrawing::OFF) {
DrawGrid();
}
UIView::Draw3D();
}
@ -992,7 +1026,6 @@ void SystemView::DrawShips(const double t, const vector3d &offset)
if ((*s).first->GetFlightState() != Ship::FlightState::FLYING) {
Frame *frame = Pi::game->GetSpace()->GetRootFrame();
pos += (*s).first->GetPositionRelTo(frame) * double(m_zoom);
;
} else {
Frame *frame = (*s).first->GetFrame();
vector3d bpos = vector3d(0., 0., 0.);
@ -1007,3 +1040,50 @@ void SystemView::DrawShips(const double t, const vector3d &offset)
PutOrbit(&(*s).second, offset, isNavTarget ? Color::GREEN : Color::BLUE, 0);
}
}
void SystemView::PrepareGrid()
{
// calculate lines for this system:
double diameter = std::floor(m_system->GetRootBody()->GetMaxChildOrbitalDistance() * 1.2 / AU);
m_grid_lines = int(diameter) + 1;
m_displayed_sbody.clear();
if (m_gridDrawing == GridDrawing::GRID_AND_LEGS) {
m_displayed_sbody = m_system->GetRootBody()->CollectAllChildren();
}
}
void SystemView::DrawGrid()
{
PrepareGrid();
m_lineVerts.reset(new Graphics::VertexArray(Graphics::ATTRIB_POSITION, m_grid_lines * 4 + m_displayed_sbody.size() * 2));
float zoom = m_zoom * float(AU);
vector3d pos(0.);
if (m_selectedObject) GetTransformTo(m_selectedObject, pos);
for (int i = -m_grid_lines; i < m_grid_lines + 1; i++) {
float z = float(i) * zoom;
m_lineVerts->Add(vector3f(-m_grid_lines * zoom, 0.0f, z) + vector3f(pos), Color::GRAY);
m_lineVerts->Add(vector3f(+m_grid_lines * zoom, 0.0f, z) + vector3f(pos), Color::GRAY);
}
for (int i = -m_grid_lines; i < m_grid_lines + 1; i++) {
float x = float(i) * zoom;
m_lineVerts->Add(vector3f(x, 0.0f, -m_grid_lines * zoom) + vector3f(pos), Color::GRAY);
m_lineVerts->Add(vector3f(x, 0.0f, +m_grid_lines * zoom) + vector3f(pos), Color::GRAY);
}
for (SystemBody *sbody : m_displayed_sbody) {
vector3d offset(0.);
GetTransformTo(sbody, offset);
m_lineVerts->Add(vector3f(pos - offset), Color::GRAY * 0.5);
offset.y = 0.0;
m_lineVerts->Add(vector3f(pos - offset), Color::GRAY * 0.5);
}
m_lines.SetData(m_lineVerts->GetNumVerts(), &m_lineVerts->position[0], &m_lineVerts->diffuse[0]);
m_lines.Draw(Pi::renderer, m_lineState);
}

View File

@ -28,6 +28,12 @@ enum ShipDrawing {
OFF
};
enum class GridDrawing {
GRID,
GRID_AND_LEGS,
OFF
};
enum ShowLagrange {
LAG_ICON,
LAG_ICONTEXT,
@ -86,23 +92,29 @@ private:
void OnIncreaseFactorButtonClick(void), OnResetFactorButtonClick(void), OnDecreaseFactorButtonClick(void);
void OnIncreaseStartTimeButtonClick(void), OnResetStartTimeButtonClick(void), OnDecreaseStartTimeButtonClick(void);
void OnToggleShipsButtonClick(void);
void OnToggleGridButtonClick(void);
void OnToggleL4L5ButtonClick(Gui::MultiStateImageButton *);
void ResetViewpoint();
void MouseWheel(bool up);
void RefreshShips(void);
void DrawShips(const double t, const vector3d &offset);
void PrepareGrid();
void DrawGrid();
void LabelShip(Ship *s, const vector3d &offset);
void OnClickShip(Ship *s);
Game *m_game;
RefCountedPtr<StarSystem> m_system;
const SystemBody *m_selectedObject;
std::vector<SystemBody *> m_displayed_sbody;
bool m_unexplored;
ShowLagrange m_showL4L5;
TransferPlanner *m_planner;
std::list<std::pair<Ship *, Orbit>> m_contacts;
Gui::LabelSet *m_shipLabels;
ShipDrawing m_shipDrawing;
GridDrawing m_gridDrawing;
int m_grid_lines;
float m_rot_x, m_rot_z;
float m_rot_x_to, m_rot_z_to;
float m_zoom, m_zoomTo;
@ -112,6 +124,8 @@ private:
Gui::ImageButton *m_zoomInButton;
Gui::ImageButton *m_zoomOutButton;
Gui::ImageButton *m_toggleShipsButton;
Gui::ImageButton *m_toggleGridButton;
Gui::ImageButton *m_ResetOrientButton;
Gui::MultiStateImageButton *m_toggleL4L5Button;
Gui::ImageButton *m_plannerIncreaseStartTimeButton, *m_plannerResetStartTimeButton, *m_plannerDecreaseStartTimeButton;
Gui::ImageButton *m_plannerIncreaseFactorButton, *m_plannerResetFactorButton, *m_plannerDecreaseFactorButton;
@ -140,6 +154,10 @@ private:
std::unique_ptr<vector3f[]> m_orbitVts;
std::unique_ptr<Color[]> m_orbitColors;
std::unique_ptr<Graphics::VertexArray> m_lineVerts;
Graphics::Drawables::Lines m_lines;
};
#endif /* _SYSTEMVIEW_H */

View File

@ -467,6 +467,27 @@ bool SystemBody::IsPlanet() const
}
}
void CollectSystemBodies(SystemBody *sb, std::vector<SystemBody*> &sb_vector)
{
for (SystemBody *body : sb->GetChildren()) {
sb_vector.push_back(body);
if (sb->HasChildren()) CollectSystemBodies(body, sb_vector);
}
}
const std::vector<SystemBody *> SystemBody::CollectAllChildren()
{
std::vector<SystemBody*> sb_vector;
// At least avoid initial reallocations
sb_vector.reserve(m_children.size());
for (SystemBody *sbody : m_children) {
sb_vector.push_back(sbody);
if (HasChildren()) CollectSystemBodies(this, sb_vector);
}
return sb_vector;
}
double SystemBody::GetMaxChildOrbitalDistance() const
{
PROFILE_SCOPED()

View File

@ -89,6 +89,8 @@ public:
IterationProxy<std::vector<SystemBody *>> GetChildren() { return MakeIterationProxy(m_children); }
const IterationProxy<const std::vector<SystemBody *>> GetChildren() const { return MakeIterationProxy(m_children); }
const std::vector<SystemBody *> CollectAllChildren();
inline const std::string &GetName() const { return m_name; }
std::string GetAstroDescription() const;
const char *GetIcon() const;