separate all utility headers and sources
This commit is contained in:
@@ -9,7 +9,13 @@ add_custom_command(
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
src/util/coxeter.cpp)
|
||||
src/util/coxeter.cpp
|
||||
src/util/files.cpp
|
||||
src/util/mesh.cpp
|
||||
src/util/mirrors.cpp
|
||||
src/util/numeric.cpp
|
||||
src/util/shader.cpp
|
||||
src/util/window.cpp)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||
|
||||
|
||||
5
cosets/include/files.hpp
Normal file
5
cosets/include/files.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string read_all_text(const std::string &file);
|
||||
19
cosets/include/mesh.hpp
Normal file
19
cosets/include/mesh.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "coxeter.hpp"
|
||||
#include "mirrors.hpp"
|
||||
#include "numeric.hpp"
|
||||
|
||||
glm::vec4 identity(const std::vector<glm::vec4> &normals, const std::vector<float> &coords);
|
||||
|
||||
glm::vec4 identity(const Mults &mults, const std::vector<float> &coords);
|
||||
|
||||
glm::vec4 center(const Mults &mults);
|
||||
|
||||
std::vector<glm::vec4> vertices(const Table *t_vert, const glm::vec4 ident);
|
||||
|
||||
std::vector<int> edges(const Table *t_vert);
|
||||
|
||||
std::vector<int> faces(const Table *t_vert);
|
||||
7
cosets/include/mirrors.hpp
Normal file
7
cosets/include/mirrors.hpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
#include "coxeter.hpp"
|
||||
|
||||
std::vector<glm::vec4> mirror(const Mults &mults);
|
||||
24
cosets/include/numeric.hpp
Normal file
24
cosets/include/numeric.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
glm::vec4 round(glm::vec4 f, int prec);
|
||||
|
||||
float dot(int n, glm::vec4 a, glm::vec4 b);
|
||||
|
||||
glm::vec4 project(glm::vec4 vec, glm::vec4 target);
|
||||
|
||||
glm::vec4 reflect(glm::vec4 vec, glm::vec4 axis);
|
||||
|
||||
glm::vec4 gram_schmidt_last(std::vector<glm::vec4> vecs);
|
||||
|
||||
glm::vec4 barycentric(std::vector<glm::vec4> basis, std::vector<float> coords);
|
||||
|
||||
std::vector<glm::vec4> plane_intersections(std::vector<glm::vec4> normals);
|
||||
|
||||
|
||||
std::vector<std::vector<int>> combinations(int N, int K);
|
||||
|
||||
std::vector<std::vector<int>> combinations(std::vector<int> N, int K);
|
||||
10
cosets/include/shader.hpp
Normal file
10
cosets/include/shader.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
|
||||
GLint build_shader(GLenum type, const std::string &name, const std::string &src);
|
||||
|
||||
GLint build_shader_file(GLenum type, const std::string &name, const std::string &file);
|
||||
|
||||
GLint build_program(const std::string &name, GLint vs, GLint fs);
|
||||
24
cosets/include/window.hpp
Normal file
24
cosets/include/window.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "glad/glad.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
class Window {
|
||||
protected:
|
||||
GLFWwindow *_window = nullptr;
|
||||
|
||||
public:
|
||||
virtual void init();
|
||||
|
||||
virtual void update();
|
||||
|
||||
virtual void render();
|
||||
|
||||
virtual void deinit();
|
||||
|
||||
void getBounds(int &width, int &height);
|
||||
|
||||
void swapbuffers();
|
||||
|
||||
void run();
|
||||
};
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "util/window.hpp"
|
||||
#include "util/shader.hpp"
|
||||
#include "window.hpp"
|
||||
#include "shader.hpp"
|
||||
#include "mesh.hpp"
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
|
||||
#include "util/mesh.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CosetsWindow : public Window {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include "files.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <streambuf>
|
||||
|
||||
std::string read_all_text(const std::string &file) {
|
||||
@@ -1,17 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include "coxeter.hpp"
|
||||
#include "mirrors.hpp"
|
||||
#include "numeric.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
template<int N>
|
||||
std::vector<std::vector<int>> coxeter_rels() {
|
||||
std::vector<std::vector<int>> rels{};
|
||||
|
||||
return rels;
|
||||
}
|
||||
#include "mesh.hpp"
|
||||
|
||||
glm::vec4 identity(const std::vector<glm::vec4> &normals, const std::vector<float> &coords) {
|
||||
const std::vector<glm::vec4> corners = plane_intersections(normals);
|
||||
@@ -1,12 +1,6 @@
|
||||
#pragma once
|
||||
#include "mirrors.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
#include "numeric.hpp"
|
||||
#include "coxeter.hpp"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
#include "numeric.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
glm::vec4 round(glm::vec4 f, int prec) {
|
||||
auto dec = (float) pow(10, prec);
|
||||
@@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
#include "shader.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "files.hpp"
|
||||
|
||||
55
cosets/src/util/window.cpp
Normal file
55
cosets/src/util/window.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "window.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
void Window::init() {}
|
||||
|
||||
void Window::update() {}
|
||||
|
||||
void Window::render() {}
|
||||
|
||||
void Window::deinit() {}
|
||||
|
||||
void Window::getBounds(int &width, int &height) {
|
||||
glfwGetFramebufferSize(_window, &width, &height);
|
||||
}
|
||||
|
||||
void Window::swapbuffers() {
|
||||
glfwSwapBuffers(_window);
|
||||
}
|
||||
|
||||
void Window::run() {
|
||||
int _gl_major = 4, _gl_minor = 0;
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, _gl_major);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, _gl_minor);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 8);
|
||||
|
||||
|
||||
_window = glfwCreateWindow(1920, 1080, "GLFW App", nullptr, nullptr);
|
||||
if (!_window) {
|
||||
fprintf(stderr, "Failed to create window;");
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(_window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
glfwSwapInterval(0);
|
||||
|
||||
init();
|
||||
|
||||
while (!glfwWindowShouldClose(_window)) {
|
||||
update();
|
||||
render();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
deinit();
|
||||
|
||||
glfwDestroyWindow(_window);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
class Window {
|
||||
protected:
|
||||
GLFWwindow *_window = nullptr;
|
||||
|
||||
public:
|
||||
virtual void init() {}
|
||||
|
||||
virtual void update() {}
|
||||
|
||||
virtual void render() {}
|
||||
|
||||
virtual void deinit() {}
|
||||
|
||||
void getBounds(int &width, int &height) {
|
||||
glfwGetFramebufferSize(_window, &width, &height);
|
||||
}
|
||||
|
||||
void swapbuffers() {
|
||||
glfwSwapBuffers(_window);
|
||||
}
|
||||
|
||||
void run() {
|
||||
int _gl_major = 4, _gl_minor = 0;
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, _gl_major);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, _gl_minor);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 8);
|
||||
|
||||
|
||||
_window = glfwCreateWindow(1920, 1080, "GLFW App", nullptr, nullptr);
|
||||
if (!_window) {
|
||||
fprintf(stderr, "Failed to create window;");
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(_window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
glfwSwapInterval(0);
|
||||
|
||||
init();
|
||||
|
||||
while (!glfwWindowShouldClose(_window)) {
|
||||
update();
|
||||
render();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
deinit();
|
||||
|
||||
glfwDestroyWindow(_window);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user