2023-07-23 16:46:30 +02:00
|
|
|
// To compile on Windows
|
|
|
|
|
2023-07-24 23:15:49 +02:00
|
|
|
// Install GLFW 3.3.8
|
|
|
|
// https://www.glfw.org/download.html
|
2023-07-26 23:29:51 +02:00
|
|
|
// Install GLEW 2.2.0
|
|
|
|
// https://github.com/nigels-com/glew/releases/tag/glew-2.2.0
|
|
|
|
//
|
|
|
|
// extract the downloaded .zip files to "C:/libs"; this is currently expected
|
2023-07-24 23:15:49 +02:00
|
|
|
// by our CMakeLists.txt.
|
|
|
|
|
2023-07-23 16:46:30 +02:00
|
|
|
// Install CMake
|
|
|
|
// https://cmake.org/download
|
|
|
|
// Add to PATH for all users
|
|
|
|
// from project root:
|
|
|
|
// mkdir build
|
|
|
|
// cd build
|
|
|
|
// cmake ..
|
|
|
|
// cmake --build .
|
2023-07-23 17:46:53 +02:00
|
|
|
// The last step compiles the executable - this can also be done from Visual
|
|
|
|
// Studio
|
2023-07-23 16:46:30 +02:00
|
|
|
|
2023-07-23 17:46:53 +02:00
|
|
|
// To run in VS
|
|
|
|
// Set startup project in Solution Explorer
|
2023-07-24 23:15:49 +02:00
|
|
|
// Press F5 to run
|
2023-08-02 00:29:52 +02:00
|
|
|
|
|
|
|
// To run in VSCode
|
|
|
|
// https://code.visualstudio.com/docs/cpp/config-mingw
|
|
|
|
|
2023-07-24 23:15:49 +02:00
|
|
|
// To compile on Arch Linux
|
|
|
|
//
|
|
|
|
// Install dependencies
|
2023-07-24 23:31:58 +02:00
|
|
|
// sudo pacman -S glfw mesa glew
|
2023-07-24 23:15:49 +02:00
|
|
|
//
|
|
|
|
// Build
|
|
|
|
// cmake ..
|
|
|
|
// cmake --build .
|
2023-07-23 17:46:53 +02:00
|
|
|
|
2023-07-24 23:31:58 +02:00
|
|
|
#include <GL/glew.h>
|
2023-07-23 17:46:53 +02:00
|
|
|
#include <GLFW/glfw3.h>
|
2023-10-08 00:53:01 +02:00
|
|
|
#include <astro/stateVectorIndices.hpp>
|
2023-07-23 16:45:15 +02:00
|
|
|
|
2023-07-31 00:08:17 +02:00
|
|
|
#include "gfx.hpp"
|
2023-08-02 01:52:04 +02:00
|
|
|
#include "icosphere.hpp"
|
2023-08-06 02:40:35 +02:00
|
|
|
#include "orbit.hpp"
|
2023-10-06 00:25:37 +02:00
|
|
|
#include "widget.hpp"
|
2023-07-24 23:54:37 +02:00
|
|
|
|
2023-07-30 23:02:20 +02:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
GLFWwindow* window = nullptr;
|
2023-08-06 15:49:59 +02:00
|
|
|
if (initGraphics(&window, "Hello Astro") != 0)
|
2023-07-30 23:02:20 +02:00
|
|
|
return -1;
|
|
|
|
|
2023-08-06 13:08:49 +02:00
|
|
|
GLuint litProgram = compileShaderProgram("./frag_lit.glsl");
|
|
|
|
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
|
|
|
|
|
2023-08-15 00:14:19 +02:00
|
|
|
Icosphere planet(0.2, 3, litProgram);
|
|
|
|
Icosphere orbiter(0.07, 2, litProgram);
|
2023-10-08 00:53:01 +02:00
|
|
|
|
|
|
|
std::vector<float> keplerianElements(6);
|
|
|
|
keplerianElements[astro::semiMajorAxisIndex] = .75;
|
|
|
|
keplerianElements[astro::eccentricityIndex] = .5;
|
|
|
|
keplerianElements[astro::inclinationIndex] = 3.142 / 2.0 + 1;
|
|
|
|
keplerianElements[astro::argumentOfPeriapsisIndex] = 2.0;
|
|
|
|
keplerianElements[astro::longitudeOfAscendingNodeIndex] = 0;
|
|
|
|
Orbit orbit(keplerianElements);
|
2023-07-30 23:02:20 +02:00
|
|
|
|
2023-10-06 00:25:37 +02:00
|
|
|
Widget widget(orbit, unlitProgram);
|
|
|
|
|
2023-07-27 21:54:06 +02:00
|
|
|
// Main loop
|
2023-07-23 17:46:53 +02:00
|
|
|
while (!glfwWindowShouldClose(window))
|
|
|
|
{
|
2023-07-24 23:54:37 +02:00
|
|
|
glClearColor(0.2, 0.3, 0.3, 1.0);
|
2023-08-03 10:28:14 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2023-07-23 18:21:44 +02:00
|
|
|
|
2023-08-06 13:08:49 +02:00
|
|
|
float time = glfwGetTime();
|
2023-10-08 01:13:32 +02:00
|
|
|
const float orbitalPeriod = 6.284;
|
|
|
|
|
|
|
|
const int ANIM_ORBITING = 0;
|
|
|
|
const int ANIM_ECCENTRICITY = 1;
|
|
|
|
int animation = (int)(time / orbitalPeriod) % 2 == 1;
|
|
|
|
|
|
|
|
glm::vec3 pos;
|
|
|
|
if (animation == ANIM_ORBITING)
|
|
|
|
{
|
|
|
|
pos = orbit.getPosition(time);
|
|
|
|
}
|
|
|
|
else if (animation == ANIM_ECCENTRICITY)
|
|
|
|
{
|
|
|
|
float e = .25 + .2 * sin(time);
|
|
|
|
keplerianElements[astro::eccentricityIndex] = e;
|
|
|
|
orbit.setElements(keplerianElements);
|
|
|
|
|
|
|
|
pos = orbit.getPosition(0);
|
|
|
|
}
|
2023-08-14 01:45:54 +02:00
|
|
|
orbiter.setPosition(pos);
|
2023-08-02 23:35:52 +02:00
|
|
|
|
2023-08-06 13:08:49 +02:00
|
|
|
// Render lit objects
|
|
|
|
glUseProgram(litProgram);
|
|
|
|
updateModelViewProjectionMatrix(litProgram, time);
|
2023-08-14 01:34:00 +02:00
|
|
|
|
|
|
|
planet.render();
|
|
|
|
orbiter.render();
|
2023-08-06 13:08:49 +02:00
|
|
|
|
|
|
|
// Render unlit objects
|
|
|
|
glUseProgram(unlitProgram);
|
|
|
|
updateModelViewProjectionMatrix(unlitProgram, time);
|
2023-08-06 02:40:35 +02:00
|
|
|
orbit.render();
|
2023-10-06 00:25:37 +02:00
|
|
|
widget.render();
|
2023-07-23 18:21:44 +02:00
|
|
|
|
2023-07-24 23:54:37 +02:00
|
|
|
glfwSwapBuffers(window);
|
2023-07-23 17:46:53 +02:00
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwTerminate();
|
2023-07-23 16:45:15 +02:00
|
|
|
return 0;
|
2023-07-24 23:15:49 +02:00
|
|
|
}
|