// To compile on Windows // Install GLFW 3.3.8 // https://www.glfw.org/download.html // 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 // by our CMakeLists.txt. // Install CMake // https://cmake.org/download // Add to PATH for all users // from project root: // mkdir build // cd build // cmake .. // cmake --build . // The last step compiles the executable - this can also be done from Visual // Studio // To run in VS // Set startup project in Solution Explorer // Press F5 to run // To run in VSCode // https://code.visualstudio.com/docs/cpp/config-mingw // To compile on Arch Linux // // Install dependencies // sudo pacman -S glfw mesa glew // // Build // cmake .. // cmake --build . #include #include #include #include "gfx.hpp" #include "icosphere.hpp" #include "orbit.hpp" #include "widget.hpp" int main() { GLFWwindow* window = nullptr; if (initGraphics(&window, "Hello Astro") != 0) return -1; GLuint litProgram = compileShaderProgram("./frag_lit.glsl"); GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl"); Icosphere planet(0.2, 3, litProgram); Icosphere orbiter(0.07, 2, litProgram); std::vector 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); Widget widget(orbit, unlitProgram); // Main loop while (!glfwWindowShouldClose(window)) { glClearColor(0.2, 0.3, 0.3, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float time = glfwGetTime(); 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); } orbiter.setPosition(pos); // Render lit objects glUseProgram(litProgram); updateModelViewProjectionMatrix(litProgram, time); planet.render(); orbiter.render(); // Render unlit objects glUseProgram(unlitProgram); updateModelViewProjectionMatrix(unlitProgram, time); orbit.render(); widget.render(); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; }