]> git.localhorst.tv Git - blobs.git/blob - src/blobs.cpp
slightly better planet
[blobs.git] / src / blobs.cpp
1 #include "const.hpp"
2 #include "app/Application.hpp"
3 #include "app/Assets.hpp"
4 #include "app/init.hpp"
5 #include "app/MasterState.hpp"
6 #include "world/Creature.hpp"
7 #include "world/Planet.hpp"
8 #include "world/Simulation.hpp"
9 #include "world/Sun.hpp"
10 #include "world/TileSet.hpp"
11 #include "world/TileType.hpp"
12
13 #include <cstdint>
14 #include <iostream>
15
16
17 using namespace blobs;
18
19 int main(int argc, char *argv[]) {
20         app::Init init(true, 8);
21         app::Assets assets;
22
23         world::TileSet tiles;
24         tiles.Add({ "algae",    "Algae",    0,  0 });
25         tiles.Add({ "desert",   "Desert",   0,  1 });
26         tiles.Add({ "forest",   "Forest",   0,  2 });
27         tiles.Add({ "grass",    "Grass",    0,  3 });
28         tiles.Add({ "ice",      "Ice",      0,  4 });
29         tiles.Add({ "jungle",   "Jungle",   0,  5 });
30         tiles.Add({ "mountain", "Mountain", 0,  6 });
31         tiles.Add({ "ocean",    "Ocean",    0,  7 });
32         tiles.Add({ "rock",     "Rock",     0,  8 });
33         tiles.Add({ "sand",     "Sand",     0,  9 });
34         tiles.Add({ "taiga",    "Taiga",    0, 10 });
35         tiles.Add({ "tundra",   "Tundra",   0, 11 });
36         tiles.Add({ "water",    "Water",    0, 12 });
37         tiles.Add({ "wheat",    "Wheat",    0, 13 });
38
39         world::Sun sun;
40         sun.Mass(1.0e14);
41         sun.Radius(20.0);
42         sun.SurfaceTilt(glm::dvec2(PI * 0.25, PI * 0.25));
43         sun.AngularMomentum(1.0e13);
44
45         world::Planet planet(25);
46         planet.SetParent(sun);
47         planet.Mass(1.0e10);
48         planet.GetOrbit().SemiMajorAxis(941.7);
49         planet.SurfaceTilt(glm::dvec2(PI * 0.25, PI * 0.25));
50         planet.AxialTilt(glm::dvec2(PI * 0.127, 0.0));
51         planet.AngularMomentum(6.0e10);
52
53         world::Planet moon(3);
54         moon.SetParent(planet);
55         moon.Mass(1.0e6);
56         moon.GetOrbit().SemiMajorAxis(37.0);
57         moon.Rotation(PI * 0.25);
58         moon.AngularMomentum(1.0e4);
59
60         world::Planet second_planet(9);
61         second_planet.SetParent(sun);
62         second_planet.Mass(1.0e9);
63         second_planet.GetOrbit().SemiMajorAxis(350.0);
64         second_planet.SurfaceTilt(glm::dvec2(PI * 0.125, PI * 0.25));
65         second_planet.AxialTilt(glm::dvec2(PI * 0.95, 0.0));
66         second_planet.AngularMomentum(1.0e8);
67
68         world::Simulation sim(sun);
69         sim.AddSun(sun);
70         sim.AddPlanet(planet);
71         sim.AddPlanet(second_planet);
72         sim.AddPlanet(moon);
73
74         world::GenerateEarthlike(tiles, planet);
75         world::GenerateTest(tiles, moon);
76         world::GenerateTest(tiles, second_planet);
77
78         std::cout << "length of year: " << planet.OrbitalPeriod() << "s" << std::endl;
79         std::cout << "length of moon cycle: " << moon.OrbitalPeriod() << "s" << std::endl;
80         std::cout << "length of day: " << planet.RotationalPeriod() << "s" << std::endl;
81         std::cout << "days per year: " << (planet.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl;
82         std::cout << "moon cycle in days: " << (moon.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl;
83         std::cout << "moon cycles per year: " << (planet.OrbitalPeriod() / moon.OrbitalPeriod()) << std::endl;
84
85         auto blob = new world::Creature;
86         blob->BuildVAO();
87         planet.AddCreature(blob);
88         blob->Surface(0);
89         blob->Position(glm::dvec3(0.0, 0.0, 0.0));
90
91         app::MasterState state(assets, sim);
92         state.GetCamera()
93                 .Reference(planet)
94                 // sunrise
95                 //.FirstPerson(0, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
96                 // sunset
97                 //.FirstPerson(3, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
98                 // from afar
99                 //.MapView(0, glm::vec3(0.0f, 0.0f, 60.0f), 0.0f)
100                 // from afar, rotating
101                 .Orbital(glm::vec3(-60.0f, 0.0f, 0.0f))
102         ;
103         // system view
104         //state.GetCamera()
105         //      .Reference(sun)
106         //      .Orbital(glm::vec3(-500.0f, 500.0f, 500.0f))
107         //;
108
109         app::Application app(init.window, init.viewport);
110         app.PushState(&state);
111         app.Run();
112
113         return 0;
114 }