Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
starsystemview.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <map>
20#include <string>
21#include <vector>
22
24#include "common/universe.h"
25#include "engine/application.h"
30#include "entt/entt.hpp"
31#include "glm/glm.hpp"
32
33namespace cqsp::client::systems {
34
35// TODO(EhWhoAmI): Would be helpful to move the following structs to a header file.
37
38// Planet that the camera center is at
39struct FocusedPlanet {};
40// City to look at
41struct FocusedCity {};
42
43struct CityFounding {};
44
45/*
46 * Main renderer for the universe
47 */
49 public:
51 void Initialize();
52 void OnTick();
53 void Render(float deltaTime);
54 void SeeStarSystem();
55 void SeeEntity();
56 void Update(float deltaTime);
57 void SeePlanet(entt::entity);
58 void DoUI(float deltaTime);
59
60 glm::vec3 GetMouseIntersectionOnObject(int mouse_x, int mouse_y);
61
62 // The angle the camera is looking from
63 float view_x = 0;
64 // The angle the camera is looking away from
65 float view_y = 0;
66
69
70 double scroll = 10;
71 double min_zoom = 1;
72 // Light year sized
73 double max_zoom = 9.4605284e15;
74
75 glm::vec3 view_center;
76
77 double GetDivider() { return divider; }
78
79 entt::entity GetMouseOnObject(int mouse_x, int mouse_y);
80
82
83 void DrawAllOrbits();
84 void DrawOrbit(const entt::entity &entity);
85
86 void OrbitEditor();
87
89
90 private:
91 entt::entity m_viewing_entity = entt::null;
92 entt::entity terrain_displaying = entt::null;
93
96
104
115#if FALSE
116 // Disabled for now
117 asset::ShaderProgram_t no_light_shader;
118#endif
119
120 glm::vec3 cam_pos;
121 glm::vec3 cam_up = glm::vec3(0.0f, 1.0f, 0.0f);
122 glm::mat4 camera_matrix;
123 glm::mat4 projection;
124 glm::vec4 viewport;
125
126 float circle_size = 0.01f;
127
128 void DrawStars();
129 void DrawBodies();
130 void DrawShips();
131 void DrawSkybox();
132 void DrawModels();
133
134 void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id);
135 void DrawPlanetIcon(glm::vec3 &object_pos);
136 void DrawPlanetBillboards(const entt::entity &ent_id, const glm::vec3 &object_pos);
137 void DrawShipIcon(const glm::vec3 &object_pos);
138 void DrawCityIcon(const glm::vec3 &object_pos);
139
140 void DrawAllCities(auto &bodies);
141
142 void DrawAllPlanets(auto &bodies);
144
145 void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity);
146 void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province);
147 void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos);
148
149 void DrawStar(const entt::entity &entity, glm::vec3 &object_pos);
150 void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity);
151 bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos);
153 void CalculateScroll();
154
155 asset::ShaderProgram_t ConstructShader(const std::string &key);
156
157 void LoadPlanetTextures();
159 void LoadProvinceMap();
160 void InitializeMeshes();
161
162 void GenerateOrbit(entt::entity body);
163
170 glm::quat GetBodyRotation(double axial, double rotation, double day_offset);
171 void FocusCityView();
172
173 glm::vec3 CalculateObjectPos(const entt::entity &);
174 glm::vec3 CalculateCenteredObject(const entt::entity &);
175 glm::vec3 CalculateCenteredObject(const glm::vec3 &);
176 glm::vec3 TranslateToNormalized(const glm::vec3 &);
177 glm::vec3 ConvertPoint(const glm::vec3 &);
178
182 glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos);
186 bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos);
187 glm::mat4 GetBillboardMatrix(const glm::vec3 &pos);
188 glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos);
189 void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat);
190 void CenterCameraOnCity();
191
192 void CalculateCamera();
193 void MoveCamera(double deltaTime);
194
196
197 glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds);
198
199 void CalculateViewChange(double deltaX, double deltaY);
200 void FoundCity();
201 void SelectCountry();
202 void FocusOnEntity(entt::entity ent);
203
204 float GetWindowRatio();
205
206 void GenerateOrbitLines();
207
208 void RenderInformationWindow(double deltaTime);
210
211 // How much to scale the the star system.
212 const double divider = 0.01;
214
215 glm::vec3 sun_position;
216 glm::vec3 sun_color;
217
219
224
225 bool is_founding_city = false;
228 // Gets the intersection in 3d point between the mouse and any planet
229 glm::vec3 GetMouseOnObject() { return mouse_on_object; }
230 entt::entity on_planet;
231
232 float view_scale = 10.f;
233
234 entt::entity selected_city = entt::null;
235
239 int tex_x;
240 int tex_y;
241
245 int tex_r;
246 int tex_g;
247 int tex_b;
248
250 void CityDetection();
251
254 entt::entity hovering_province;
255 entt::entity selected_province;
256
258
259 const int sphere_resolution = 64;
260
261 bool have_province = false;
262};
263} // namespace cqsp::client::systems
Definition: starsystemview.h:48
entt::entity terrain_displaying
Definition: starsystemview.h:92
entt::entity on_planet
Definition: starsystemview.h:230
glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos)
Calculates the GL position for a log renderbuffer.
Definition: starsystemview.cpp:833
void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity)
Definition: starsystemview.cpp:453
glm::vec4 viewport
Definition: starsystemview.h:124
void FocusOnEntity(entt::entity ent)
Definition: starsystemview.cpp:1031
int ship_icon_layer
Definition: starsystemview.h:220
engine::Renderable sun
Definition: starsystemview.h:103
void SeeStarSystem()
Definition: starsystemview.cpp:186
asset::ShaderProgram_t sun_shader
Definition: starsystemview.h:112
void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province)
Definition: starsystemview.cpp:497
void DrawAllOrbits()
Definition: starsystemview.cpp:1318
int tex_r
Debugging colors
Definition: starsystemview.h:245
asset::ShaderProgram_t model_shader
Definition: starsystemview.h:105
void GenerateOrbitLines()
Definition: starsystemview.cpp:1054
bool is_rendering_founding_city
Definition: starsystemview.h:226
engine::Renderable ship_overlay
Definition: starsystemview.h:101
void DrawOrbit(const entt::entity &entity)
Definition: starsystemview.cpp:1334
void DrawShipIcon(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:437
engine::Application & m_app
Definition: starsystemview.h:95
void SelectCountry()
Definition: starsystemview.cpp:1010
glm::vec3 hovering_province_color
Definition: starsystemview.h:252
asset::ShaderProgram_t orbit_shader
Definition: starsystemview.h:106
void DrawAllCities(auto &bodies)
Definition: starsystemview.cpp:428
glm::vec3 GetMouseIntersectionOnObject(int mouse_x, int mouse_y)
Definition: starsystemview.cpp:1203
void InitializeMeshes()
Definition: starsystemview.cpp:746
double scroll
Definition: starsystemview.h:70
void CalculateCityPositions()
Definition: starsystemview.cpp:642
float circle_size
Definition: starsystemview.h:126
asset::ShaderProgram_t near_shader
Definition: starsystemview.h:107
glm::vec3 GetMouseOnObject()
Definition: starsystemview.h:229
double GetDivider()
Definition: starsystemview.h:77
engine::Renderable planet
Definition: starsystemview.h:97
int tex_y
Definition: starsystemview.h:240
void OnTick()
Definition: starsystemview.cpp:134
glm::vec3 TranslateToNormalized(const glm::vec3 &)
Definition: starsystemview.cpp:827
void Update(float deltaTime)
Definition: starsystemview.cpp:212
void FoundCity()
Definition: starsystemview.cpp:992
void Initialize()
Definition: starsystemview.cpp:119
void Render(float deltaTime)
Definition: starsystemview.cpp:141
void DrawCityIcon(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:412
float window_ratio
Definition: starsystemview.h:213
int tex_b
Definition: starsystemview.h:247
void OrbitEditor()
Definition: starsystemview.cpp:1378
bool have_province
Definition: starsystemview.h:261
glm::mat4 GetBillboardMatrix(const glm::vec3 &pos)
Definition: starsystemview.cpp:848
entt::entity selected_city
Definition: starsystemview.h:234
glm::quat GetBodyRotation(double axial, double rotation, double day_offset)
Gets the quaternion to calculate the planet's rotation from the axial rotation and the rotation perio...
Definition: starsystemview.cpp:787
void LoadProvinceMap()
Definition: starsystemview.cpp:744
glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:856
entt::entity selected_province
Definition: starsystemview.h:255
double max_zoom
Definition: starsystemview.h:73
void RenderInformationWindow(double deltaTime)
Definition: starsystemview.cpp:1073
bool is_founding_city
Definition: starsystemview.h:225
int skybox_layer
Definition: starsystemview.h:223
void RenderSelectedObjectInformation()
Definition: starsystemview.cpp:1117
asset::ShaderProgram_t skybox_shader
Definition: starsystemview.h:113
engine::Renderable planet_circle
Definition: starsystemview.h:100
void FocusCityView()
Definition: starsystemview.cpp:798
void DrawShips()
Definition: starsystemview.cpp:314
glm::vec3 view_center
Definition: starsystemview.h:75
static bool IsFoundingCity(common::Universe &universe)
Definition: starsystemview.cpp:1314
glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds)
Definition: starsystemview.cpp:966
double previous_mouseX
Definition: starsystemview.h:67
void DrawModels()
Definition: starsystemview.cpp:351
void MoveCamera(double deltaTime)
Definition: starsystemview.cpp:908
void DrawStars()
Definition: starsystemview.cpp:277
void DrawPlanetBillboards(const entt::entity &ent_id, const glm::vec3 &object_pos)
Definition: starsystemview.cpp:393
bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos)
Definition: starsystemview.cpp:637
void InitializeFramebuffers()
Definition: starsystemview.cpp:735
glm::vec3 cam_pos
Definition: starsystemview.h:120
asset::ShaderProgram_t circle_shader
Definition: starsystemview.h:109
void CheckResourceDistRender()
Definition: starsystemview.cpp:939
glm::vec3 selected_province_color
Definition: starsystemview.h:253
float GetWindowRatio()
Definition: starsystemview.cpp:1052
glm::vec3 sun_color
Definition: starsystemview.h:216
float view_scale
Definition: starsystemview.h:232
glm::mat4 camera_matrix
Definition: starsystemview.h:122
void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat)
Definition: starsystemview.cpp:860
void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id)
Definition: starsystemview.cpp:376
glm::vec3 CalculateObjectPos(const entt::entity &)
Definition: starsystemview.cpp:815
int tex_x
Debugging mouse position
Definition: starsystemview.h:239
void DrawAllPlanetBillboards(auto &bodies)
Definition: starsystemview.cpp:546
asset::ShaderProgram_t textured_planet_shader
Definition: starsystemview.h:111
engine::Renderable sky
Definition: starsystemview.h:99
double previous_mouseY
Definition: starsystemview.h:68
float view_y
Definition: starsystemview.h:65
asset::ShaderProgram_t buffer_shader
Definition: starsystemview.h:114
engine::LayerRenderer renderer
Definition: starsystemview.h:218
void DrawSkybox()
Definition: starsystemview.cpp:337
glm::vec3 ConvertPoint(const glm::vec3 &)
Definition: starsystemview.cpp:831
glm::mat4 projection
Definition: starsystemview.h:123
glm::vec3 cam_up
Definition: starsystemview.h:121
entt::entity hovering_province
Definition: starsystemview.h:254
asset::ShaderProgram_t ConstructShader(const std::string &key)
Definition: starsystemview.cpp:731
void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity)
Definition: starsystemview.cpp:596
entt::entity m_viewing_entity
Definition: starsystemview.h:91
int orbits_generated
Definition: starsystemview.h:257
common::Universe & m_universe
Definition: starsystemview.h:94
engine::Renderable textured_planet
Definition: starsystemview.h:98
void CalculateCamera()
Definition: starsystemview.cpp:900
void CalculateScroll()
Definition: starsystemview.cpp:665
asset::ShaderProgram_t planet_shader
Definition: starsystemview.h:110
void DrawBodies()
Definition: starsystemview.cpp:291
void SeePlanet(entt::entity)
Definition: starsystemview.cpp:264
void DrawPlanetIcon(glm::vec3 &object_pos)
Definition: starsystemview.cpp:386
void DrawStar(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemview.cpp:563
float view_x
Definition: starsystemview.h:63
const int sphere_resolution
Definition: starsystemview.h:259
SysStarSystemRenderer(common::Universe &, engine::Application &)
Definition: starsystemview.cpp:80
int physical_layer
Definition: starsystemview.h:222
engine::Renderable city
Definition: starsystemview.h:102
glm::vec3 sun_position
Definition: starsystemview.h:215
glm::vec3 CalculateCenteredObject(const entt::entity &)
Definition: starsystemview.cpp:896
void SeeEntity()
Definition: starsystemview.cpp:198
const double divider
Definition: starsystemview.h:212
double min_zoom
Definition: starsystemview.h:71
void DoUI(float deltaTime)
Definition: starsystemview.cpp:269
void GenerateOrbit(entt::entity body)
Definition: starsystemview.cpp:1233
void LoadPlanetTextures()
Definition: starsystemview.cpp:677
bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos)
Check if the GL position is within the window
Definition: starsystemview.cpp:843
asset::ShaderProgram_t vis_shader
Definition: starsystemview.h:108
void CenterCameraOnCity()
Definition: starsystemview.cpp:866
void DrawAllPlanets(auto &bodies)
Definition: starsystemview.cpp:524
void CityDetection()
Definition: starsystemview.cpp:1166
glm::vec3 mouse_on_object
Definition: starsystemview.h:227
int tex_g
Definition: starsystemview.h:246
void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemview.cpp:579
int planet_icon_layer
Definition: starsystemview.h:221
void CalculateViewChange(double deltaX, double deltaY)
Definition: starsystemview.cpp:976
common::components::types::SurfaceCoordinate GetMouseSurfaceIntersection()
Definition: starsystemview.cpp:1145
Definition: universe.h:33
Definition: application.h:48
Renders a series of framebuffers onto screen. This is a relatively simple way of allowing organizatio...
Definition: framebuffer.h:132
Definition: renderable.h:27
std::shared_ptr< ShaderProgram > ShaderProgram_t
The preferred way of using a shader program.
Definition: shader.h:113
Definition: goodviewer.cpp:25
Definition: bodies.h:29
Definition: starsystemview.h:43
Definition: starsystemview.h:41
Definition: starsystemview.h:39
Definition: starsystemview.h:36
Longitude and lattitude. Planet coordinates.
Definition: coordinates.h:76
common::Universe * universe
Definition: turnsavewindow.h:3