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.
coordinates.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 <math.h>
20
21#include <entt/entt.hpp>
22#include <glm/glm.hpp>
23#include <glm/gtc/quaternion.hpp>
24
27
29struct OrbitDirty {};
30
32struct Kinematics {
33 glm::dvec3 position {0, 0, 0};
34 glm::dvec3 velocity {0, 0, 0};
35 glm::dvec3 center {0, 0, 0};
36};
37
39 glm::dvec3 position {0, 0, 0};
40 glm::dvec3 velocity {0, 0, 0};
41 glm::dvec3 center {0, 0, 0};
42};
43
44// A one tick impulse in the vector
45struct Impulse {
46 glm::dvec3 impulse;
47};
48
55};
56
57template <typename T>
59 T r;
61
62 PolarCoordinate_tp() = default;
63 PolarCoordinate_tp(T _r, degree _theta) : r(_r), theta(_theta) {}
64};
66
67struct MoveTarget {
68 entt::entity target;
69 explicit MoveTarget(entt::entity _targetent) : target(_targetent) {}
70};
71
77 private:
80
81 public:
82 SurfaceCoordinate() = default;
83
90 _lat = normalize_radian_coord(_lat);
92 }
93
96
97 degree latitude() const { return toDegree(_latitude); }
98
99 degree longitude() const { return toDegree(_longitude); }
100
101 radian r_longitude() const { return _longitude; }
102
103 radian r_latitude() const { return _latitude; }
104
106
107 entt::entity planet = entt::null;
108};
109
117
122glm::vec3 toVec3(const SurfaceCoordinate& coord, const float& radius = 1);
123
129inline glm::vec3 toVec3(const PolarCoordinate& coordinate) {
130 return glm::vec3(coordinate.r * cos(toRadian(coordinate.theta)), 0, coordinate.r * sin(toRadian(coordinate.theta)));
131}
132
139double GetLaunchAzimuth(double latitude, double inclination);
140
147double GetLaunchInclination(double latitude, double azimuth);
148
149SurfaceCoordinate ToSurfaceCoordinate(const glm::vec3& vec);
150} // namespace cqsp::common::components::types
Definition: coordinates.cpp:22
SurfaceCoordinate ToSurfaceCoordinate(const glm::vec3 &vec)
Definition: coordinates.cpp:51
constexpr degree toDegree(radian theta)
Definition: units.h:98
double GetLaunchAzimuth(double latitude, double inclination)
Calculates the azimuth of the orbit based on the latitude and inclination
Definition: coordinates.cpp:44
glm::vec3 toVec3(const SurfaceCoordinate &coord, const float &radius)
Converts surface coordinate to vector3 in space so that we can get the surface coordinate to render i...
Definition: coordinates.cpp:33
double radian
Definition: units.h:37
constexpr radian toRadian(degree theta)
Definition: units.h:97
double GreatCircleDistance(SurfaceCoordinate &coord1, SurfaceCoordinate &coord2)
Calculates the angle between the two coordinates. Just multiply by the planet's diameter for fun and ...
Definition: coordinates.cpp:23
double light_year
Definition: units.h:33
constexpr double PI
Definition: units.h:45
double degree
Definition: units.h:36
double GetLaunchInclination(double latitude, double azimuth)
Calculates the inclination of the orbit based on the latitude and azimuth
Definition: coordinates.cpp:49
constexpr double normalize_radian_coord(const radian &radian)
Definition: units.h:78
PolarCoordinate_tp< types::astronomical_unit > PolarCoordinate
Definition: coordinates.h:65
glm::dvec3 position
Definition: coordinates.h:39
glm::dvec3 velocity
Definition: coordinates.h:40
glm::dvec3 center
Definition: coordinates.h:41
Way to position star systems on the universe.
Definition: coordinates.h:52
types::light_year x
Definition: coordinates.h:53
types::light_year y
Definition: coordinates.h:54
Definition: coordinates.h:45
glm::dvec3 impulse
Definition: coordinates.h:46
Relative position from the parent orbiting object.
Definition: coordinates.h:32
glm::dvec3 velocity
Definition: coordinates.h:34
glm::dvec3 position
Definition: coordinates.h:33
glm::dvec3 center
Definition: coordinates.h:35
MoveTarget(entt::entity _targetent)
Definition: coordinates.h:69
entt::entity target
Definition: coordinates.h:68
degree theta
Definition: coordinates.h:60
PolarCoordinate_tp(T _r, degree _theta)
Definition: coordinates.h:63
Longitude and lattitude. Planet coordinates.
Definition: coordinates.h:76
degree longitude() const
Definition: coordinates.h:99
SurfaceCoordinate(degree _lat, degree _long)
Creates a surface coordinate
Definition: coordinates.h:89
radian _longitude
Definition: coordinates.h:79
radian _latitude
Definition: coordinates.h:78
entt::entity planet
Definition: coordinates.h:107
radian r_longitude() const
Definition: coordinates.h:101
degree latitude() const
Definition: coordinates.h:97
radian r_latitude() const
Definition: coordinates.h:103
SurfaceCoordinate universe_view() const
Definition: coordinates.h:105
SurfaceCoordinate(radian _lat, radian _long, bool radian)
Definition: coordinates.h:94