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
106
111#if FALSE
112 // Disabled for now
113 asset::ShaderProgram_t no_light_shader;
114#endif
115
116 glm::vec3 cam_pos;
117 glm::vec3 cam_up = glm::vec3(0.0f, 1.0f, 0.0f);
118 glm::mat4 camera_matrix;
119 glm::mat4 projection;
120 glm::vec4 viewport;
121
122 float circle_size = 0.01f;
123
124 void DrawStars();
125 void DrawBodies();
126 void DrawShips();
127 void DrawSkybox();
128 void DrawModels();
129
130 void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id);
131 void DrawPlanetIcon(glm::vec3 &object_pos);
132 void DrawPlanetBillboards(const entt::entity &ent_id, const glm::vec3 &object_pos);
133 void DrawShipIcon(const glm::vec3 &object_pos);
134 void DrawCityIcon(const glm::vec3 &object_pos);
135
136 void DrawAllCities(auto &bodies);
137
138 void DrawAllPlanets(auto &bodies);
139 void DrawAllPlanetBillboards(auto &bodies);
140
141 void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity);
142 void GetPlanetTexture(const entt::entity entity, bool &have_normal, bool &have_roughness, bool &have_province);
143 void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos);
144
145 void DrawStar(const entt::entity &entity, glm::vec3 &object_pos);
146 void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity);
147 bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos);
149 void CalculateScroll();
150
151 void LoadPlanetTextures();
153 void LoadProvinceMap();
154 void InitializeMeshes();
155
156 void GenerateOrbit(entt::entity body);
157
164 glm::quat GetBodyRotation(double axial, double rotation, double day_offset);
165 void FocusCityView();
166
167 glm::vec3 CalculateObjectPos(const entt::entity &);
168 glm::vec3 CalculateCenteredObject(const entt::entity &);
169 glm::vec3 CalculateCenteredObject(const glm::vec3 &);
170 glm::vec3 TranslateToNormalized(const glm::vec3 &);
171 glm::vec3 ConvertPoint(const glm::vec3 &);
172
176 glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos);
180 bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos);
181 glm::mat4 GetBillboardMatrix(const glm::vec3 &pos);
182 glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos);
183 void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat);
184 void CenterCameraOnCity();
185
186 void CalculateCamera();
187 void MoveCamera(double deltaTime);
188
190
191 glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds);
192
193 void CalculateViewChange(double deltaX, double deltaY);
194 void FoundCity();
195 void SelectCountry();
196 void FocusOnEntity(entt::entity ent);
197
198 float GetWindowRatio();
199
200 void GenerateOrbitLines();
201
202 void RenderInformationWindow(double deltaTime);
204
205 // How much to scale the the star system.
206 const double divider = 0.01;
208
209 glm::vec3 sun_position;
210 glm::vec3 sun_color;
211
213
218
219 bool is_founding_city = false;
222 // Gets the intersection in 3d point between the mouse and any planet
223 glm::vec3 GetMouseOnObject() { return mouse_on_object; }
224 entt::entity on_planet;
225
226 float view_scale = 10.f;
227
228 entt::entity selected_city = entt::null;
229
233 int tex_x;
234 int tex_y;
235
239 int tex_r;
240 int tex_g;
241 int tex_b;
242
245
247 void CityDetection();
248
251 entt::entity hovering_province;
252 entt::entity selected_province;
253
255
256 const int sphere_resolution = 64;
257};
258} // namespace systems
259} // namespace client
260} // namespace cqsp
Definition: starsystemview.h:49
entt::entity terrain_displaying
Definition: starsystemview.h:93
entt::entity on_planet
Definition: starsystemview.h:224
glm::vec4 CalculateGLPosition(const glm::vec3 &object_pos)
Calculates the GL position for a log renderbuffer.
Definition: starsystemview.cpp:831
void DrawTexturedPlanet(const glm::vec3 &object_pos, const entt::entity entity)
Definition: starsystemview.cpp:441
glm::vec4 viewport
Definition: starsystemview.h:120
cqsp::asset::ShaderProgram_t near_shader
Definition: starsystemview.h:109
void FocusOnEntity(entt::entity ent)
Definition: starsystemview.cpp:1035
int ship_icon_layer
Definition: starsystemview.h:214
void SeeStarSystem()
Definition: starsystemview.cpp:169
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:486
void DrawAllOrbits()
Definition: starsystemview.cpp:1317
int tex_r
Debugging colors
Definition: starsystemview.h:239
void GenerateOrbitLines()
Definition: starsystemview.cpp:1060
cqsp::asset::Model * iss_model
Definition: starsystemview.h:105
bool is_rendering_founding_city
Definition: starsystemview.h:220
void DrawOrbit(const entt::entity &entity)
Definition: starsystemview.cpp:1338
void DrawShipIcon(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:425
void SelectCountry()
Definition: starsystemview.cpp:1014
void DrawAllCities(auto &bodies)
Definition: starsystemview.cpp:416
glm::vec3 GetMouseIntersectionOnObject(int mouse_x, int mouse_y)
Definition: starsystemview.cpp:1196
void InitializeMeshes()
Definition: starsystemview.cpp:735
double scroll
Definition: starsystemview.h:71
void CalculateCityPositions()
Definition: starsystemview.cpp:636
float circle_size
Definition: starsystemview.h:122
glm::vec3 GetMouseOnObject()
Definition: starsystemview.h:223
double GetDivider()
Definition: starsystemview.h:78
cqsp::asset::ShaderProgram_t model_shader
Definition: starsystemview.h:107
glm::vec3 selected_country_color
Definition: starsystemview.h:250
int tex_y
Definition: starsystemview.h:234
void OnTick()
Definition: starsystemview.cpp:115
glm::vec3 TranslateToNormalized(const glm::vec3 &)
Definition: starsystemview.cpp:825
void Update(float deltaTime)
Definition: starsystemview.cpp:199
void FoundCity()
Definition: starsystemview.cpp:993
void Initialize()
Definition: starsystemview.cpp:100
void Render(float deltaTime)
Definition: starsystemview.cpp:123
void DrawCityIcon(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:400
cqsp::engine::Renderable sun
Definition: starsystemview.h:104
float window_ratio
Definition: starsystemview.h:207
cqsp::asset::ShaderProgram_t orbit_shader
Definition: starsystemview.h:108
int tex_b
Definition: starsystemview.h:241
void OrbitEditor()
Definition: starsystemview.cpp:1395
common::components::types::SurfaceCoordinate GetMouseSurfaceIntersection()
Definition: starsystemview.cpp:1140
glm::mat4 GetBillboardMatrix(const glm::vec3 &pos)
Definition: starsystemview.cpp:846
entt::entity selected_city
Definition: starsystemview.h:228
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:783
void LoadProvinceMap()
Definition: starsystemview.cpp:733
cqsp::engine::Renderable planet_circle
Definition: starsystemview.h:101
glm::vec3 GetBillboardPosition(const glm::vec3 &object_pos)
Definition: starsystemview.cpp:854
entt::entity selected_province
Definition: starsystemview.h:252
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:1082
bool is_founding_city
Definition: starsystemview.h:219
int skybox_layer
Definition: starsystemview.h:217
void RenderSelectedObjectInformation()
Definition: starsystemview.cpp:1111
void FocusCityView()
Definition: starsystemview.cpp:795
SysStarSystemRenderer(cqsp::common::Universe &, cqsp::engine::Application &)
Definition: starsystemview.cpp:61
void DrawShips()
Definition: starsystemview.cpp:304
glm::vec3 view_center
Definition: starsystemview.h:76
static bool IsFoundingCity(common::Universe &universe)
Definition: starsystemview.cpp:1313
glm::vec3 CalculateMouseRay(const glm::vec3 &ray_nds)
Definition: starsystemview.cpp:967
double previous_mouseX
Definition: starsystemview.h:68
int province_width
Definition: starsystemview.h:244
void DrawModels()
Definition: starsystemview.cpp:343
cqsp::common::Universe & m_universe
Definition: starsystemview.h:95
void MoveCamera(double deltaTime)
Definition: starsystemview.cpp:907
void DrawStars()
Definition: starsystemview.cpp:265
void DrawPlanetBillboards(const entt::entity &ent_id, const glm::vec3 &object_pos)
Definition: starsystemview.cpp:380
bool CityIsVisible(glm::vec3 city_pos, glm::vec3 planet_pos, glm::vec3 cam_pos)
Definition: starsystemview.cpp:631
void InitializeFramebuffers()
Definition: starsystemview.cpp:724
glm::vec3 cam_pos
Definition: starsystemview.h:116
void CheckResourceDistRender()
Definition: starsystemview.cpp:938
glm::vec3 selected_province_color
Definition: starsystemview.h:249
float GetWindowRatio()
Definition: starsystemview.cpp:1058
glm::vec3 sun_color
Definition: starsystemview.h:210
float view_scale
Definition: starsystemview.h:226
glm::mat4 camera_matrix
Definition: starsystemview.h:118
void SetBillboardProjection(cqsp::asset::ShaderProgram_t &shader, glm::mat4 mat)
Definition: starsystemview.cpp:858
void DrawEntityName(glm::vec3 &object_pos, entt::entity ent_id)
Definition: starsystemview.cpp:362
glm::vec3 CalculateObjectPos(const entt::entity &)
Definition: starsystemview.cpp:812
int tex_x
Debugging mouse position
Definition: starsystemview.h:233
void DrawAllPlanetBillboards(auto &bodies)
Definition: starsystemview.cpp:535
double previous_mouseY
Definition: starsystemview.h:69
float view_y
Definition: starsystemview.h:66
engine::LayerRenderer renderer
Definition: starsystemview.h:212
void DrawSkybox()
Definition: starsystemview.cpp:329
glm::vec3 ConvertPoint(const glm::vec3 &)
Definition: starsystemview.cpp:829
glm::mat4 projection
Definition: starsystemview.h:119
glm::vec3 cam_up
Definition: starsystemview.h:117
entt::entity hovering_province
Definition: starsystemview.h:251
void RenderCities(glm::vec3 &object_pos, const entt::entity &body_entity)
Definition: starsystemview.cpp:588
entt::entity m_viewing_entity
Definition: starsystemview.h:92
cqsp::engine::Renderable planet
Definition: starsystemview.h:98
int orbits_generated
Definition: starsystemview.h:254
cqsp::engine::Renderable sky
Definition: starsystemview.h:100
void CalculateCamera()
Definition: starsystemview.cpp:899
void CalculateScroll()
Definition: starsystemview.cpp:661
void DrawBodies()
Definition: starsystemview.cpp:281
void SeePlanet(entt::entity)
Definition: starsystemview.cpp:252
void DrawPlanetIcon(glm::vec3 &object_pos)
Definition: starsystemview.cpp:373
void DrawStar(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemview.cpp:553
float view_x
Definition: starsystemview.h:64
const int sphere_resolution
Definition: starsystemview.h:256
cqsp::engine::Renderable textured_planet
Definition: starsystemview.h:99
int physical_layer
Definition: starsystemview.h:216
glm::vec3 sun_position
Definition: starsystemview.h:209
glm::vec3 CalculateCenteredObject(const entt::entity &)
Definition: starsystemview.cpp:895
void SeeEntity()
Definition: starsystemview.cpp:183
const double divider
Definition: starsystemview.h:206
double min_zoom
Definition: starsystemview.h:72
cqsp::asset::ShaderProgram_t vis_shader
Definition: starsystemview.h:110
void DoUI(float deltaTime)
Definition: starsystemview.cpp:257
void GenerateOrbit(entt::entity body)
Definition: starsystemview.cpp:1229
void LoadPlanetTextures()
Definition: starsystemview.cpp:676
bool GLPositionNotInBounds(const glm::vec4 &gl_Position, const glm::vec3 &pos)
Check if the GL position is within the window
Definition: starsystemview.cpp:841
void CenterCameraOnCity()
Definition: starsystemview.cpp:864
int province_height
Definition: starsystemview.h:243
void DrawAllPlanets(auto &bodies)
Definition: starsystemview.cpp:511
void CityDetection()
Definition: starsystemview.cpp:1164
glm::vec3 mouse_on_object
Definition: starsystemview.h:221
int tex_g
Definition: starsystemview.h:240
void DrawTerrainlessPlanet(const entt::entity &entity, glm::vec3 &object_pos)
Definition: starsystemview.cpp:569
int planet_icon_layer
Definition: starsystemview.h:215
void CalculateViewChange(double deltaX, double deltaY)
Definition: starsystemview.cpp:977
Definition: universe.h:32
Definition: application.h:47
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:112
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:21
Definition: model.h:73
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