Draw space background in SystemView

- Steal the current space's background object; ideally SystemView should have its own copy it generates for systems
- Don't draw stars sourced from the current system's position when looking at other systems
- The background system in general doesn't respect the plane of the ecliptic vs the galactic plane.
  This is a problem that affects WorldView as well as the SystemView
master
Webster Sheets 2020-12-10 17:56:22 -05:00 committed by Webster Sheets
parent 365476dfe3
commit 013721f405
2 changed files with 27 additions and 4 deletions

View File

@ -108,6 +108,7 @@ namespace Background {
void SetIntensity(float intensity);
void SetDrawFlags(const Uint32 flags);
Uint32 GetDrawFlags() const { return m_drawFlags; }
private:
Graphics::Renderer *m_renderer;

View File

@ -7,6 +7,7 @@
#include "SystemView.h"
#include "AnimationCurves.h"
#include "Background.h"
#include "Game.h"
#include "GameLog.h"
#include "Input.h"
@ -319,12 +320,8 @@ void SystemView::CalculateFramePositionAtTime(FrameId frameId, double t, vector3
void SystemView::Draw3D()
{
PROFILE_SCOPED()
// We need to adjust the "far" cutoff plane, so that at high magnifications you can see
// distant objects in the background.
m_renderer->SetPerspectiveProjection(CAMERA_FOV, m_renderer->GetDisplayAspect(), 1.f, 1000.f * m_zoom * float(AU) + DEFAULT_VIEW_DISTANCE * 2);
m_renderer->ClearScreen();
m_projected.clear();
//TODO add reserve
SystemPath path = m_game->GetSectorView()->GetSelected().SystemOnly();
if (m_system) {
@ -346,6 +343,31 @@ void SystemView::Draw3D()
m_unexplored = m_system->GetUnexplored();
}
// Set up the perspective projection for the background stars
m_renderer->SetPerspectiveProjection(CAMERA_FOV, m_renderer->GetDisplayAspect(), 1.f, 1500.f);
matrix4x4d trans2bg = matrix4x4d::Identity();
trans2bg.RotateX(DEG2RAD(-m_rot_x));
trans2bg.RotateY(DEG2RAD(-m_rot_y));
auto *background = m_game->GetSpace()->GetBackground();
// Background is rotated around (0,0,0) and drawn
background->SetIntensity(0.6);
if (!m_game->GetSpace()->GetStarSystem()->GetPath().IsSameSystem(path)) {
Uint32 cachedFlags = background->GetDrawFlags();
background->SetDrawFlags(Background::Container::DRAW_SKYBOX);
background->Draw(trans2bg);
background->SetDrawFlags(cachedFlags);
} else {
background->Draw(trans2bg);
}
m_renderer->ClearDepthBuffer();
// We need to adjust the "far" cutoff plane, so that at high magnifications you can see
// distant objects in the background.
m_renderer->SetPerspectiveProjection(CAMERA_FOV, m_renderer->GetDisplayAspect(), 1.f, 1000.f * m_zoom * float(AU) + DEFAULT_VIEW_DISTANCE * 2);
//TODO add reserve
// The matrix is shifted from the (0,0,0) by DEFAULT_VIEW_DISTANCE
// and then rotated (around 0,0,0) and scaled by m_zoom, shift doesn't scale.
// m_zoom default value is 1/AU.