2014-01-01 19:43:38 -08:00
|
|
|
// Copyright © 2008-2014 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"
|
|
|
|
#include "Pi.h"
|
|
|
|
#include "SectorView.h"
|
2012-04-04 18:53:58 -07:00
|
|
|
#include "galaxy/StarSystem.h"
|
2011-07-27 03:46:56 -07:00
|
|
|
#include "Lang.h"
|
2011-08-23 20:18:53 -07:00
|
|
|
#include "StringF.h"
|
2011-09-14 13:13:53 -07:00
|
|
|
#include "Space.h"
|
|
|
|
#include "Player.h"
|
2011-09-22 14:49:13 -07:00
|
|
|
#include "FloatComparison.h"
|
2011-11-19 02:33:36 -08:00
|
|
|
#include "Game.h"
|
2012-09-09 13:30:11 -07:00
|
|
|
#include "AnimationCurves.h"
|
2012-02-21 02:04:06 -08:00
|
|
|
#include "graphics/Material.h"
|
|
|
|
#include "graphics/Renderer.h"
|
|
|
|
|
|
|
|
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;
|
2012-04-10 09:06:48 -07:00
|
|
|
static const float MIN_ZOOM = 1e-30f; // Just to avoid having 0
|
|
|
|
static const float MAX_ZOOM = 1e30f;
|
|
|
|
static const float ZOOM_IN_SPEED = 2;
|
|
|
|
static const float ZOOM_OUT_SPEED = 1.f/ZOOM_IN_SPEED;
|
2013-09-24 00:50:41 -07:00
|
|
|
static const float WHEEL_SENSITIVITY = .1f; // Should be a variable in user settings.
|
2013-06-26 18:07:40 -07:00
|
|
|
// i don't know how to name it
|
|
|
|
static const double ROUGH_SIZE_OF_TURD = 10.0;
|
2011-10-18 13:19:29 -07:00
|
|
|
|
2011-02-10 18:03:27 -08:00
|
|
|
SystemView::SystemView()
|
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;
|
|
|
|
|
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);
|
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);
|
2008-11-24 13:06:00 -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_zoomInButton = new Gui::ImageButton("icons/zoom_in.png");
|
2011-07-27 03:46:56 -07:00
|
|
|
m_zoomInButton->SetToolTip(Lang::ZOOM_IN);
|
2012-09-02 08:30:57 -07:00
|
|
|
m_zoomInButton->SetRenderDimensions(30, 22);
|
2009-10-20 09:47:54 -07:00
|
|
|
Add(m_zoomInButton, 700, 5);
|
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);
|
2009-10-20 09:47:54 -07:00
|
|
|
Add(m_zoomOutButton, 732, 5);
|
2008-06-24 03:17:31 -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");
|
2012-03-31 01:44:53 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), -1000000.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");
|
2012-03-31 01:44:53 -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 + 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");
|
2012-03-31 01:44:53 -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 + 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");
|
2012-03-31 01:44:53 -07:00
|
|
|
b->onPress.connect(sigc::bind(sigc::mem_fun(this, &SystemView::OnClickAccel), 1000000.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 =
|
|
|
|
Pi::onMouseWheel.connect(sigc::mem_fun(this, &SystemView::MouseWheel));
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2008-06-24 03:17:31 -07:00
|
|
|
ResetViewpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemView::~SystemView()
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
2012-04-02 17:13:51 -07: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;
|
2011-11-21 13:33:03 -08:00
|
|
|
m_time = Pi::game->GetTime();
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
void SystemView::PutOrbit(const Orbit *orbit, const vector3d &offset, const Color &color, double planetRadius)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
2013-03-29 07:59:05 -07:00
|
|
|
int num_vertices = 0;
|
2012-07-22 07:33:35 -07:00
|
|
|
vector3f vts[100];
|
2012-07-22 09:17:18 -07:00
|
|
|
for (int i = 0; i < int(COUNTOF(vts)); ++i) {
|
2012-07-22 07:33:35 -07:00
|
|
|
const double t = double(i) / double(COUNTOF(vts));
|
2013-03-29 07:59:05 -07:00
|
|
|
const vector3d pos = orbit->EvenSpacedPosTrajectory(t);
|
|
|
|
vts[i] = vector3f(offset + pos * double(m_zoom));
|
|
|
|
++num_vertices;
|
|
|
|
if (pos.Length() < planetRadius)
|
|
|
|
break;
|
|
|
|
}
|
2013-02-14 06:37:54 -08:00
|
|
|
|
2013-03-29 07:59:05 -07:00
|
|
|
if (num_vertices > 1) {
|
|
|
|
// don't close the loop for hyperbolas and parabolas and crashed ellipses
|
2013-03-29 09:10:03 -07:00
|
|
|
if ((orbit->GetEccentricity() > 1.0) || (num_vertices < int(COUNTOF(vts))))
|
2014-01-30 18:22:52 -08:00
|
|
|
m_renderer->DrawLines(num_vertices, vts, color, m_lineState, LINE_STRIP);
|
2013-03-29 09:10:03 -07:00
|
|
|
else
|
2014-01-30 18:22:52 -08:00
|
|
|
m_renderer->DrawLines(num_vertices, vts, color, m_lineState, LINE_LOOP);
|
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";
|
2009-10-18 09:12:51 -07:00
|
|
|
data += b->name+"\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";
|
2011-08-23 20:18:53 -07:00
|
|
|
data += stringf(Lang::N_DAYS, formatarg("days", b->rotationPeriod.ToFloat())) + "\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";
|
2009-10-18 09:12:51 -07:00
|
|
|
data += format_distance(b->GetRadius())+"\n";
|
|
|
|
|
|
|
|
if (b->parent) {
|
2011-07-27 03:46:56 -07:00
|
|
|
desc += std::string(Lang::SEMI_MAJOR_AXIS);
|
2011-09-14 13:13:53 -07:00
|
|
|
desc += ":\n";
|
2013-03-29 09:10:03 -07:00
|
|
|
data += format_distance(b->orbit.GetSemiMajorAxis())+"\n";
|
2009-10-18 09:12:51 -07:00
|
|
|
|
2011-07-27 03:46:56 -07:00
|
|
|
desc += std::string(Lang::ORBITAL_PERIOD);
|
2011-09-14 13:13:53 -07:00
|
|
|
desc += ":\n";
|
2013-02-14 06:37:54 -08:00
|
|
|
data += stringf(Lang::N_DAYS, formatarg("days", b->orbit.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
|
|
|
|
|
|
|
if (Pi::KeyState(SDLK_LSHIFT) || Pi::KeyState(SDLK_RSHIFT)) {
|
|
|
|
SystemPath path = m_system->GetPathOf(b);
|
2011-11-19 02:33:36 -08:00
|
|
|
if (Pi::game->GetSpace()->GetStarSystem()->GetPath() == m_system->GetPath()) {
|
|
|
|
Body* body = Pi::game->GetSpace()->FindBodyForPath(&path);
|
2011-09-14 13:13:53 -07:00
|
|
|
if (body != 0)
|
|
|
|
Pi::player->SetNavTarget(body);
|
|
|
|
}
|
|
|
|
}
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
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
|
2011-02-20 13:01:37 -08:00
|
|
|
m_objectLabels->Add(b->name, sigc::bind(sigc::mem_fun(this, &SystemView::OnClickObject), b), pos.x, pos.y);
|
2008-06-24 03:17:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::Screen::LeaveOrtho();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-04-17 18:53:53 -07:00
|
|
|
if (b->type == SystemBody::TYPE_STARPORT_SURFACE) return;
|
|
|
|
if (b->type != SystemBody::TYPE_GRAVPOINT) {
|
2012-08-04 15:07:05 -07:00
|
|
|
|
2013-10-29 04:44:49 -07:00
|
|
|
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();
|
|
|
|
invRot = invRot.InverseOf();
|
|
|
|
|
|
|
|
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();
|
|
|
|
if(frame->IsRotFrame()) frame = frame->GetNonRotFrame();
|
|
|
|
if(frame->GetSystemBody() == b && frame->GetSystemBody()->GetMass() > 0) {
|
2013-03-29 09:30:29 -07:00
|
|
|
const double t0 = Pi::game->GetTime();
|
2013-03-29 07:59:47 -07:00
|
|
|
Orbit playerOrbit = Pi::player->ComputeOrbit();
|
2013-12-09 12:37:02 -08:00
|
|
|
PutOrbit(&playerOrbit, offset, Color::RED, b->GetRadius());
|
|
|
|
PutSelectionBox(offset + playerOrbit.OrbitalPosAtTime(m_time - t0)* double(m_zoom), Color::RED);
|
2013-02-14 06:37:54 -08:00
|
|
|
}
|
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
if (b->children.size()) {
|
|
|
|
for(std::vector<SystemBody*>::const_iterator kid = b->children.begin(); kid != b->children.end(); ++kid) {
|
2013-03-29 09:10:03 -07:00
|
|
|
if (is_zero_general((*kid)->orbit.GetSemiMajorAxis())) continue;
|
|
|
|
if ((*kid)->orbit.GetSemiMajorAxis() * m_zoom < ROUGH_SIZE_OF_TURD) {
|
2013-12-09 12:37:02 -08:00
|
|
|
PutOrbit(&((*kid)->orbit), offset, Color(0, 255, 0, 255));
|
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
|
|
|
|
vector3d pos = (*kid)->orbit.OrbitalPosAtTime(m_time);
|
|
|
|
pos *= double(m_zoom);
|
2011-08-18 19:10:15 -07:00
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
PutBody(*kid, offset + pos, trans);
|
|
|
|
}
|
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
|
2012-04-17 18:53:53 -07:00
|
|
|
if (b->type == SystemBody::TYPE_STARPORT_SURFACE)
|
2011-10-18 13:19:29 -07:00
|
|
|
b = b->parent;
|
|
|
|
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)
|
2011-10-18 13:19:29 -07:00
|
|
|
while (b->parent) {
|
|
|
|
pos += b->orbit.OrbitalPosAtTime(m_time) * double(m_zoom);
|
|
|
|
b = b->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-04-01 13:27:00 -07: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)
|
2012-02-13 07:37:51 -08:00
|
|
|
};
|
2014-01-30 18:22:52 -08:00
|
|
|
m_renderer->DrawLines(4, &verts[0], col, m_lineState, Graphics::LINE_LOOP);
|
2011-10-18 13:19:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::Screen::LeaveOrtho();
|
|
|
|
}
|
|
|
|
|
2012-03-31 01:44:53 -07:00
|
|
|
static const GLfloat fogDensity = 0.1f;
|
|
|
|
static const GLfloat fogColor[4] = { 0,0,0,1.0f };
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2013-03-29 07:59:47 -07:00
|
|
|
void SystemView::GetTransformTo(const SystemBody *b, vector3d &pos)
|
2008-06-24 03:17:31 -07:00
|
|
|
{
|
|
|
|
if (b->parent) {
|
2009-05-04 05:02:58 -07:00
|
|
|
GetTransformTo(b->parent, pos);
|
2011-05-10 17:57:37 -07:00
|
|
|
pos -= double(m_zoom) * b->orbit.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-02-02 08:15:57 -08:00
|
|
|
SystemPath path = Pi::sectorView->GetSelected().SystemOnly();
|
2008-06-24 03:17:31 -07:00
|
|
|
if (m_system) {
|
2011-06-27 05:31:49 -07:00
|
|
|
if (!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) {
|
|
|
|
m_time = Pi::game->GetTime();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_time += m_timeStep*Pi::GetFrameTime();
|
|
|
|
}
|
2011-07-27 03:46:56 -07:00
|
|
|
std::string t = Lang::TIME_POINT+format_date(m_time);
|
2008-06-24 03:17:31 -07:00
|
|
|
m_timePoint->SetText(t);
|
|
|
|
|
2011-06-27 05:31:49 -07:00
|
|
|
if (!m_system) m_system = StarSystem::GetCached(path);
|
2008-06-24 03:17:31 -07:00
|
|
|
|
2012-02-14 07:25:40 -08:00
|
|
|
matrix4x4f trans = matrix4x4f::Identity();
|
|
|
|
trans.Translate(0,0,-ROUGH_SIZE_OF_TURD);
|
|
|
|
trans.Rotate(DEG2RAD(m_rot_x), 1, 0, 0);
|
|
|
|
trans.Rotate(DEG2RAD(m_rot_z), 0, 0, 1);
|
|
|
|
m_renderer->SetTransform(trans);
|
2012-07-04 12:13:48 -07:00
|
|
|
|
2009-05-04 05:02:58 -07:00
|
|
|
vector3d pos(0,0,0);
|
|
|
|
if (m_selectedObject) GetTransformTo(m_selectedObject, pos);
|
2008-06-24 03:17:31 -07:00
|
|
|
|
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);
|
2011-10-18 13:19:29 -07:00
|
|
|
else if (m_system->rootBody) {
|
2013-02-04 13:35:20 -08:00
|
|
|
PutBody(m_system->rootBody.Get(), pos, trans);
|
2011-11-19 02:33:36 -08:00
|
|
|
if (Pi::game->GetSpace()->GetStarSystem() == m_system) {
|
2011-10-18 13:19:29 -07:00
|
|
|
const Body *navTarget = Pi::player->GetNavTarget();
|
2012-04-17 18:53:53 -07:00
|
|
|
const SystemBody *navTargetSystemBody = navTarget ? navTarget->GetSystemBody() : 0;
|
|
|
|
if (navTargetSystemBody)
|
2013-12-09 12:37:02 -08:00
|
|
|
PutSelectionBox(navTargetSystemBody, pos, Color::GREEN);
|
2011-10-18 13:19:29 -07:00
|
|
|
}
|
|
|
|
}
|
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()) {
|
|
|
|
if (Pi::KeyState(SDLK_EQUALS) ||
|
2012-12-22 14:26:30 -08:00
|
|
|
m_zoomInButton->IsPressed())
|
2012-04-10 09:06:48 -07:00
|
|
|
m_zoomTo *= pow(ZOOM_IN_SPEED * Pi::GetMoveSpeedShiftModifier(), ft);
|
2011-09-18 15:18:02 -07:00
|
|
|
if (Pi::KeyState(SDLK_MINUS) ||
|
2012-12-22 14:26:30 -08:00
|
|
|
m_zoomOutButton->IsPressed())
|
2012-04-10 09:06:48 -07:00
|
|
|
m_zoomTo *= pow(ZOOM_OUT_SPEED / Pi::GetMoveSpeedShiftModifier(), ft);
|
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);
|
2012-09-09 13:30:11 -07:00
|
|
|
AnimationCurves::Approach(m_zoom, m_zoomTo, ft);
|
2012-04-10 09:06:48 -07:00
|
|
|
|
2010-03-13 10:33:15 -08:00
|
|
|
if (Pi::MouseButtonState(SDL_BUTTON_RIGHT)) {
|
2008-06-24 03:17:31 -07:00
|
|
|
int motion[2];
|
|
|
|
Pi::GetMouseMotion(motion);
|
2008-06-28 13:00:50 -07:00
|
|
|
m_rot_x += motion[1]*20*ft;
|
|
|
|
m_rot_z += motion[0]*20*ft;
|
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)
|
2012-04-10 09:06:48 -07:00
|
|
|
m_zoomTo *= ((ZOOM_OUT_SPEED-1) * WHEEL_SENSITIVITY+1) / Pi::GetMoveSpeedShiftModifier();
|
2013-09-24 00:50:41 -07:00
|
|
|
else
|
2012-04-10 09:06:48 -07: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
|
|
|
}
|