2019-01-02 01:47:08 -08:00
|
|
|
// Copyright © 2008-2019 Pioneer Developers. See AUTHORS.txt for details
|
2012-09-15 17:59:15 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
2012-09-12 04:38:30 -07:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
#include "SystemView.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "AnimationCurves.h"
|
|
|
|
#include "FloatComparison.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "Lang.h"
|
|
|
|
#include "MathUtil.h"
|
2008-06-24 03:17:31 -07:00
|
|
|
#include "Pi.h"
|
2019-01-13 11:21:00 -08:00
|
|
|
#include "LuaObject.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "Player.h"
|
2008-06-24 03:17:31 -07:00
|
|
|
#include "SectorView.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "Space.h"
|
2019-01-13 09:15:56 -08:00
|
|
|
#include "Frame.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "StringF.h"
|
2014-04-27 05:12:14 -07:00
|
|
|
#include "galaxy/Galaxy.h"
|
2012-04-04 18:53:58 -07:00
|
|
|
#include "galaxy/StarSystem.h"
|
2012-02-21 02:04:06 -08:00
|
|
|
#include "graphics/Material.h"
|
|
|
|
#include "graphics/Renderer.h"
|
2014-08-18 05:53:10 -07:00
|
|
|
#include "graphics/TextureBuilder.h"
|
2015-07-19 05:43:11 -07:00
|
|
|
#include <iomanip>
|
2019-01-02 08:59:07 -08:00
|
|
|
#include <sstream>
|
2012-02-21 02:04:06 -08:00
|
|
|
|
|
|
|
using namespace Graphics;
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2011-10-18 13:19:29 -07:00
|
|
|
const double SystemView::PICK_OBJECT_RECT_SIZE = 12.0;
|
2015-09-28 14:08:48 -07:00
|
|
|
const Uint16 SystemView::N_VERTICES_MAX = 100;
|
2019-01-02 08:59:07 -08:00
|
|
|
static const float MIN_ZOOM = 1e-30f; // Just to avoid having 0
|
2012-04-10 09:06:48 -07:00
|
|
|
static const float MAX_ZOOM = 1e30f;
|
|
|
|
static const float ZOOM_IN_SPEED = 2;
|
2019-01-02 08:59:07 -08:00
|
|
|
static const float ZOOM_OUT_SPEED = 1.f / ZOOM_IN_SPEED;
|
|
|
|
static const float WHEEL_SENSITIVITY = .1f; // Should be a variable in user settings.
|
2015-11-17 12:57:10 -08:00
|
|
|
static const double DEFAULT_VIEW_DISTANCE = 10.0;
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2015-07-18 15:24:19 -07:00
|
|
|
TransferPlanner::TransferPlanner() :
|
2019-01-02 08:59:07 -08:00
|
|
|
m_position(0., 0., 0.),
|
|
|
|
m_velocity(0., 0., 0.)
|
2015-07-18 15:24:19 -07:00
|
|
|
{
|
2014-07-23 10:47:47 -07:00
|
|
|
m_dvPrograde = 0.0;
|
|
|
|
m_dvNormal = 0.0;
|
|
|
|
m_dvRadial = 0.0;
|
2015-07-19 05:43:11 -07:00
|
|
|
m_startTime = 0.0;
|
2014-07-24 09:54:03 -07:00
|
|
|
m_factor = 1;
|
2014-07-23 10:47:47 -07:00
|
|
|
}
|
|
|
|
|
2015-07-19 09:57:33 -07:00
|
|
|
vector3d TransferPlanner::GetVel() const { return m_velocity + GetOffsetVel(); }
|
2015-07-18 15:24:19 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
vector3d TransferPlanner::GetOffsetVel() const
|
|
|
|
{
|
|
|
|
if (m_position.ExactlyEqual(vector3d(0., 0., 0.)))
|
2015-07-18 15:24:19 -07:00
|
|
|
return vector3d(0., 0., 0.);
|
2014-07-24 23:37:48 -07:00
|
|
|
|
2015-07-19 09:57:33 -07:00
|
|
|
const vector3d pNormal = m_position.Cross(m_velocity);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2015-07-19 09:57:33 -07:00
|
|
|
return m_dvPrograde * m_velocity.Normalized() +
|
2019-01-02 08:59:07 -08:00
|
|
|
m_dvNormal * pNormal.Normalized() +
|
|
|
|
m_dvRadial * m_position.Normalized();
|
2014-07-23 10:47:47 -07:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::AddStartTime(double timeStep)
|
|
|
|
{
|
|
|
|
if (std::fabs(m_startTime) < 1.)
|
2017-03-05 05:15:55 -08:00
|
|
|
m_startTime = Pi::game->GetTime();
|
2015-07-19 09:57:33 -07:00
|
|
|
|
2015-07-27 00:19:48 -07:00
|
|
|
m_startTime += m_factor * timeStep;
|
|
|
|
double deltaT = m_startTime - Pi::game->GetTime();
|
2019-01-02 08:59:07 -08:00
|
|
|
if (deltaT > 0.) {
|
2015-07-27 00:19:48 -07:00
|
|
|
Frame *frame = Pi::player->GetFrame()->GetNonRotFrame();
|
|
|
|
Orbit playerOrbit = Orbit::FromBodyState(Pi::player->GetPositionRelTo(frame), Pi::player->GetVelocityRelTo(frame), frame->GetSystemBody()->GetMass());
|
|
|
|
|
|
|
|
m_position = playerOrbit.OrbitalPosAtTime(deltaT);
|
|
|
|
m_velocity = playerOrbit.OrbitalVelocityAtTime(frame->GetSystemBody()->GetMass(), deltaT);
|
2019-01-02 08:59:07 -08:00
|
|
|
} else
|
2015-07-27 00:19:48 -07:00
|
|
|
ResetStartTime();
|
2015-07-19 05:43:11 -07:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::ResetStartTime()
|
|
|
|
{
|
2015-07-19 05:43:11 -07:00
|
|
|
m_startTime = 0;
|
2015-07-27 00:19:48 -07:00
|
|
|
Frame *frame = Pi::player->GetFrame();
|
2019-01-02 08:59:07 -08:00
|
|
|
if (!frame || GetOffsetVel().ExactlyEqual(vector3d(0., 0., 0.))) {
|
2015-07-19 05:43:11 -07:00
|
|
|
m_position = vector3d(0., 0., 0.);
|
2019-01-02 08:59:07 -08:00
|
|
|
m_velocity = vector3d(0., 0., 0.);
|
|
|
|
} else {
|
2015-07-27 00:19:48 -07:00
|
|
|
frame = frame->GetNonRotFrame();
|
2015-07-19 05:43:11 -07:00
|
|
|
m_position = Pi::player->GetPositionRelTo(frame);
|
2015-07-19 09:57:33 -07:00
|
|
|
m_velocity = Pi::player->GetVelocityRelTo(frame);
|
2015-07-19 05:43:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
double TransferPlanner::GetStartTime() const
|
|
|
|
{
|
2015-07-19 05:43:11 -07:00
|
|
|
return m_startTime;
|
|
|
|
}
|
|
|
|
|
2015-07-27 00:19:48 -07:00
|
|
|
static std::string formatTime(double t)
|
|
|
|
{
|
|
|
|
std::stringstream formattedTime;
|
|
|
|
formattedTime << std::setprecision(1) << std::fixed;
|
2015-11-09 12:42:18 -08:00
|
|
|
double absT = fabs(t);
|
2019-01-02 08:59:07 -08:00
|
|
|
if (absT < 60.)
|
2015-07-27 00:19:48 -07:00
|
|
|
formattedTime << t << "s";
|
2019-01-02 08:59:07 -08:00
|
|
|
else if (absT < 3600)
|
2015-07-27 00:19:48 -07:00
|
|
|
formattedTime << t / 60. << "m";
|
2019-01-02 08:59:07 -08:00
|
|
|
else if (absT < 86400)
|
2015-07-27 00:19:48 -07:00
|
|
|
formattedTime << t / 3600. << "h";
|
2019-01-02 08:59:07 -08:00
|
|
|
else if (absT < 31536000)
|
2015-07-27 00:19:48 -07:00
|
|
|
formattedTime << t / 86400. << "d";
|
|
|
|
else
|
|
|
|
formattedTime << t / 31536000. << "y";
|
2017-03-05 05:15:55 -08:00
|
|
|
return formattedTime.str();
|
2015-07-27 00:19:48 -07:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string TransferPlanner::printDeltaTime()
|
|
|
|
{
|
2015-07-19 05:43:11 -07:00
|
|
|
std::stringstream out;
|
2015-07-27 00:19:48 -07:00
|
|
|
out << std::setw(9);
|
|
|
|
double deltaT = m_startTime - Pi::game->GetTime();
|
2019-01-02 08:59:07 -08:00
|
|
|
if (std::fabs(m_startTime) < 1.)
|
2015-12-06 09:51:40 -08:00
|
|
|
out << Lang::NOW;
|
2015-07-19 05:43:11 -07:00
|
|
|
else
|
2017-03-05 05:15:55 -08:00
|
|
|
out << formatTime(deltaT);
|
2015-07-19 05:43:11 -07:00
|
|
|
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::AddDv(BurnDirection d, double dv)
|
|
|
|
{
|
|
|
|
if (m_position.ExactlyEqual(vector3d(0., 0., 0.))) {
|
2015-07-19 05:43:11 -07:00
|
|
|
Frame *frame = Pi::player->GetFrame()->GetNonRotFrame();
|
|
|
|
m_position = Pi::player->GetPositionRelTo(frame);
|
2015-07-19 09:57:33 -07:00
|
|
|
m_velocity = Pi::player->GetVelocityRelTo(frame);
|
2015-07-27 00:19:48 -07:00
|
|
|
m_startTime = Pi::game->GetTime();
|
2015-07-18 15:24:19 -07:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:37:48 -07:00
|
|
|
switch (d) {
|
|
|
|
case PROGRADE: m_dvPrograde += m_factor * dv; break;
|
2019-01-02 08:59:07 -08:00
|
|
|
case NORMAL: m_dvNormal += m_factor * dv; break;
|
|
|
|
case RADIAL: m_dvRadial += m_factor * dv; break;
|
2014-07-24 23:37:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::ResetDv(BurnDirection d)
|
|
|
|
{
|
2014-07-24 23:37:48 -07:00
|
|
|
switch (d) {
|
|
|
|
case PROGRADE: m_dvPrograde = 0; break;
|
2019-01-02 08:59:07 -08:00
|
|
|
case NORMAL: m_dvNormal = 0; break;
|
|
|
|
case RADIAL: m_dvRadial = 0; break;
|
2014-07-24 23:37:48 -07:00
|
|
|
}
|
2015-07-19 05:43:11 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
if (std::fabs(m_startTime) < 1. &&
|
|
|
|
GetOffsetVel().ExactlyEqual(vector3d(0., 0., 0.))) {
|
2015-07-19 05:43:11 -07:00
|
|
|
m_position = vector3d(0., 0., 0.);
|
2015-07-19 09:57:33 -07:00
|
|
|
m_velocity = vector3d(0., 0., 0.);
|
2015-07-27 00:19:48 -07:00
|
|
|
m_startTime = 0.;
|
2015-07-19 05:43:11 -07:00
|
|
|
}
|
2014-07-24 23:37:48 -07:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::ResetDv()
|
|
|
|
{
|
|
|
|
m_dvPrograde = 0;
|
|
|
|
m_dvNormal = 0;
|
|
|
|
m_dvRadial = 0;
|
2015-07-27 00:19:48 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
if (std::fabs(m_startTime) < 1.) {
|
2015-07-27 00:19:48 -07:00
|
|
|
m_position = vector3d(0., 0., 0.);
|
|
|
|
m_velocity = vector3d(0., 0., 0.);
|
|
|
|
m_startTime = 0.;
|
2019-01-02 08:59:07 -08:00
|
|
|
}
|
2015-07-27 00:19:48 -07:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string TransferPlanner::printDv(BurnDirection d)
|
|
|
|
{
|
2014-07-30 00:34:36 -07:00
|
|
|
double dv = 0;
|
2014-07-24 23:37:48 -07:00
|
|
|
char buf[10];
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
switch (d) {
|
2014-07-24 23:37:48 -07:00
|
|
|
case PROGRADE: dv = m_dvPrograde; break;
|
2019-01-02 08:59:07 -08:00
|
|
|
case NORMAL: dv = m_dvNormal; break;
|
|
|
|
case RADIAL: dv = m_dvRadial; break;
|
2014-07-24 23:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%6.0fm/s", dv);
|
|
|
|
return std::string(buf);
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::IncreaseFactor(void)
|
|
|
|
{
|
|
|
|
if (m_factor > 1000) return;
|
2014-07-24 09:54:03 -07:00
|
|
|
m_factor *= m_factorFactor;
|
|
|
|
}
|
|
|
|
void TransferPlanner::ResetFactor(void) { m_factor = 1; }
|
2014-07-24 23:37:48 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::DecreaseFactor(void)
|
|
|
|
{
|
|
|
|
if (m_factor < 0.0002) return;
|
2014-07-24 09:54:03 -07:00
|
|
|
m_factor /= m_factorFactor;
|
|
|
|
}
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string TransferPlanner::printFactor(void)
|
|
|
|
{
|
2017-06-21 23:21:07 -07:00
|
|
|
char buf[16];
|
2015-07-27 00:19:48 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%8gx", 10 * m_factor);
|
2014-07-24 23:37:48 -07:00
|
|
|
return std::string(buf);
|
2014-07-23 10:47:47 -07:00
|
|
|
}
|
|
|
|
|
2015-07-18 15:24:19 -07:00
|
|
|
vector3d TransferPlanner::GetPosition() const { return m_position; }
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void TransferPlanner::SetPosition(const vector3d &position) { m_position = position; }
|
2015-07-18 15:24:19 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
SystemView::SystemView(Game *game) :
|
|
|
|
UIView(),
|
|
|
|
m_game(game)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
|
|
|
SetTransparency(true);
|
|
|
|
|
2014-01-30 18:22:52 -08:00
|
|
|
Graphics::RenderStateDesc rsd;
|
|
|
|
m_lineState = Pi::renderer->CreateRenderState(rsd); //m_renderer not set yet
|
|
|
|
|
2013-02-22 22:47:08 -08:00
|
|
|
m_realtime = true;
|
2014-01-18 10:51:22 -08:00
|
|
|
m_unexplored = true;
|
2013-02-22 22:47:08 -08:00
|
|
|
|
2011-07-21 00:07:09 -07:00
|
|
|
Gui::Screen::PushFont("OverlayFont");
|
2011-01-19 21:07:28 -08:00
|
|
|
m_objectLabels = new Gui::LabelSet();
|
|
|
|
Add(m_objectLabels, 0, 0);
|
2014-08-07 03:04:46 -07:00
|
|
|
m_shipLabels = new Gui::LabelSet();
|
2019-01-02 08:59:07 -08:00
|
|
|
m_shipLabels->SetLabelColor(Color(255, 155, 0, 200));
|
2014-08-07 03:04:46 -07:00
|
|
|
Add(m_shipLabels, 0, 0);
|
2011-07-21 00:07:09 -07:00
|
|
|
Gui::Screen::PopFont();
|
2011-01-19 21:07:28 -08:00
|
|
|
|
2013-12-09 12:37:02 -08:00
|
|
|
m_timePoint = (new Gui::Label(""))->Color(178, 178, 178);
|
2019-01-02 08:59:07 -08:00
|
|
|
Add(m_timePoint, 2, Gui::Screen::GetHeight() - Gui::Screen::GetFontHeight() - 66);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2013-12-09 12:37:02 -08:00
|
|
|
m_infoLabel = (new Gui::Label(""))->Color(178, 178, 178);
|
2009-10-18 09:12:51 -07:00
|
|
|
Add(m_infoLabel, 2, 0);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2013-12-09 12:37:02 -08:00
|
|
|
m_infoText = (new Gui::Label(""))->Color(178, 178, 178);
|
2009-10-18 09:12:51 -07:00
|
|
|
Add(m_infoText, 200, 0);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
m_zoomOutButton = new Gui::ImageButton("icons/zoom_out.png");
|
2011-07-27 03:46:56 -07:00
|
|
|
m_zoomOutButton->SetToolTip(Lang::ZOOM_OUT);
|
2012-09-02 08:30:57 -07:00
|
|
|
m_zoomOutButton->SetRenderDimensions(30, 22);
|
2014-08-04 23:02:50 -07:00
|
|
|
Add(m_zoomOutButton, 700, 5);
|
|
|
|
|
|
|
|
m_zoomInButton = new Gui::ImageButton("icons/zoom_in.png");
|
|
|
|
m_zoomInButton->SetToolTip(Lang::ZOOM_IN);
|
|
|
|
m_zoomInButton->SetRenderDimensions(30, 22);
|
|
|
|
Add(m_zoomInButton, 732, 5);
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2014-08-07 00:36:04 -07:00
|
|
|
m_toggleShipsButton = new Gui::ImageButton("icons/toggle_ships_display.png");
|
2014-08-07 12:53:11 -07:00
|
|
|
m_toggleShipsButton->SetToolTip(Lang::SHIPS_DISPLAY_MODE_TOGGLE);
|
2014-08-07 00:36:04 -07:00
|
|
|
m_toggleShipsButton->SetRenderDimensions(30, 22);
|
|
|
|
m_toggleShipsButton->onClick.connect(sigc::mem_fun(this, &SystemView::OnToggleShipsButtonClick));
|
|
|
|
Add(m_toggleShipsButton, 660, 5);
|
2015-11-17 12:57:10 -08:00
|
|
|
|
|
|
|
// Add the 3 Lagrange button stations
|
|
|
|
m_toggleL4L5Button = new Gui::MultiStateImageButton();
|
2019-01-02 08:59:07 -08:00
|
|
|
m_toggleL4L5Button->AddState(LAG_ICON, "icons/toggle_lag_icon.png");
|
|
|
|
m_toggleL4L5Button->AddState(LAG_ICONTEXT, "icons/toggle_lag_icon_text.png");
|
|
|
|
m_toggleL4L5Button->AddState(LAG_OFF, "icons/toggle_lag_off.png");
|
2015-11-17 12:57:10 -08:00
|
|
|
m_toggleL4L5Button->SetToolTip(Lang::L4L5_DISPLAY_MODE_TOGGLE);
|
|
|
|
m_toggleL4L5Button->SetRenderDimensions(30, 22);
|
|
|
|
m_toggleL4L5Button->onClick.connect(sigc::mem_fun(this, &SystemView::OnToggleL4L5ButtonClick));
|
|
|
|
Add(m_toggleL4L5Button, 628, 5);
|
|
|
|
m_toggleL4L5Button->SetActiveState(LAG_OFF);
|
|
|
|
|
2014-07-24 09:54:03 -07:00
|
|
|
// orbital transfer planner UI
|
2014-08-04 23:02:50 -07:00
|
|
|
int dx = 670;
|
2014-07-23 10:47:47 -07:00
|
|
|
int dy = 40;
|
|
|
|
|
2014-07-24 09:54:03 -07:00
|
|
|
m_plannerIncreaseFactorButton = new Gui::ImageButton("icons/orbit_increase_big.png");
|
|
|
|
m_plannerIncreaseFactorButton->SetRenderDimensions(18, 18);
|
|
|
|
m_plannerIncreaseFactorButton->onClick.connect(sigc::mem_fun(this, &SystemView::OnIncreaseFactorButtonClick));
|
|
|
|
Add(m_plannerIncreaseFactorButton, dx + 40, dy);
|
|
|
|
|
|
|
|
m_plannerResetFactorButton = new Gui::ImageButton("icons/orbit_factor_big.png");
|
|
|
|
m_plannerResetFactorButton->SetRenderDimensions(18, 18);
|
|
|
|
m_plannerResetFactorButton->SetToolTip(Lang::PLANNER_RESET_FACTOR);
|
|
|
|
m_plannerResetFactorButton->onClick.connect(sigc::mem_fun(this, &SystemView::OnResetFactorButtonClick));
|
|
|
|
Add(m_plannerResetFactorButton, dx + 20, dy);
|
|
|
|
|
|
|
|
m_plannerDecreaseFactorButton = new Gui::ImageButton("icons/orbit_reduce_big.png");
|
|
|
|
m_plannerDecreaseFactorButton->SetRenderDimensions(18, 18);
|
|
|
|
m_plannerDecreaseFactorButton->onClick.connect(sigc::mem_fun(this, &SystemView::OnDecreaseFactorButtonClick));
|
|
|
|
Add(m_plannerDecreaseFactorButton, dx, dy);
|
|
|
|
|
|
|
|
m_plannerFactorText = (new Gui::Label(""))->Color(178, 178, 178);
|
|
|
|
Add(m_plannerFactorText, dx + 60 + 7, dy);
|
|
|
|
|
2015-07-19 05:43:11 -07:00
|
|
|
m_plannerIncreaseStartTimeButton = new Gui::ImageButton("icons/orbit_increase_big.png");
|
|
|
|
m_plannerIncreaseStartTimeButton->SetRenderDimensions(18, 18);
|
|
|
|
Add(m_plannerIncreaseStartTimeButton, dx + 40, dy + 20);
|
|
|
|
|
|
|
|
m_plannerResetStartTimeButton = new Gui::ImageButton("icons/orbit_start_big.png");
|
|
|
|
m_plannerResetStartTimeButton->SetRenderDimensions(18, 18);
|
|
|
|
m_plannerResetStartTimeButton->SetToolTip(Lang::PLANNER_RESET_START);
|
|
|
|
Add(m_plannerResetStartTimeButton, dx + 20, dy + 20);
|
|
|
|
|
|
|
|
m_plannerDecreaseStartTimeButton = new Gui::ImageButton("icons/orbit_reduce_big.png");
|
|
|
|
m_plannerDecreaseStartTimeButton->SetRenderDimensions(18, 18);
|
|
|
|
Add(m_plannerDecreaseStartTimeButton, dx, dy + 20);
|
|
|
|
|
|
|
|
m_plannerStartTimeText = (new Gui::Label(""))->Color(178, 178, 178);
|
|
|
|
Add(m_plannerStartTimeText, dx + 60, dy + 20);
|
|
|
|
|
2014-07-23 10:47:47 -07:00
|
|
|
m_plannerAddProgradeVelButton = new Gui::ImageButton("icons/orbit_increase_big.png");
|
|
|
|
m_plannerAddProgradeVelButton->SetRenderDimensions(18, 18);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerAddProgradeVelButton, dx + 40, dy + 40);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerZeroProgradeVelButton = new Gui::ImageButton("icons/orbit_proretro_big.png");
|
|
|
|
m_plannerZeroProgradeVelButton->SetRenderDimensions(18, 18);
|
2014-07-24 09:54:03 -07:00
|
|
|
m_plannerZeroProgradeVelButton->SetToolTip(Lang::PLANNER_RESET_PROGRADE);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerZeroProgradeVelButton, dx + 20, dy + 40);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerAddRetrogradeVelButton = new Gui::ImageButton("icons/orbit_reduce_big.png");
|
|
|
|
m_plannerAddRetrogradeVelButton->SetRenderDimensions(18, 18);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerAddRetrogradeVelButton, dx, dy + 40);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerProgradeDvText = (new Gui::Label(""))->Color(178, 178, 178);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerProgradeDvText, dx + 60, dy + 40);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerAddNormalVelButton = new Gui::ImageButton("icons/orbit_increase_big.png");
|
|
|
|
m_plannerAddNormalVelButton->SetRenderDimensions(18, 18);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerAddNormalVelButton, dx + 40, dy + 60);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerZeroNormalVelButton = new Gui::ImageButton("icons/orbit_normal_big.png");
|
|
|
|
m_plannerZeroNormalVelButton->SetRenderDimensions(18, 18);
|
2014-07-24 09:54:03 -07:00
|
|
|
m_plannerZeroNormalVelButton->SetToolTip(Lang::PLANNER_RESET_NORMAL);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerZeroNormalVelButton, dx + 20, dy + 60);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerAddAntiNormalVelButton = new Gui::ImageButton("icons/orbit_reduce_big.png");
|
|
|
|
m_plannerAddAntiNormalVelButton->SetRenderDimensions(18, 18);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerAddAntiNormalVelButton, dx, dy + 60);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerNormalDvText = (new Gui::Label(""))->Color(178, 178, 178);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerNormalDvText, dx + 60, dy + 60);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerAddRadiallyInVelButton = new Gui::ImageButton("icons/orbit_increase_big.png");
|
|
|
|
m_plannerAddRadiallyInVelButton->SetRenderDimensions(18, 18);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerAddRadiallyInVelButton, dx + 40, dy + 80);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerZeroRadialVelButton = new Gui::ImageButton("icons/orbit_radial_big.png");
|
|
|
|
m_plannerZeroRadialVelButton->SetRenderDimensions(18, 18);
|
2014-07-24 09:54:03 -07:00
|
|
|
m_plannerZeroRadialVelButton->SetToolTip(Lang::PLANNER_RESET_RADIAL);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerZeroRadialVelButton, dx + 20, dy + 80);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerAddRadiallyOutVelButton = new Gui::ImageButton("icons/orbit_reduce_big.png");
|
|
|
|
m_plannerAddRadiallyOutVelButton->SetRenderDimensions(18, 18);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerAddRadiallyOutVelButton, dx, dy + 80);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
m_plannerRadialDvText = (new Gui::Label(""))->Color(178, 178, 178);
|
2015-07-19 05:43:11 -07:00
|
|
|
Add(m_plannerRadialDvText, dx + 60, dy + 80);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2013-02-22 21:08:29 -08:00
|
|
|
const int time_controls_left = Gui::Screen::GetWidth() - 150;
|
2012-12-21 16:10:21 -08:00
|
|
|
const int time_controls_top = Gui::Screen::GetHeight() - 86;
|
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
Gui::ImageButton *b = new Gui::ImageButton("icons/sysview_accel_r3.png", "icons/sysview_accel_r3_on.png");
|
2012-03-31 01:44:53 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), -10000000.f));
|
2012-03-31 03:08:15 -07:00
|
|
|
b->onRelease.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 0.0f));
|
2012-12-21 16:10:21 -08:00
|
|
|
b->SetRenderDimensions(26, 17);
|
|
|
|
Add(b, time_controls_left + 0, time_controls_top);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
b = new Gui::ImageButton("icons/sysview_accel_r2.png", "icons/sysview_accel_r2_on.png");
|
2015-07-27 00:19:48 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), -100000.f));
|
2012-03-31 03:08:15 -07:00
|
|
|
b->onRelease.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 0.0f));
|
2012-09-02 08:30:57 -07:00
|
|
|
b->SetRenderDimensions(19, 17);
|
2012-12-21 16:10:21 -08:00
|
|
|
Add(b, time_controls_left + 26, time_controls_top);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
b = new Gui::ImageButton("icons/sysview_accel_r1.png", "icons/sysview_accel_r1_on.png");
|
2015-07-27 00:19:48 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), -1000.f));
|
2012-03-31 03:08:15 -07:00
|
|
|
b->onRelease.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 0.0f));
|
2012-09-02 08:30:57 -07:00
|
|
|
b->SetRenderDimensions(19, 17);
|
2012-12-21 16:10:21 -08:00
|
|
|
Add(b, time_controls_left + 45, time_controls_top);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2013-02-22 21:08:29 -08:00
|
|
|
b = new Gui::ImageButton("icons/sysview_accel_rl.png", "icons/sysview_accel_rl_on.png");
|
2013-02-23 03:29:23 -08:00
|
|
|
b->onPress.connect(sigc::mem_fun(this, &SystemView::OnClickRealt));
|
2013-02-22 21:08:29 -08:00
|
|
|
b->SetRenderDimensions(19, 17);
|
|
|
|
Add(b, time_controls_left + 64, time_controls_top);
|
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
b = new Gui::ImageButton("icons/sysview_accel_f1.png", "icons/sysview_accel_f1_on.png");
|
2015-07-27 00:19:48 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 1000.f));
|
2012-03-31 03:08:15 -07:00
|
|
|
b->onRelease.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 0.0f));
|
2012-09-02 08:30:57 -07:00
|
|
|
b->SetRenderDimensions(19, 17);
|
2013-02-22 21:08:29 -08:00
|
|
|
Add(b, time_controls_left + 83, time_controls_top);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
b = new Gui::ImageButton("icons/sysview_accel_f2.png", "icons/sysview_accel_f2_on.png");
|
2015-07-27 00:19:48 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 100000.f));
|
2012-03-31 03:08:15 -07:00
|
|
|
b->onRelease.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 0.0f));
|
2012-09-02 08:30:57 -07:00
|
|
|
b->SetRenderDimensions(19, 17);
|
2013-02-22 21:08:29 -08:00
|
|
|
Add(b, time_controls_left + 102, time_controls_top);
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2012-02-18 01:01:45 -08:00
|
|
|
b = new Gui::ImageButton("icons/sysview_accel_f3.png", "icons/sysview_accel_f3_on.png");
|
2012-03-31 01:44:53 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 10000000.f));
|
2012-03-31 03:08:15 -07:00
|
|
|
b->onRelease.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 0.0f));
|
2012-12-21 16:10:21 -08:00
|
|
|
b->SetRenderDimensions(26, 17);
|
2013-02-22 21:08:29 -08:00
|
|
|
Add(b, time_controls_left + 121, time_controls_top);
|
2010-03-13 10:33:15 -08:00
|
|
|
|
2013-09-24 00:50:41 -07:00
|
|
|
m_onMouseWheelCon =
|
2018-09-06 04:15:17 -07:00
|
|
|
Pi::input.onMouseWheel.connect(sigc::mem_fun(this, &SystemView::MouseWheel));
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2014-08-18 05:53:10 -07:00
|
|
|
Graphics::TextureBuilder b1 = Graphics::TextureBuilder::UI("icons/periapsis.png");
|
|
|
|
m_periapsisIcon.reset(new Gui::TexturedQuad(b1.GetOrCreateTexture(Gui::Screen::GetRenderer(), "ui")));
|
|
|
|
Graphics::TextureBuilder b2 = Graphics::TextureBuilder::UI("icons/apoapsis.png");
|
|
|
|
m_apoapsisIcon.reset(new Gui::TexturedQuad(b2.GetOrCreateTexture(Gui::Screen::GetRenderer(), "ui")));
|
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
Graphics::TextureBuilder l4 = Graphics::TextureBuilder::UI("icons/l4.png");
|
|
|
|
m_l4Icon.reset(new Gui::TexturedQuad(l4.GetOrCreateTexture(Gui::Screen::GetRenderer(), "ui")));
|
|
|
|
Graphics::TextureBuilder l5 = Graphics::TextureBuilder::UI("icons/l5.png");
|
|
|
|
m_l5Icon.reset(new Gui::TexturedQuad(l5.GetOrCreateTexture(Gui::Screen::GetRenderer(), "ui")));
|
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
ResetViewpoint();
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2014-08-07 00:36:04 -07:00
|
|
|
RefreshShips();
|
|
|
|
m_shipDrawing = OFF;
|
2015-11-17 12:57:10 -08:00
|
|
|
m_showL4L5 = LAG_OFF;
|
2014-07-23 10:47:47 -07:00
|
|
|
m_planner = Pi::planner;
|
2015-09-28 14:08:48 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
m_orbitVts.reset(new vector3f[N_VERTICES_MAX]);
|
|
|
|
m_orbitColors.reset(new Color[N_VERTICES_MAX]);
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemView::~SystemView()
|
|
|
|
{
|
2014-08-07 00:36:04 -07:00
|
|
|
m_contacts.clear();
|
2013-09-24 00:50:41 -07:00
|
|
|
m_onMouseWheelCon.disconnect();
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemView::OnClickAccel(float step)
|
|
|
|
{
|
2013-02-22 22:47:08 -08:00
|
|
|
m_realtime = false;
|
2008-06-24 03:17:31 -07:00
|
|
|
m_timeStep = step;
|
|
|
|
}
|
|
|
|
|
2014-07-24 09:54:03 -07:00
|
|
|
void SystemView::OnIncreaseFactorButtonClick(void) { m_planner->IncreaseFactor(); }
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::OnResetFactorButtonClick(void) { m_planner->ResetFactor(); }
|
2014-07-24 09:54:03 -07:00
|
|
|
void SystemView::OnDecreaseFactorButtonClick(void) { m_planner->DecreaseFactor(); }
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::OnToggleShipsButtonClick(void)
|
|
|
|
{
|
|
|
|
switch (m_shipDrawing) {
|
|
|
|
case OFF:
|
|
|
|
m_shipDrawing = BOXES;
|
|
|
|
RefreshShips();
|
|
|
|
break;
|
|
|
|
case BOXES:
|
|
|
|
m_shipDrawing = ORBITS;
|
|
|
|
RefreshShips();
|
|
|
|
break;
|
|
|
|
case ORBITS:
|
|
|
|
m_shipDrawing = OFF;
|
|
|
|
m_shipLabels->Clear();
|
|
|
|
break;
|
2014-08-07 00:36:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::OnToggleL4L5ButtonClick(Gui::MultiStateImageButton *b)
|
|
|
|
{
|
|
|
|
switch (m_showL4L5) {
|
|
|
|
case LAG_OFF:
|
|
|
|
m_showL4L5 = LAG_ICON;
|
|
|
|
m_toggleL4L5Button->SetActiveState(LAG_ICON);
|
|
|
|
break;
|
|
|
|
case LAG_ICON:
|
|
|
|
m_showL4L5 = LAG_ICONTEXT;
|
|
|
|
m_toggleL4L5Button->SetActiveState(LAG_ICONTEXT);
|
|
|
|
break;
|
|
|
|
case LAG_ICONTEXT:
|
|
|
|
m_showL4L5 = LAG_OFF;
|
|
|
|
m_toggleL4L5Button->SetActiveState(LAG_OFF);
|
|
|
|
break;
|
2015-11-17 12:57:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 03:29:23 -08:00
|
|
|
void SystemView::OnClickRealt()
|
2013-02-22 22:09:43 -08:00
|
|
|
{
|
2013-02-22 22:47:08 -08:00
|
|
|
m_realtime = true;
|
2013-02-22 22:09:43 -08:00
|
|
|
}
|
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
void SystemView::ResetViewpoint()
|
|
|
|
{
|
|
|
|
m_selectedObject = 0;
|
2010-03-13 10:33:15 -08:00
|
|
|
m_rot_z = 0;
|
|
|
|
m_rot_x = 50;
|
2018-10-20 08:18:06 -07:00
|
|
|
m_rot_z_to = m_rot_z;
|
|
|
|
m_rot_x_to = m_rot_x;
|
2019-01-02 08:59:07 -08:00
|
|
|
m_zoom = 1.0f / float(AU);
|
2012-04-10 09:06:48 -07:00
|
|
|
m_zoomTo = m_zoom;
|
2008-06-24 03:17:31 -07:00
|
|
|
m_timeStep = 1.0f;
|
2014-09-15 11:12:15 -07:00
|
|
|
m_time = m_game->GetTime();
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
void SystemView::PutOrbit(const Orbit *orbit, const vector3d &offset, const Color &color, const double planetRadius, const bool showLagrange)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
2015-07-26 15:11:10 -07:00
|
|
|
double maxT = 1.;
|
|
|
|
unsigned short num_vertices = 0;
|
2015-09-28 14:08:48 -07:00
|
|
|
for (unsigned short i = 0; i < N_VERTICES_MAX; ++i) {
|
|
|
|
const double t = double(i) / double(N_VERTICES_MAX);
|
2015-07-26 15:11:10 -07:00
|
|
|
const vector3d pos = orbit->EvenSpacedPosTrajectory(t);
|
2019-01-02 08:59:07 -08:00
|
|
|
if (pos.Length() < planetRadius) {
|
2015-07-26 15:11:10 -07:00
|
|
|
maxT = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 14:23:35 -07:00
|
|
|
static const float startTrailPercent = 0.85;
|
2018-01-10 08:58:08 -08:00
|
|
|
static const float fadedColorParameter = 0.8;
|
2015-09-20 04:22:16 -07:00
|
|
|
|
|
|
|
Uint16 fadingColors = 0;
|
2015-11-17 12:57:10 -08:00
|
|
|
const double tMinust0 = m_time - m_game->GetTime();
|
2015-09-28 14:08:48 -07:00
|
|
|
for (unsigned short i = 0; i < N_VERTICES_MAX; ++i) {
|
|
|
|
const double t = double(i) / double(N_VERTICES_MAX) * maxT;
|
2019-01-02 08:59:07 -08:00
|
|
|
if (fadingColors == 0 && t >= startTrailPercent * maxT)
|
2015-09-20 04:22:16 -07:00
|
|
|
fadingColors = i;
|
2015-11-17 12:57:10 -08:00
|
|
|
const vector3d pos = orbit->EvenSpacedPosTrajectory(t, tMinust0);
|
2015-09-28 14:08:48 -07:00
|
|
|
m_orbitVts[i] = vector3f(offset + pos * double(m_zoom));
|
2013-03-29 07:59:05 -07:00
|
|
|
++num_vertices;
|
|
|
|
if (pos.Length() < planetRadius)
|
|
|
|
break;
|
|
|
|
}
|
2013-02-14 06:37:54 -08:00
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
const Color fadedColor = color * fadedColorParameter;
|
2015-09-28 14:08:48 -07:00
|
|
|
std::fill_n(m_orbitColors.get(), num_vertices, fadedColor);
|
2015-09-28 14:23:35 -07:00
|
|
|
const Uint16 trailLength = num_vertices - fadingColors;
|
2015-09-20 04:22:16 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
for (Uint16 currentColor = 0; currentColor < trailLength; ++currentColor) {
|
2015-09-20 04:22:16 -07:00
|
|
|
float scalingParameter = fadedColorParameter + static_cast<float>(currentColor) / trailLength * (1.f - fadedColorParameter);
|
2015-09-28 14:08:48 -07:00
|
|
|
m_orbitColors[currentColor + fadingColors] = color * scalingParameter;
|
2015-09-20 04:22:16 -07:00
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:05 -07:00
|
|
|
if (num_vertices > 1) {
|
2015-09-28 14:08:48 -07:00
|
|
|
m_orbits.SetData(num_vertices, m_orbitVts.get(), m_orbitColors.get());
|
2015-09-20 04:22:16 -07:00
|
|
|
|
2013-03-29 07:59:05 -07:00
|
|
|
// don't close the loop for hyperbolas and parabolas and crashed ellipses
|
2015-07-26 15:11:10 -07:00
|
|
|
if (maxT < 1. || (orbit->GetEccentricity() > 1.0)) {
|
2015-01-02 14:43:26 -08:00
|
|
|
m_orbits.Draw(m_renderer, m_lineState, LINE_STRIP);
|
|
|
|
} else {
|
|
|
|
m_orbits.Draw(m_renderer, m_lineState, LINE_LOOP);
|
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
2014-08-18 05:53:10 -07:00
|
|
|
|
|
|
|
Gui::Screen::EnterOrtho();
|
|
|
|
vector3d pos;
|
2019-01-02 08:59:07 -08:00
|
|
|
if (Gui::Screen::Project(offset + orbit->Perigeum() * double(m_zoom), pos))
|
|
|
|
m_periapsisIcon->Draw(Pi::renderer, vector2f(pos.x - 3, pos.y - 5), vector2f(6, 10), color);
|
|
|
|
if (Gui::Screen::Project(offset + orbit->Apogeum() * double(m_zoom), pos))
|
|
|
|
m_apoapsisIcon->Draw(Pi::renderer, vector2f(pos.x - 3, pos.y - 5), vector2f(6, 10), color);
|
2015-11-17 12:57:10 -08:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
if (showLagrange && m_showL4L5 != LAG_OFF) {
|
2015-11-22 11:03:00 -08:00
|
|
|
const Color LPointColor(0x00d6e2ff);
|
2015-11-17 12:57:10 -08:00
|
|
|
const vector3d posL4 = orbit->EvenSpacedPosTrajectory((1.0 / 360.0) * 60.0, tMinust0);
|
|
|
|
if (Gui::Screen::Project(offset + posL4 * double(m_zoom), pos)) {
|
2015-11-22 11:03:00 -08:00
|
|
|
m_l4Icon->Draw(Pi::renderer, vector2f(pos.x - 2, pos.y - 2), vector2f(4, 4), LPointColor);
|
2019-01-02 08:59:07 -08:00
|
|
|
if (m_showL4L5 == LAG_ICONTEXT)
|
2015-11-17 12:57:10 -08:00
|
|
|
m_objectLabels->Add(std::string("L4"), sigc::mem_fun(this, &SystemView::OnClickLagrange), pos.x, pos.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
const vector3d posL5 = orbit->EvenSpacedPosTrajectory((1.0 / 360.0) * 300.0, tMinust0);
|
|
|
|
if (Gui::Screen::Project(offset + posL5 * double(m_zoom), pos)) {
|
2015-11-22 11:03:00 -08:00
|
|
|
m_l5Icon->Draw(Pi::renderer, vector2f(pos.x - 2, pos.y - 2), vector2f(4, 4), LPointColor);
|
2015-11-17 12:57:10 -08:00
|
|
|
if (m_showL4L5 == LAG_ICONTEXT)
|
|
|
|
m_objectLabels->Add(std::string("L5"), sigc::mem_fun(this, &SystemView::OnClickLagrange), pos.x, pos.y);
|
|
|
|
}
|
|
|
|
}
|
2014-08-18 05:53:10 -07:00
|
|
|
Gui::Screen::LeaveOrtho();
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
void SystemView::OnClickObject(const SystemBody *b)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
|
|
|
m_selectedObject = b;
|
2009-10-18 09:12:51 -07:00
|
|
|
std::string desc;
|
|
|
|
std::string data;
|
|
|
|
|
2014-01-06 05:49:17 -08:00
|
|
|
desc += std::string(Lang::NAME_OBJECT);
|
2011-09-14 13:13:53 -07:00
|
|
|
desc += ":\n";
|
2019-01-02 08:59:07 -08:00
|
|
|
data += b->GetName() + "\n";
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2011-07-27 03:46:56 -07:00
|
|
|
desc += std::string(Lang::DAY_LENGTH);
|
|
|
|
desc += std::string(Lang::ROTATIONAL_PERIOD);
|
2011-09-14 13:13:53 -07:00
|
|
|
desc += ":\n";
|
2014-02-20 13:40:31 -08:00
|
|
|
data += stringf(Lang::N_DAYS, formatarg("days", b->GetRotationPeriodInDays())) + "\n";
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2011-07-27 03:46:56 -07:00
|
|
|
desc += std::string(Lang::RADIUS);
|
2011-09-14 13:13:53 -07:00
|
|
|
desc += ":\n";
|
2019-01-02 08:59:07 -08:00
|
|
|
data += format_distance(b->GetRadius()) + "\n";
|
2009-10-18 09:12:51 -07:00
|
|
|
|
2014-02-20 13:40:31 -08:00
|
|
|
if (b->GetParent()) {
|
2011-07-27 03:46:56 -07:00
|
|
|
desc += std::string(Lang::SEMI_MAJOR_AXIS);
|
2019-01-02 08:59:07 -08:00
|
|
|
desc += ":\n";
|
|
|
|
data += format_distance(b->GetOrbit().GetSemiMajorAxis()) + "\n";
|
2009-10-18 09:12:51 -07:00
|
|
|
|
2011-07-27 03:46:56 -07:00
|
|
|
desc += std::string(Lang::ORBITAL_PERIOD);
|
2019-01-02 08:59:07 -08:00
|
|
|
desc += ":\n";
|
|
|
|
data += stringf(Lang::N_DAYS, formatarg("days", b->GetOrbit().Period() / (24 * 60 * 60))) + "\n";
|
2009-10-18 09:12:51 -07:00
|
|
|
}
|
|
|
|
m_infoLabel->SetText(desc);
|
|
|
|
m_infoText->SetText(data);
|
2011-09-14 13:13:53 -07:00
|
|
|
|
2014-08-13 05:40:12 -07:00
|
|
|
// click on object (in same system) sets/unsets it as nav target
|
|
|
|
SystemPath path = m_system->GetPathOf(b);
|
2014-09-15 11:12:15 -07:00
|
|
|
if (m_game->GetSpace()->GetStarSystem()->GetPath() == m_system->GetPath()) {
|
2019-01-02 08:59:07 -08:00
|
|
|
Body *body = m_game->GetSpace()->FindBodyForPath(&path);
|
2014-08-13 05:40:12 -07:00
|
|
|
if (body != 0) {
|
2019-01-02 08:59:07 -08:00
|
|
|
if (Pi::player->GetNavTarget() == body) {
|
2011-09-14 13:13:53 -07:00
|
|
|
Pi::player->SetNavTarget(body);
|
2014-08-13 05:40:12 -07:00
|
|
|
Pi::player->SetNavTarget(0);
|
2014-09-15 11:12:15 -07:00
|
|
|
m_game->log->Add(Lang::UNSET_NAVTARGET);
|
2019-01-02 08:59:07 -08:00
|
|
|
} else {
|
2014-08-13 05:40:12 -07:00
|
|
|
Pi::player->SetNavTarget(body);
|
2014-09-15 11:12:15 -07:00
|
|
|
m_game->log->Add(Lang::SET_NAVTARGET_TO + body->GetLabel());
|
2014-08-13 05:40:12 -07:00
|
|
|
}
|
2011-09-14 13:13:53 -07:00
|
|
|
}
|
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
void SystemView::OnClickLagrange()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
void SystemView::PutLabel(const SystemBody *b, const vector3d &offset)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
|
|
|
Gui::Screen::EnterOrtho();
|
2011-10-18 13:19:29 -07:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
vector3d pos;
|
2011-02-20 13:01:37 -08:00
|
|
|
if (Gui::Screen::Project(offset, pos)) {
|
2008-06-24 03:17:31 -07:00
|
|
|
// libsigc++ is a beautiful thing
|
2014-02-20 13:40:31 -08:00
|
|
|
m_objectLabels->Add(b->GetName(), sigc::bind(sigc::mem_fun(this, &SystemView::OnClickObject), b), pos.x, pos.y);
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::Screen::LeaveOrtho();
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::LabelShip(Ship *s, const vector3d &offset)
|
|
|
|
{
|
2014-08-07 03:04:46 -07:00
|
|
|
Gui::Screen::EnterOrtho();
|
|
|
|
|
|
|
|
vector3d pos;
|
|
|
|
if (Gui::Screen::Project(offset, pos)) {
|
2014-08-13 06:44:05 -07:00
|
|
|
m_shipLabels->Add(s->GetLabel(), sigc::bind(sigc::mem_fun(this, &SystemView::OnClickShip), s), pos.x, pos.y);
|
2014-08-07 03:04:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::Screen::LeaveOrtho();
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::OnClickShip(Ship *s)
|
|
|
|
{
|
|
|
|
if (!s) {
|
|
|
|
printf("clicked on ship label but ship wasn't there\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Pi::player->GetNavTarget() == s) { //un-select ship if already selected
|
2014-08-07 12:53:11 -07:00
|
|
|
Pi::player->SetNavTarget(0); // remove current
|
2014-09-15 11:12:15 -07:00
|
|
|
m_game->log->Add(Lang::UNSET_NAVTARGET);
|
2019-01-02 08:59:07 -08:00
|
|
|
m_infoLabel->SetText(""); // remove lingering text
|
2014-08-11 07:56:54 -07:00
|
|
|
m_infoText->SetText("");
|
2014-08-07 12:53:11 -07:00
|
|
|
} else {
|
|
|
|
Pi::player->SetNavTarget(s);
|
2014-09-15 11:12:15 -07:00
|
|
|
m_game->log->Add(Lang::SET_NAVTARGET_TO + s->GetLabel());
|
2014-08-11 07:56:54 -07:00
|
|
|
|
|
|
|
// always show label of selected ship...
|
|
|
|
std::string text;
|
|
|
|
text += s->GetLabel();
|
|
|
|
text += "\n";
|
|
|
|
|
2016-09-30 04:50:53 -07:00
|
|
|
// ...if we have advanced target scanner equipment, show some extra info on selected ship
|
2014-08-11 07:56:54 -07:00
|
|
|
int prop_var = 0;
|
2016-09-30 04:50:53 -07:00
|
|
|
Pi::player->Properties().Get("target_scanner_level_cap", prop_var);
|
2019-01-02 08:59:07 -08:00
|
|
|
if (prop_var > 1) { // advanced target scanner
|
2014-08-11 07:56:54 -07:00
|
|
|
const shipstats_t &stats = s->GetStats();
|
|
|
|
|
|
|
|
text += s->GetShipType()->name;
|
|
|
|
text += "\n";
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
lua_State *l = Lua::manager->GetLuaState();
|
2014-08-11 07:56:54 -07:00
|
|
|
int clean_stack = lua_gettop(l);
|
|
|
|
|
|
|
|
LuaObject<Ship>::CallMethod<LuaRef>(s, "GetEquip", "engine").PushCopyToStack();
|
|
|
|
lua_rawgeti(l, -1, 1);
|
|
|
|
if (lua_isnil(l, -1)) {
|
|
|
|
text += Lang::NO_HYPERDRIVE;
|
|
|
|
} else {
|
|
|
|
text += LuaTable(l, -1).CallMethod<std::string>("GetName");
|
|
|
|
}
|
|
|
|
lua_settop(l, clean_stack);
|
|
|
|
|
|
|
|
text += "\n";
|
2015-10-10 07:32:43 -07:00
|
|
|
text += stringf(Lang::MASS_N_TONNES, formatarg("mass", stats.static_mass));
|
2014-08-11 07:56:54 -07:00
|
|
|
text += "\n";
|
|
|
|
text += stringf(Lang::CARGO_N, formatarg("mass", stats.used_cargo));
|
|
|
|
text += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
m_infoLabel->SetText(text);
|
2019-01-02 08:59:07 -08:00
|
|
|
m_infoText->SetText(""); // clear lingering info from body being selected
|
2014-08-07 12:53:11 -07:00
|
|
|
}
|
2014-08-07 03:04:46 -07:00
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
void SystemView::PutBody(const SystemBody *b, const vector3d &offset, const matrix4x4f &trans)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
2017-03-05 05:15:55 -08:00
|
|
|
if (b->GetType() == SystemBody::TYPE_STARPORT_SURFACE)
|
2015-11-15 13:22:56 -08:00
|
|
|
return;
|
2012-08-04 15:07:05 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
if (b->GetType() != SystemBody::TYPE_GRAVPOINT) {
|
|
|
|
if (!m_bodyIcon) {
|
2014-01-26 17:26:44 -08:00
|
|
|
Graphics::RenderStateDesc rsd;
|
|
|
|
auto solidState = m_renderer->CreateRenderState(rsd);
|
|
|
|
m_bodyIcon.reset(new Graphics::Drawables::Disk(m_renderer, solidState, Color::WHITE, 1.0f));
|
2009-10-18 09:12:51 -07:00
|
|
|
}
|
2012-08-04 15:07:05 -07:00
|
|
|
|
|
|
|
const double radius = b->GetRadius() * m_zoom;
|
|
|
|
|
|
|
|
matrix4x4f invRot = trans;
|
|
|
|
invRot.ClearToRotOnly();
|
2014-10-07 06:04:18 -07:00
|
|
|
invRot = invRot.Inverse();
|
2012-08-04 15:07:05 -07:00
|
|
|
|
|
|
|
matrix4x4f bodyTrans = trans;
|
|
|
|
bodyTrans.Translate(vector3f(offset));
|
|
|
|
bodyTrans.Scale(radius);
|
|
|
|
m_renderer->SetTransform(bodyTrans * invRot);
|
|
|
|
m_bodyIcon->Draw(m_renderer);
|
|
|
|
|
|
|
|
m_renderer->SetTransform(trans);
|
2008-08-12 09:38:23 -07:00
|
|
|
|
2009-05-04 05:02:58 -07:00
|
|
|
PutLabel(b, offset);
|
2008-08-12 09:38:23 -07:00
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
Frame *frame = Pi::player->GetFrame();
|
2019-01-02 08:59:07 -08:00
|
|
|
if (frame->IsRotFrame())
|
2015-11-15 13:22:56 -08:00
|
|
|
frame = frame->GetNonRotFrame();
|
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
// display the players orbit(?)
|
2019-01-02 08:59:07 -08:00
|
|
|
if (frame->GetSystemBody() == b && frame->GetSystemBody()->GetMass() > 0) {
|
2014-09-15 11:12:15 -07:00
|
|
|
const double t0 = m_game->GetTime();
|
2013-03-29 07:59:47 -07:00
|
|
|
Orbit playerOrbit = Pi::player->ComputeOrbit();
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2013-12-09 12:37:02 -08:00
|
|
|
PutOrbit(&playerOrbit, offset, Color::RED, b->GetRadius());
|
2014-08-18 05:53:10 -07:00
|
|
|
|
2015-11-15 13:22:56 -08:00
|
|
|
const double plannerStartTime = m_planner->GetStartTime();
|
2019-01-02 08:59:07 -08:00
|
|
|
if (!m_planner->GetPosition().ExactlyEqual(vector3d(0, 0, 0))) {
|
2015-07-18 15:24:19 -07:00
|
|
|
Orbit plannedOrbit = Orbit::FromBodyState(m_planner->GetPosition(),
|
2019-01-02 08:59:07 -08:00
|
|
|
m_planner->GetVel(),
|
|
|
|
frame->GetSystemBody()->GetMass());
|
2014-08-18 05:53:10 -07:00
|
|
|
PutOrbit(&plannedOrbit, offset, Color::STEELBLUE, b->GetRadius());
|
2019-01-02 08:59:07 -08:00
|
|
|
if (std::fabs(m_time - t0) > 1. && (m_time - plannerStartTime) > 0.)
|
2015-08-12 14:34:53 -07:00
|
|
|
PutSelectionBox(offset + plannedOrbit.OrbitalPosAtTime(m_time - plannerStartTime) * static_cast<double>(m_zoom), Color::STEELBLUE);
|
2015-07-27 00:19:48 -07:00
|
|
|
else
|
|
|
|
PutSelectionBox(offset + m_planner->GetPosition() * static_cast<double>(m_zoom), Color::STEELBLUE);
|
2014-08-18 05:53:10 -07:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
PutSelectionBox(offset + playerOrbit.OrbitalPosAtTime(m_time - t0) * double(m_zoom), Color::RED);
|
2013-02-14 06:37:54 -08:00
|
|
|
}
|
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
// display all child bodies and their orbits
|
2019-01-02 08:59:07 -08:00
|
|
|
if (b->HasChildren()) {
|
|
|
|
for (const SystemBody *kid : b->GetChildren()) {
|
2017-03-05 05:15:55 -08:00
|
|
|
if (is_zero_general(kid->GetOrbit().GetSemiMajorAxis()))
|
2015-11-15 13:22:56 -08:00
|
|
|
continue;
|
|
|
|
|
2015-11-17 12:57:10 -08:00
|
|
|
const double axisZoom = kid->GetOrbit().GetSemiMajorAxis() * m_zoom;
|
2019-01-02 08:59:07 -08:00
|
|
|
if (axisZoom < DEFAULT_VIEW_DISTANCE) {
|
2015-11-17 12:57:10 -08:00
|
|
|
const SystemBody::BodySuperType bst = kid->GetSuperType();
|
|
|
|
const bool showLagrange = (bst == SystemBody::SUPERTYPE_ROCKY_PLANET || bst == SystemBody::SUPERTYPE_GAS_GIANT);
|
|
|
|
PutOrbit(&(kid->GetOrbit()), offset, Color::GREEN, 0.0, showLagrange);
|
2013-03-29 07:59:47 -07:00
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
// not using current time yet
|
2015-11-17 12:57:10 -08:00
|
|
|
const vector3d pos = kid->GetOrbit().OrbitalPosAtTime(m_time) * double(m_zoom);
|
2014-02-22 08:06:23 -08:00
|
|
|
PutBody(kid, offset + pos, trans);
|
2013-03-29 07:59:47 -07:00
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 18:53:53 -07:00
|
|
|
void SystemView::PutSelectionBox(const SystemBody *b, const vector3d &rootPos, const Color &col)
|
2011-10-18 13:19:29 -07:00
|
|
|
{
|
|
|
|
// surface starports just show the planet as being selected,
|
|
|
|
// because SystemView doesn't render terrains anyway
|
2014-02-20 13:40:31 -08:00
|
|
|
if (b->GetType() == SystemBody::TYPE_STARPORT_SURFACE)
|
|
|
|
b = b->GetParent();
|
2011-10-18 13:19:29 -07:00
|
|
|
assert(b);
|
|
|
|
|
|
|
|
vector3d pos = rootPos;
|
2012-04-17 18:53:53 -07:00
|
|
|
// while (b->parent), not while (b) because the root SystemBody is defined to be at (0,0,0)
|
2014-02-20 13:40:31 -08:00
|
|
|
while (b->GetParent()) {
|
|
|
|
pos += b->GetOrbit().OrbitalPosAtTime(m_time) * double(m_zoom);
|
|
|
|
b = b->GetParent();
|
2011-10-18 13:19:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PutSelectionBox(pos, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemView::PutSelectionBox(const vector3d &worldPos, const Color &col)
|
|
|
|
{
|
|
|
|
Gui::Screen::EnterOrtho();
|
|
|
|
|
|
|
|
vector3d screenPos;
|
|
|
|
if (Gui::Screen::Project(worldPos, screenPos)) {
|
|
|
|
// XXX copied from WorldView::DrawTargetSquare -- these should be unified
|
|
|
|
const float x1 = float(screenPos.x - SystemView::PICK_OBJECT_RECT_SIZE * 0.5);
|
|
|
|
const float x2 = float(x1 + SystemView::PICK_OBJECT_RECT_SIZE);
|
|
|
|
const float y1 = float(screenPos.y - SystemView::PICK_OBJECT_RECT_SIZE * 0.5);
|
|
|
|
const float y2 = float(y1 + SystemView::PICK_OBJECT_RECT_SIZE);
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
const vector3f verts[4] = {
|
|
|
|
vector3f(x1, y1, 0.f),
|
|
|
|
vector3f(x2, y1, 0.f),
|
|
|
|
vector3f(x2, y2, 0.f),
|
|
|
|
vector3f(x1, y2, 0.f)
|
|
|
|
};
|
2015-01-02 14:43:26 -08:00
|
|
|
m_selectBox.SetData(4, &verts[0], col);
|
|
|
|
m_selectBox.Draw(m_renderer, m_lineState, Graphics::LINE_LOOP);
|
2011-10-18 13:19:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::Screen::LeaveOrtho();
|
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
void SystemView::GetTransformTo(const SystemBody *b, vector3d &pos)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
2014-02-20 13:40:31 -08:00
|
|
|
if (b->GetParent()) {
|
|
|
|
GetTransformTo(b->GetParent(), pos);
|
|
|
|
pos -= double(m_zoom) * b->GetOrbit().OrbitalPosAtTime(m_time);
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemView::Draw3D()
|
|
|
|
{
|
2013-11-10 03:26:50 -08:00
|
|
|
PROFILE_SCOPED()
|
2013-10-02 10:24:46 -07:00
|
|
|
m_renderer->SetPerspectiveProjection(50.f, m_renderer->GetDisplayAspect(), 1.f, 1000.f);
|
2012-02-13 07:37:51 -08:00
|
|
|
m_renderer->ClearScreen();
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2014-09-15 11:27:49 -07:00
|
|
|
SystemPath path = m_game->GetSectorView()->GetSelected().SystemOnly();
|
2008-06-24 03:17:31 -07:00
|
|
|
if (m_system) {
|
2014-01-18 10:51:22 -08:00
|
|
|
if (m_system->GetUnexplored() != m_unexplored || !m_system->GetPath().IsSameSystem(path)) {
|
2011-11-14 21:56:55 -08:00
|
|
|
m_system.Reset();
|
2008-06-24 03:17:31 -07:00
|
|
|
ResetViewpoint();
|
|
|
|
}
|
|
|
|
}
|
2013-04-01 13:27:00 -07:00
|
|
|
|
2013-02-22 22:47:08 -08:00
|
|
|
if (m_realtime) {
|
2014-09-15 11:12:15 -07:00
|
|
|
m_time = m_game->GetTime();
|
2019-01-02 08:59:07 -08:00
|
|
|
} else {
|
|
|
|
m_time += m_timeStep * Pi::GetFrameTime();
|
2013-02-22 22:47:08 -08:00
|
|
|
}
|
2019-01-02 08:59:07 -08:00
|
|
|
std::string t = Lang::TIME_POINT + format_date(m_time);
|
2008-06-24 03:17:31 -07:00
|
|
|
m_timePoint->SetText(t);
|
|
|
|
|
2014-01-18 10:51:22 -08:00
|
|
|
if (!m_system) {
|
|
|
|
m_system = m_game->GetGalaxy()->GetStarSystem(path);
|
|
|
|
m_unexplored = m_system->GetUnexplored();
|
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2012-02-14 07:25:40 -08:00
|
|
|
matrix4x4f trans = matrix4x4f::Identity();
|
2019-01-02 08:59:07 -08:00
|
|
|
trans.Translate(0, 0, -DEFAULT_VIEW_DISTANCE);
|
|
|
|
trans.Rotate(DEG2RAD(m_rot_x), 1, 0, 0);
|
2018-07-06 10:59:01 -07:00
|
|
|
trans.Rotate(-DEG2RAD(m_rot_z), 0, 0, 1);
|
2012-02-14 07:25:40 -08:00
|
|
|
m_renderer->SetTransform(trans);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
vector3d pos(0, 0, 0);
|
2009-05-04 05:02:58 -07:00
|
|
|
if (m_selectedObject) GetTransformTo(m_selectedObject, pos);
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2014-10-14 12:43:09 -07:00
|
|
|
// glLineWidth(2);
|
2011-01-19 21:07:28 -08:00
|
|
|
m_objectLabels->Clear();
|
2012-12-02 06:41:34 -08:00
|
|
|
if (m_system->GetUnexplored())
|
2011-07-27 03:46:56 -07:00
|
|
|
m_infoLabel->SetText(Lang::UNEXPLORED_SYSTEM_NO_SYSTEM_VIEW);
|
2014-01-18 10:51:22 -08:00
|
|
|
else {
|
|
|
|
if (m_system->GetRootBody()) {
|
|
|
|
PutBody(m_system->GetRootBody().Get(), pos, trans);
|
|
|
|
if (m_game->GetSpace()->GetStarSystem() == m_system) {
|
|
|
|
const Body *navTarget = Pi::player->GetNavTarget();
|
|
|
|
const SystemBody *navTargetSystemBody = navTarget ? navTarget->GetSystemBody() : 0;
|
|
|
|
if (navTargetSystemBody)
|
|
|
|
PutSelectionBox(navTargetSystemBody, pos, Color::GREEN);
|
|
|
|
}
|
2011-10-18 13:19:29 -07:00
|
|
|
}
|
|
|
|
}
|
2014-10-14 12:43:09 -07:00
|
|
|
// glLineWidth(1);
|
2013-01-08 22:13:14 -08:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
if (m_shipDrawing != OFF) {
|
2014-08-09 07:24:12 -07:00
|
|
|
RefreshShips();
|
2014-09-15 11:12:15 -07:00
|
|
|
DrawShips(m_time - m_game->GetTime(), pos);
|
2014-08-07 00:36:04 -07:00
|
|
|
}
|
|
|
|
|
2013-01-08 22:13:14 -08:00
|
|
|
UIView::Draw3D();
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemView::Update()
|
|
|
|
{
|
2008-06-28 13:00:50 -07:00
|
|
|
const float ft = Pi::GetFrameTime();
|
2011-09-18 15:18:02 -07:00
|
|
|
// XXX ugly hack checking for console here
|
|
|
|
if (!Pi::IsConsoleActive()) {
|
2018-09-06 04:15:17 -07:00
|
|
|
if (Pi::input.KeyState(SDLK_EQUALS) ||
|
2012-12-22 14:26:30 -08:00
|
|
|
m_zoomInButton->IsPressed())
|
2019-01-02 08:59:07 -08:00
|
|
|
m_zoomTo *= pow(ZOOM_IN_SPEED * Pi::GetMoveSpeedShiftModifier(), ft);
|
2018-09-06 04:15:17 -07:00
|
|
|
if (Pi::input.KeyState(SDLK_MINUS) ||
|
2012-12-22 14:26:30 -08:00
|
|
|
m_zoomOutButton->IsPressed())
|
2019-01-02 08:59:07 -08:00
|
|
|
m_zoomTo *= pow(ZOOM_OUT_SPEED / Pi::GetMoveSpeedShiftModifier(), ft);
|
2014-07-23 10:47:47 -07:00
|
|
|
|
|
|
|
// transfer planner buttons
|
2019-01-02 08:59:07 -08:00
|
|
|
if (m_plannerIncreaseStartTimeButton->IsPressed()) {
|
|
|
|
m_planner->AddStartTime(10.);
|
|
|
|
}
|
|
|
|
if (m_plannerDecreaseStartTimeButton->IsPressed()) {
|
|
|
|
m_planner->AddStartTime(-10.);
|
|
|
|
}
|
|
|
|
if (m_plannerAddProgradeVelButton->IsPressed()) {
|
|
|
|
m_planner->AddDv(PROGRADE, 10.0);
|
|
|
|
}
|
|
|
|
if (m_plannerAddRetrogradeVelButton->IsPressed()) {
|
|
|
|
m_planner->AddDv(PROGRADE, -10.0);
|
|
|
|
}
|
|
|
|
if (m_plannerAddNormalVelButton->IsPressed()) {
|
|
|
|
m_planner->AddDv(NORMAL, 10.0);
|
|
|
|
}
|
|
|
|
if (m_plannerAddAntiNormalVelButton->IsPressed()) {
|
|
|
|
m_planner->AddDv(NORMAL, -10.0);
|
|
|
|
}
|
|
|
|
if (m_plannerAddRadiallyInVelButton->IsPressed()) {
|
|
|
|
m_planner->AddDv(RADIAL, 10.0);
|
|
|
|
}
|
|
|
|
if (m_plannerAddRadiallyOutVelButton->IsPressed()) {
|
|
|
|
m_planner->AddDv(RADIAL, -10.0);
|
|
|
|
}
|
|
|
|
if (m_plannerResetStartTimeButton->IsPressed()) {
|
|
|
|
m_planner->ResetStartTime();
|
|
|
|
}
|
|
|
|
if (m_plannerZeroProgradeVelButton->IsPressed()) {
|
|
|
|
m_planner->ResetDv(PROGRADE);
|
|
|
|
}
|
|
|
|
if (m_plannerZeroNormalVelButton->IsPressed()) {
|
|
|
|
m_planner->ResetDv(NORMAL);
|
|
|
|
}
|
|
|
|
if (m_plannerZeroRadialVelButton->IsPressed()) {
|
|
|
|
m_planner->ResetDv(RADIAL);
|
|
|
|
}
|
2014-07-23 10:47:47 -07:00
|
|
|
|
2014-07-24 09:54:03 -07:00
|
|
|
m_plannerFactorText->SetText(m_planner->printFactor());
|
2015-07-27 00:19:48 -07:00
|
|
|
m_plannerStartTimeText->SetText(m_planner->printDeltaTime());
|
2014-07-24 23:37:48 -07:00
|
|
|
m_plannerProgradeDvText->SetText(m_planner->printDv(PROGRADE));
|
|
|
|
m_plannerNormalDvText->SetText(m_planner->printDv(NORMAL));
|
|
|
|
m_plannerRadialDvText->SetText(m_planner->printDv(RADIAL));
|
2011-09-18 15:18:02 -07:00
|
|
|
}
|
2012-04-10 09:06:48 -07:00
|
|
|
// TODO: add "true" lower/upper bounds to m_zoomTo / m_zoom
|
|
|
|
m_zoomTo = Clamp(m_zoomTo, MIN_ZOOM, MAX_ZOOM);
|
|
|
|
m_zoom = Clamp(m_zoom, MIN_ZOOM, MAX_ZOOM);
|
2018-10-20 08:18:06 -07:00
|
|
|
// Since m_zoom changes over multiple orders of magnitude, any fixed linear factor will not be appropriate
|
|
|
|
// at some of them.
|
|
|
|
AnimationCurves::Approach(m_zoom, m_zoomTo, ft, 10.f, m_zoomTo / 60.f);
|
|
|
|
|
|
|
|
AnimationCurves::Approach(m_rot_x, m_rot_x_to, ft);
|
|
|
|
AnimationCurves::Approach(m_rot_z, m_rot_z_to, ft);
|
2012-04-10 09:06:48 -07:00
|
|
|
|
2018-09-06 04:15:17 -07:00
|
|
|
if (Pi::input.MouseButtonState(SDL_BUTTON_RIGHT)) {
|
2008-06-24 03:17:31 -07:00
|
|
|
int motion[2];
|
2018-09-06 04:15:17 -07:00
|
|
|
Pi::input.GetMouseMotion(motion);
|
2019-01-02 08:59:07 -08:00
|
|
|
m_rot_x_to += motion[1] * 20 * ft;
|
|
|
|
m_rot_z_to += motion[0] * 20 * ft;
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
2013-01-08 22:13:14 -08:00
|
|
|
|
|
|
|
UIView::Update();
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
2010-03-13 10:33:15 -08:00
|
|
|
|
2013-09-24 00:50:41 -07:00
|
|
|
void SystemView::MouseWheel(bool up)
|
2010-03-13 10:33:15 -08:00
|
|
|
{
|
2012-01-19 18:43:29 -08:00
|
|
|
if (this == Pi::GetView()) {
|
2013-09-24 00:50:41 -07:00
|
|
|
if (!up)
|
2019-01-02 08:59:07 -08:00
|
|
|
m_zoomTo *= ((ZOOM_OUT_SPEED - 1) * WHEEL_SENSITIVITY + 1) / Pi::GetMoveSpeedShiftModifier();
|
2013-09-24 00:50:41 -07:00
|
|
|
else
|
2019-01-02 08:59:07 -08:00
|
|
|
m_zoomTo *= ((ZOOM_IN_SPEED - 1) * WHEEL_SENSITIVITY + 1) * Pi::GetMoveSpeedShiftModifier();
|
2012-01-19 18:43:29 -08:00
|
|
|
}
|
2010-03-13 10:33:15 -08:00
|
|
|
}
|
2014-08-07 00:36:04 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::RefreshShips(void)
|
|
|
|
{
|
2014-08-07 00:36:04 -07:00
|
|
|
m_contacts.clear();
|
2019-01-02 08:59:07 -08:00
|
|
|
if (!m_game->GetSpace()->GetStarSystem()->GetPath().IsSameSystem(m_game->GetSectorView()->GetSelected()))
|
2014-08-08 02:42:28 -07:00
|
|
|
return;
|
|
|
|
|
2014-09-15 11:12:15 -07:00
|
|
|
auto bs = m_game->GetSpace()->GetBodies();
|
2019-01-02 08:59:07 -08:00
|
|
|
for (auto s = bs.begin(); s != bs.end(); s++) {
|
|
|
|
if ((*s) != Pi::player &&
|
|
|
|
(*s)->GetType() == Object::SHIP) {
|
2014-08-07 00:36:04 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
const auto c = static_cast<Ship *>(*s);
|
2014-08-07 00:36:04 -07:00
|
|
|
m_contacts.push_back(std::make_pair(c, c->ComputeOrbit()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void SystemView::DrawShips(const double t, const vector3d &offset)
|
|
|
|
{
|
2014-08-07 03:04:46 -07:00
|
|
|
m_shipLabels->Clear();
|
2019-01-02 08:59:07 -08:00
|
|
|
for (auto s = m_contacts.begin(); s != m_contacts.end(); s++) {
|
2018-06-19 04:49:23 -07:00
|
|
|
vector3d pos = offset;
|
|
|
|
if ((*s).first->GetFlightState() != Ship::FlightState::FLYING) {
|
|
|
|
Frame *frame = Pi::game->GetSpace()->GetRootFrame();
|
2019-01-02 08:59:07 -08:00
|
|
|
pos += (*s).first->GetPositionRelTo(frame) * double(m_zoom);
|
|
|
|
;
|
2018-06-19 04:49:23 -07:00
|
|
|
} else {
|
|
|
|
Frame *frame = (*s).first->GetFrame();
|
|
|
|
vector3d bpos = vector3d(0., 0., 0.);
|
|
|
|
if (frame != Pi::game->GetSpace()->GetRootFrame())
|
2019-01-02 08:59:07 -08:00
|
|
|
bpos += frame->GetPositionRelTo(Pi::game->GetSpace()->GetRootFrame());
|
2018-06-19 04:49:23 -07:00
|
|
|
pos += (bpos + (*s).second.OrbitalPosAtTime(t)) * double(m_zoom);
|
|
|
|
}
|
2014-08-07 12:53:11 -07:00
|
|
|
const bool isNavTarget = Pi::player->GetNavTarget() == (*s).first;
|
|
|
|
PutSelectionBox(pos, isNavTarget ? Color::GREEN : Color::BLUE);
|
2014-08-07 03:04:46 -07:00
|
|
|
LabelShip((*s).first, pos);
|
2019-01-02 08:59:07 -08:00
|
|
|
if (m_shipDrawing == ORBITS && (*s).first->GetFlightState() == Ship::FlightState::FLYING)
|
2014-08-07 12:53:11 -07:00
|
|
|
PutOrbit(&(*s).second, offset, isNavTarget ? Color::GREEN : Color::BLUE, 0);
|
2014-08-07 00:36:04 -07:00
|
|
|
}
|
|
|
|
}
|