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-2023 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 {
34namespace client {
35namespace systems {
36// TODO(EhWhoAmI): Would be helpful to move the following structs to a header file.
38
39// Planet that the camera center is at
40struct FocusedPlanet {};
41// City to look at
42struct FocusedCity {};
43
44struct CityFounding {};
45
46/*
47 * Main renderer for the universe
48 */
50 public:
52 void Initialize();
53 void OnTick();
54 void Render(float deltaTime);
55 void SeeStarSystem();
56 void SeeEntity();
57 void Update(float deltaTime);
58 void SeePlanet(entt::entity);
59 void DoUI(float deltaTime);
60
61 glm::vec3 GetMouseIntersectionOnObject(int mouse_x, int mouse_y);
62
63 // The angle the camera is looking from
64 float view_x = 0;
65 // The angle the camera is looking away from
66 float view_y = 0;
67
70
71 double scroll = 10;
72 double min_zoom = 1;
73 // Light year sized
74 double max_zoom = 9.4605284e15;
75
76 glm::vec3 view_center;
77
78 double GetDivider() { return divider; }
79
80 entt::entity GetMouseOnObject(int mouse_x, int mouse_y);
81
83
84 void DrawAllOrbits();
85 void DrawOrbit(const entt::entity &entity);
86
87 void OrbitEditor();
88
90
91 private:
92 entt::entity m_viewing_entity = entt::null;
93 entt::entity terrain_displaying = entt::null;
94
97
105
110#if FALSE
111 // Disabled for now
112 asset::ShaderProgram_t no_light_shader;
113#endif
114
115 glm::vec3 cam_pos;
116 glm::vec3 cam_up = glm::vec3(0.0f, 1.0f, 0.0f);
117 glm::mat4 camera_matrix;
118 glm::mat4 projection;
119 glm::vec4 viewport;
120
121 float circle_size = 0.01f;
122
123 void DrawStars();
124 void DrawBodies();
125 void DrawShips();
126 void DrawSkybox();
127 void DrawModels();
128
129 void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id);
130 void DrawPlanetIcon(glm::vec3 &object_pos);
131 void DrawPlanetBillboards(const entt::entity &ent_id, const glm::vec3 &object_pos);
132 void DrawShipIcon(const glm::vec3 &object_pos);
133 void DrawCityIcon(const glm::vec3 &object_pos);
134
135 void DrawAllCities(auto &bodies);
136
137 void DrawAllPlanets(auto &bodies);
138 void DrawAllPlanetBillboards(auto &bodies);
139
140 void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity);
141 void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province);
142 void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos);
143
144 void DrawStar(const entt::entity &entity, glm::vec3 &object_pos);
145 void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity);
146 bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos);
148 void CalculateScroll();
149
150 void LoadPlanetTextures();
152 void LoadProvinceMap();
153 void InitializeMeshes();
154
155 void GenerateOrbit(entt::entity body);
156
163 glm::quat GetBodyRotation(double axial, double rotation, double day_offset);
164 void FocusCityView();
165
166 glm::vec3 CalculateObjectPos(const entt::entity &);
167 glm::vec3 CalculateCenteredObject(const entt::entity &);
168 glm::vec3 CalculateCenteredObject(const glm::vec3 &);
169 glm::vec3 TranslateToNormalized(const glm::vec3 &);
170 glm::vec3 ConvertPoint(const glm::vec3 &);
171
175 glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos);
179 bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos);
180 glm::mat4 GetBillboardMatrix(const glm::vec3 &pos);
181 glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos);
182 void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat);
183 void CenterCameraOnCity();
184
185 void CalculateCamera();
186 void MoveCamera(double deltaTime);
187
189
190 glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds);
191
192 void CalculateViewChange(double deltaX, double deltaY);
193 void FoundCity();
194 void SelectCountry();
195 void FocusOnEntity(entt::entity ent);
196
197 float GetWindowRatio();
198
199 void GenerateOrbitLines();
200
201 void RenderInformationWindow(double deltaTime);
203
204 // How much to scale the the star system.
205 const double divider = 0.01;
207
208 glm::vec3 sun_position;
209 glm::vec3 sun_color;
210
212
217
218 bool is_founding_city = false;
221 // Gets the intersection in 3d point between the mouse and any planet
222 glm::vec3 GetMouseOnObject() { return mouse_on_object; }
223 entt::entity on_planet;
224
225 float view_scale = 10.f;
226
227 entt::entity selected_city = entt::null;
228
232 int tex_x;
233 int tex_y;
234
238 int tex_r;
239 int tex_g;
240 int tex_b;
241
244
246 void CityDetection();
247
250 entt::entity hovering_province;
251 entt::entity selected_province;
252
254
255 const int sphere_resolution = 64;
256};
257} // namespace systems
258} // namespace client
259} // namespace cqsp
Definition: starsystemview.h:49
entt::entity terrain_displaying
Definition: starsystemview.h:93
entt::entity on_planet
Definition: starsystemview.h:223
glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos)
Calculates the GL position for a log renderbuffer.
Definition: starsystemview.cpp:839
void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity)
Definition: starsystemview.cpp:450
glm::vec4 viewport
Definition: starsystemview.h:119
cqsp::asset::ShaderProgram_t near_shader
Definition: starsystemview.h:108
void FocusOnEntity(entt::entity ent)
Definition: starsystemview.cpp:1043
int ship_icon_layer
Definition: starsystemview.h:213
void SeeStarSystem()
Definition: starsystemview.cpp:170
cqsp::engine::Application & m_app
Definition: starsystemview.h:96
void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province)
Definition: starsystemview.cpp:495
void DrawAllOrbits()
Definition: starsystemview.cpp:1325
int tex_r
Debugging colors
Definition: starsystemview.h:238
void GenerateOrbitLines()
Definition: starsystemview.cpp:1068
bool is_rendering_founding_city
Definition: starsystemview.h:219
void DrawOrbit(const entt::entity &entity)
Definition: starsystemview.cpp:1346
void DrawShipIcon(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:434
void SelectCountry()
Definition: starsystemview.cpp:1022
void DrawAllCities(auto &bodies)
Definition: starsystemview.cpp:425
glm::vec3 GetMouseIntersectionOnObject(int mouse_x, int mouse_y)
Definition: starsystemview.cpp:1204
void InitializeMeshes()
Definition: starsystemview.cpp:744
double scroll
Definition: starsystemview.h:71
void CalculateCityPositions()
Definition: starsystemview.cpp:645
float circle_size
Definition: starsystemview.h:121
glm::vec3 GetMouseOnObject()
Definition: starsystemview.h:222
double GetDivider()
Definition: starsystemview.h:78
cqsp::asset::ShaderProgram_t model_shader
Definition: starsystemview.h:106
glm::vec3 selected_country_color
Definition: starsystemview.h:249
int tex_y
Definition: starsystemview.h:233
void OnTick()
Definition: starsystemview.cpp:116
glm::vec3 TranslateToNormalized(const glm::vec3 &)
Definition: starsystemview.cpp:833
void Update(float deltaTime)
Definition: starsystemview.cpp:200
void FoundCity()
Definition: starsystemview.cpp:1001
void Initialize()
Definition: starsystemview.cpp:101
void Render(float deltaTime)
Definition: starsystemview.cpp:124
void DrawCityIcon(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:409
cqsp::engine::Renderable sun
Definition: starsystemview.h:104
float window_ratio
Definition: starsystemview.h:206
cqsp::asset::ShaderProgram_t orbit_shader
Definition: starsystemview.h:107
int tex_b
Definition: starsystemview.h:240
void OrbitEditor()
Definition: starsystemview.cpp:1403
common::components::types::SurfaceCoordinate GetMouseSurfaceIntersection()
Definition: starsystemview.cpp:1148
glm::mat4 GetBillboardMatrix(const glm::vec3 &pos)
Definition: starsystemview.cpp:854
entt::entity selected_city
Definition: starsystemview.h:227
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:791
void LoadProvinceMap()
Definition: starsystemview.cpp:742
cqsp::engine::Renderable planet_circle
Definition: starsystemview.h:101
glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:862
entt::entity selected_province
Definition: starsystemview.h:251
cqsp::engine::Renderable city
Definition: starsystemview.h:103
cqsp::engine::Renderable ship_overlay
Definition: starsystemview.h:102
double max_zoom
Definition: starsystemview.h:74
void RenderInformationWindow(double deltaTime)
Definition: starsystemview.cpp:1090
bool is_founding_city
Definition: starsystemview.h:218
int skybox_layer
Definition: starsystemview.h:216
void RenderSelectedObjectInformation()
Definition: starsystemview.cpp:1119
void FocusCityView()
Definition: starsystemview.cpp:803
SysStarSystemRenderer(cqsp::common::Universe &, cqsp::engine::Application &)
Definition: starsystemview.cpp:62
void DrawShips()
Definition: starsystemview.cpp:305
glm::vec3 view_center
Definition: starsystemview.h:76
static bool IsFoundingCity(common::Universe &universe)
Definition: starsystemview.cpp:1321
glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds)
Definition: starsystemview.cpp:975
double previous_mouseX
Definition: starsystemview.h:68
int province_width
Definition: starsystemview.h:243
void DrawModels()
Definition: starsystemview.cpp:344
cqsp::common::Universe & m_universe
Definition: starsystemview.h:95
void MoveCamera(double deltaTime)
Definition: starsystemview.cpp:915
void DrawStars()
Definition: starsystemview.cpp:266
void DrawPlanetBillboards(const entt::entity &ent_id, const glm::vec3 &object_pos)
Definition: starsystemview.cpp:389
bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos)
Definition: starsystemview.cpp:640
void InitializeFramebuffers()
Definition: starsystemview.cpp:733
glm::vec3 cam_pos
Definition: starsystemview.h:115
void CheckResourceDistRender()
Definition: starsystemview.cpp:946
glm::vec3 selected_province_color
Definition: starsystemview.h:248
float GetWindowRatio()
Definition: starsystemview.cpp:1066
glm::vec3 sun_color
Definition: starsystemview.h:209
float view_scale
Definition: starsystemview.h:225
glm::mat4 camera_matrix
Definition: starsystemview.h:117
void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat)
Definition: starsystemview.cpp:866
void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id)
Definition: starsystemview.cpp:371
glm::vec3 CalculateObjectPos(const entt::entity &)
Definition: starsystemview.cpp:820
int tex_x
Debugging mouse position
Definition: starsystemview.h:232
void DrawAllPlanetBillboards(auto &bodies)
Definition: starsystemview.cpp:544
double previous_mouseY
Definition: starsystemview.h:69
float view_y
Definition: starsystemview.h:66
engine::LayerRenderer renderer
Definition: starsystemview.h:211
void DrawSkybox()
Definition: starsystemview.cpp:330
glm::vec3 ConvertPoint(const glm::vec3 &)
Definition: starsystemview.cpp:837
glm::mat4 projection
Definition: starsystemview.h:118
glm::vec3 cam_up
Definition: starsystemview.h:116
entt::entity hovering_province
Definition: starsystemview.h:250
void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity)
Definition: starsystemview.cpp:597
entt::entity m_viewing_entity
Definition: starsystemview.h:92
cqsp::engine::Renderable planet
Definition: starsystemview.h:98
int orbits_generated
Definition: starsystemview.h:253
cqsp::engine::Renderable sky
Definition: starsystemview.h:100
void CalculateCamera()
Definition: starsystemview.cpp:907
void CalculateScroll()
Definition: starsystemview.cpp:670
void DrawBodies()
Definition: starsystemview.cpp:282
void SeePlanet(entt::entity)
Definition: starsystemview.cpp:253
void DrawPlanetIcon(glm::vec3 &object_pos)
Definition: starsystemview.cpp:382
void DrawStar(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemview.cpp:562
float view_x
Definition: starsystemview.h:64
const int sphere_resolution
Definition: starsystemview.h:255
cqsp::engine::Renderable textured_planet
Definition: starsystemview.h:99
int physical_layer
Definition: starsystemview.h:215
glm::vec3 sun_position
Definition: starsystemview.h:208
glm::vec3 CalculateCenteredObject(const entt::entity &)
Definition: starsystemview.cpp:903
void SeeEntity()
Definition: starsystemview.cpp:184
const double divider
Definition: starsystemview.h:205
double min_zoom
Definition: starsystemview.h:72
cqsp::asset::ShaderProgram_t vis_shader
Definition: starsystemview.h:109
void DoUI(float deltaTime)
Definition: starsystemview.cpp:258
void GenerateOrbit(entt::entity body)
Definition: starsystemview.cpp:1237
void LoadPlanetTextures()
Definition: starsystemview.cpp:685
bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos)
Check if the GL position is within the window
Definition: starsystemview.cpp:849
void CenterCameraOnCity()
Definition: starsystemview.cpp:872
int province_height
Definition: starsystemview.h:242
void DrawAllPlanets(auto &bodies)
Definition: starsystemview.cpp:520
void CityDetection()
Definition: starsystemview.cpp:1172
glm::vec3 mouse_on_object
Definition: starsystemview.h:220
int tex_g
Definition: starsystemview.h:239
void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemview.cpp:578
int planet_icon_layer
Definition: starsystemview.h:214
void CalculateViewChange(double deltaX, double deltaY)
Definition: starsystemview.cpp:985
Definition: universe.h:34
Definition: application.h:49
Renders a series of framebuffers onto screen. This is a relatively simple way of allowing organizatio...
Definition: framebuffer.h:133
Definition: renderable.h:28
std::shared_ptr< ShaderProgram > ShaderProgram_t
The preferred way of using a shader program.
Definition: shader.h:114
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:21
Definition: starsystemview.h:44
Definition: starsystemview.h:42
Definition: starsystemview.h:40
Definition: starsystemview.h:37
Longitude and lattitude. Planet coordinates.
Definition: coordinates.h:76
common::Universe * universe
Definition: turnsavewindow.h:3