-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKeplerian_objects.hpp
executable file
·308 lines (244 loc) · 12.5 KB
/
Keplerian_objects.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// Game_Objects.h //////////////////////////////////////////////////////////////
// All of the core classes that the ignition engine requires to function, //////
// including Newtonian and Keplerian parent classes for all celestial bodies ///
// and vessels /////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
#include <math.h>
#include <vector>
#include "Game_physics.hpp"
#ifndef KeplersObjects
#define KeplersObjects
class Force
{ public:
// all really just a nice placeholder for two vectors, since a force acting
// on a body has a point where it acts on the body and a direction
Force(VectorVictor::Vector2 attack_point, VectorVictor::Vector2 force);
// simple as it gets, although maybe an alternate for direct variables might
// be nice here
VectorVictor::Vector2 Attack_point;
VectorVictor::Vector2 Force_vector;
// our vectors...
double Get_force_torque();
// basically find the cross product of the two vectors, which should always
// only have a z component if the vectors are all 2d. This simple version
// just assumes that the origin we want the waaaiit. Oh shit
// okay, now that should be cleaned up. The basic idea here is that the
// vanilla Get_force_torque(); assumes our origin to be at (0,0), when we
// may want to translate it around (center of mass)
double Get_force_torque(VectorVictor::Vector2 reference_point);
// and the second version of the function mentioned above, where our origin
// is shifted by reference_point
VectorVictor::Vector2 Get_force_vector();
// just as simple as it sounds
VectorVictor::Vector2 Get_force_vector(double angle);
// returns the vector rotated by the given angle clockwise around the origin
// angle is inputted in degrees. No affect to the direction of the stored
// Force vector in this object
// I dont recall where this is used, should look that up
~Force();
};
// Celestial Bodies ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class Planetary_surface: public sf::Drawable, public sf::Transformable
{ public:
Planetary_surface();
Planetary_surface(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);
Planetary_surface(const std::string& tileset, sf::Vector2u tileSize, std::vector<int> tiles, unsigned int width, unsigned int height);
Planetary_surface(sf::Texture &tileset, sf::Vector2u tileSize, std::vector<int> tiles, unsigned int width, unsigned int height);
// in practice, each planet will have a list of surface points, which will
// use a seed to generate the list of values in tiles based on the seed
// (ie fractally compressed terrain)
// also the terrain point contains some sort of reference to the type of
// terrain (grass, desert, water, whatever)
// not sure what Im gonna do about water though
// maybe a list of water points that behave like a normal surface tile
// cause oceans gotta be somewhat rounded if they cover several degrees of
// longitude and cant be really flat lines across huge distances
// hmm wait, cant define ocean bottoms that way, maybe just define seas
// by their beds, and the planetary sea level is used to find where the
// sea level tiles go from there, that way we can also have underwater
// dynamics
// but Im going overboard here
bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);
bool load(const std::string& tileset, sf::Vector2u tileSize, std::vector<int> tiles, unsigned int width, unsigned int height);
bool load(sf::Texture &tileset, sf::Vector2u tileSize, std::vector<int> tiles, unsigned int width, unsigned int height);
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
sf::VertexArray m_vertices;
sf::Texture m_tileset;
public:
~Planetary_surface();
};
class Terrain_point
{ Terrain_point();
Terrain_point(int terrain_type, long double radius, int point_id);
bool Init_object(int terrain_type, long double radius, int point_id);
// setter
protected:
// sigh, I can never remember what these all do...
int Terrain_type;
// terrain types determine which texture set is used for the terrain block
// if it goes over the number of types available, we just go to the last one
// defined, no problem
long double Radius;
// the radius of the planet at this given point
int Point_id;
// unique id of the point in the list of all of the planets terrain points,
// used to find the in universe location of the point
// int Seed;
// this comin later
public:
bool Match_point(int point_id);
~Terrain_point();
};
typedef id celestial_id;
// an id type for all celestial bodies
class CKeplerian_Object
{ public:
CKeplerian_Object(long double theta, long double omega, long double mean_radius, long double atm_height, long double mass, std::string texture_path);
// constructor, fairly generic enough for celestial objects
static celestial_id Celestial_index;
// can be seen as either the number of celestial/keplerian objects in the
// sim, or the id # that will be assigned to the next object of this type
// created
// used to assign a unique number as an id to each object of this type
celestial_id Get_new_index();
// returns a new index to assign to an object and increments the counter
// by one
celestial_id Celestial_id;
// the current objects id #
celestial_id Get_celestial_id();
static std::vector<CKeplerian_Object*> Celestial_objects;
// the global list of all objects of type CKeplerian... and all objects that
// inherit from this type
void New_keplerian(CKeplerian_Object * new_this);
// inserts the new keplerian objects pointer of this into the
// Celestial_objects vector. *must* be called every time an object
// of this type is created for things to work out nicely
virtual void Frame(double dt, long double simtime);
// virtual stub for the update function for objects of this type
long double Theta, Omega;
// rotation and angular rate, both stored in degrees, but can be accessed as
// radians where required
long double Get_omega();
// by default in degrees
long double Get_theta_in_degrees();
long double Get_theta_in_radians();
long double Simulation_time;
// ahh, this I do not really like, it sort of syncs between the master
// ignition engine objects simtime, since this object needs to know the
// current time with precision to know its position (or will soon anyways)
long double Radius;
// in meters. Sort of a global mean, specific radii will be determined later
long double Get_radius(double longitude);
// Simple as it gets, just return the terrain height at given longitude
// from the planets prime meridian (all the little greenwiches xD)
// This just returns the constant above for the moment, but the world will
// not always be a perfect sphere!
long double Atmosphere_height;
// distance from the surface to the top of the atmosphere (the point we stop
// rendering the atmosphere mask at) in meters
sf::Color Surface_atmosphere_colour;
// the colour of the atmosphere mask at sea level on the planet
sf::Color Top_atmosphere_colour;
// The final colour of the atmosphere mask at an altitude of Atmosphere
// height above the ground
//the alphas of both of these are forced to correct values in the
// constructor, so we dont get any monkey business
long double Mass;
// Total mass of the celestial object in kilograms
long double Get_mass();
virtual VectorVictor::Vector2 Get_position(long double sim_time);
virtual VectorVictor::Vector2 Get_position();
// returns the position of the object at the current time. sim_time
// required so that we can use the orbit equations in 2d to get an
// exact position
VectorVictor::Vector2 Gravity_acceleration(VectorVictor::Vector2 satellite_position, long double simtime);
// function returning the acceleration due to gravity caused by this body,
// for the parameters passed
std::string Object_name;
// Welcome to <Object_name>!
std::string Get_object_name();
sf::Texture Object_texture;
std::vector<sf::Sprite> Object_sprites;
// the whole sequence of sprites for each successive scaled map view
// need to remember what the order was for scales
// after a certain point of zooming out, we just assumed that the image
// looks the same no matter how much farther we go
sf::Sprite Object_sprite;
// the image of the object drawn in the camera view at huge scales, meant
// to gradually replace the map view in practice
virtual bool In_view(SFML_Window * window, int zoom_factor, long double simtime);
virtual bool In_view(SFML_Window * window, long double cam_scale, long double simtime);
// how we check if the planet should be drawn
virtual void Draw_flag(SFML_Window * iwindow, int zoom_factor);
virtual void Draw_flag(SFML_Window * iwindow, long double cam_scale, long double sim_time);
// and how we do it if it should
virtual sf::Color Get_atmosphere_mask(VectorVictor::Vector2 window_origin, long double sim_time);
// get the colour of the atmosphere that we will render over the starfield
// as a sf::RectShape in the main window loop
// this is virtual so that more complex behaviours can eventually be
// implemented, like gas giant atmospheres with many levels of atmosphere
virtual int Get_terrain_points();
// returns the number of points in the terrain total, evenly spaced
// over the whole planet/moon
// a quick note, based on a maximum value of int of around 2.1 billion,
// this gives Earth a max density of about 2 cm per point, which
// should be way better than needed
std::vector<Terrain_point> Surface;
// the list of points that make up the surface, containing info about radii
// at longitudes & so on
virtual void Draw_surface(SFML_Window * iwindow);
// virtual function that draws the surface of the object when in camera view
CKeplerian_Object * Get_keplerian_pointer();
};
bool Retrieve_keplerian(celestial_id target_id, CKeplerian_Object * &target_object);
// checks to see if an object with the given target id can be found, returns
// true if it is found, and assigns its pointer to target_object so we can play
// with an object BASED ON A NUMBER!!!
typedef id planet_id;
class TPlanet: public CKeplerian_Object
{ public:
// basic type derived from Keplerian object that handles official planets
// and mostly dwarf planets too. Basically anything that orbits the sun and
// is to big to realistically handle as a newtonian object
static planet_id Planet_index;
// can be seen as either the number of planets in the
// sim, or the id # that will be assigned to the next object of this type
// created
// used to assign a unique number as an id to each object of this type
planet_id Get_new_index();
// returns a new index to assign to an object and increments the counter
// by one
planet_id Planet_id;
// the current objects id #
planet_id Get_planet_id();
static std::vector<TPlanet*> Planet_list;
// the global list of all objects of type CKeplerian... and all objects that
// inherit from this type
void New_planet(TPlanet * new_this);
// inserts the new planet objects pointer of this into the
// Celestial_objects vector. *must* be called every time an object
// of this type is created for things to work out nicely
TPlanet(long double initial_theta, long double omega, long double radius, long double atmosphere_height, long double mass, std::string planet_texture_path, sf::Color top_atm_color, sf::Color surf_atm_color);
void Frame(double dt, long double simtime);
VectorVictor::Vector2 Get_position(long double sim_time);
VectorVictor::Vector2 Get_position();
// this... this should work a bit differently, sim_time should be implicitly
// now, position evaluated and stored each frame
bool In_view(SFML_Window * window, int zoom_factor, long double simtime);
bool In_view(SFML_Window * window, long double cam_scale, long double simtime);
void Draw_flag(SFML_Window * iwindow, int zoom_factor);
void Draw_flag(SFML_Window * iwindow, long double cam_scale, long double sim_time);
// Similar deal as before. Should double check that the inview check uses
// the correct radius for that map scale
sf::Color Get_atmosphere_mask(VectorVictor::Vector2 window_origin, long double sim_time);
int Get_terrain_points();
void Draw_surface(SFML_Window * iwindow);
TPlanet * Get_planet_pointer();
~TPlanet();
};
bool Retrieve_planet(planet_id target_id, TPlanet * &target_object);
#endif