1 Commits
master ... hopf

Author SHA1 Message Date
d98a596a7b hopf fibration visualization - add arbitrary animations 2019-01-11 01:35:43 -05:00
15 changed files with 228 additions and 487 deletions

3
.gitmodules vendored
View File

@@ -8,6 +8,3 @@
[submodule "vendor/glm"]
path = vendor/glm
url = https://github.com/g-truc/glm.git
[submodule "vendor/versor"]
path = vendor/versor
url = https://github.com/wolftype/versor.git

View File

@@ -14,9 +14,5 @@ add_subdirectory(vendor/glfw)
option(GLM_TEST_ENABLE OFF)
add_subdirectory(vendor/glm)
add_subdirectory(vendor/versor)
get_property(VSR_INCLUDE_DIR GLOBAL PROPERTY VSR_INCLUDE_DIR)
target_include_directories(vsr PUBLIC ${VSR_INCLUDE_DIR})
add_subdirectory(framework)
add_subdirectory(simplex)

View File

@@ -1,3 +1,7 @@
#include <utility>
#include <utility>
#ifndef GL_TEMPLATE_UTIL_H
#define GL_TEMPLATE_UTIL_H
@@ -69,8 +73,6 @@ namespace util {
return buildShader(kind, "VERTEX", paths);
case GL_FRAGMENT_SHADER:
return buildShader(kind, "FRAGMENT", paths);
case GL_GEOMETRY_SHADER:
return buildShader(kind, "GEOMETRY", paths);
default:
return buildShader(kind, "?", paths);
}
@@ -86,8 +88,6 @@ namespace util {
return buildShader(GL_VERTEX_SHADER, paths);
} else if (ext == ".frag") {
return buildShader(GL_FRAGMENT_SHADER, paths);
} else if (ext == ".geom") {
return buildShader(GL_GEOMETRY_SHADER, paths);
} else {
fprintf(stderr, "Cannot parse path %s\n", path.c_str());
return 0;

View File

@@ -1,3 +1,11 @@
# Simplex Visualizations
# OpenGL Application Template
Features are being merged into https://github.com/JCRaymond/toddcox-faster. Favor that instead.
A template and framework for building OpenGL applications in C++.
### Libraries:
* glad (OpenGL Bindings)
* glfw (Window and OpenGL Context Management)
* glm (Linear Algebra)
Requires CMake 3.10+

View File

@@ -7,7 +7,6 @@ target_link_libraries(${PROJECT_NAME}
glad
glm
glfw
vsr
framework)
target_include_directories(${PROJECT_NAME}
@@ -15,7 +14,7 @@ target_include_directories(${PROJECT_NAME}
include)
set(SHADERS
shaders/wire.frag
shaders/main.frag
shaders/main.vert)
add_custom_target(shaders DEPENDS ${SHADERS})

View File

@@ -1,159 +0,0 @@
#ifndef SIMPLEX_MESH_H
#define SIMPLEX_MESH_H
#include <algorithm>
#include <vector>
#include <glm/mat4x4.hpp>
#include <glm/vec4.hpp>
template<unsigned int prim>
struct Mesh {
std::vector<glm::vec4> verts;
std::vector<unsigned> inds;
Mesh(std::vector<glm::vec4> verts, std::vector<unsigned> inds)
: verts(std::move(verts)), inds(std::move(inds)) {}
unsigned size() {
return (unsigned) inds.size() / prim;
}
};
template<unsigned int prim>
Mesh<prim> concat(Mesh<prim> m, Mesh<prim> n) {
Mesh<prim> res({}, {});
for (auto v: m.verts) res.verts.push_back(v);
for (auto v: n.verts) res.verts.push_back(v);
auto off = (unsigned) m.verts.size();
for (auto i: m.inds) res.inds.push_back(i);
for (auto i: n.inds) res.inds.push_back(off + i);
return res;
}
template<unsigned int prim>
Mesh<prim> transform(Mesh<prim> m, glm::mat4 mat) {
Mesh<prim> res(m.verts, m.inds);
for (auto &vert : res.verts)
vert = mat * vert;
return res;
}
template<unsigned int prim>
Mesh<prim> offset(Mesh<prim> m, glm::vec4 off) {
Mesh<prim> res(m.verts, m.inds);
for (auto &vert : res.verts)
vert += off;
return res;
}
template<unsigned int prim>
Mesh<prim> scale(Mesh<prim> m, glm::vec4 scl) {
Mesh<prim> res(m.verts, m.inds);
for (auto &vert : res.verts)
vert *= scl;
return res;
}
template<unsigned int prim>
Mesh<prim> scale(Mesh<prim> m, float scl) {
return scale(m, glm::vec4(scl));
}
template<unsigned int prim>
Mesh<prim + 1> pyramid(Mesh<prim> m, glm::vec4 apex) {
Mesh<prim + 1> res(m.verts, {});
res.verts.push_back(apex);
auto apex_ind = (unsigned) res.verts.size() - 1;
for (int i = 0; i < m.size(); ++i) {
for (int j = 0; j < prim; ++j) {
res.inds.push_back(m.inds[i * prim + j]);
}
res.inds.push_back(apex_ind);
}
return res;
}
template<unsigned int prim>
Mesh<prim + 1> fill(Mesh<prim> m) {
Mesh<prim + 1> res(m.verts, {});
for (int i = 0; i < m.size(); ++i) {
for (int j = 0; j < prim; ++j) {
res.inds.push_back(m.inds[i * prim + j]);
}
res.inds.push_back(0);
}
return res;
}
template<unsigned int prim>
Mesh<prim + 1> join(Mesh<prim> m, Mesh<prim> n) {
Mesh<prim + 1> res({}, {});
for (auto v : m.verts) res.verts.push_back(v);
for (auto v : n.verts) res.verts.push_back(v);
auto off = (unsigned) m.verts.size();
auto size = (int) std::min(m.inds.size(), n.inds.size());
for (int i = 0; i < size; i += prim) {
for (int j = 0; j < prim; ++j) {
for (int x = j; x < prim; ++x)
res.inds.push_back(m.inds[i + x]);
for (int x = 0; x <= j; ++x)
res.inds.push_back(off + n.inds[i + x]);
}
}
return res;
}
template<unsigned int prim>
Mesh<prim + 1> joinCap(Mesh<prim> m, Mesh<prim> n) {
return concat(join(m, n), concat(fill(m), fill(n)));
}
template<unsigned int prim>
Mesh<prim + 1> thicken(const Mesh<prim> &m, glm::vec4 width) {
return joinCap(m - width / 2.f, m + width / 2.f);
}
template<unsigned int prim>
Mesh<prim> operator+(Mesh<prim> m, Mesh<prim> n) { return concat(m, n); }
template<unsigned int prim>
Mesh<prim> operator+(Mesh<prim> m, glm::vec4 off) { return offset(m, off); }
template<unsigned int prim>
Mesh<prim> operator-(Mesh<prim> m, glm::vec4 off) { return offset(m, -off); }
template<unsigned int prim>
Mesh<prim> operator*(Mesh<prim> m, glm::vec4 scl) { return scale(m, scl); }
template<unsigned int prim>
Mesh<prim> operator/(Mesh<prim> m, glm::vec4 scl) { return scale(m, 1.f / scl); }
template<unsigned int prim>
Mesh<prim> operator*(Mesh<prim> m, float scl) { return scale(m, scl); }
template<unsigned int prim>
Mesh<prim> operator/(Mesh<prim> m, float scl) { return scale(m, 1.f / scl); }
template<unsigned int prim>
Mesh<prim> operator*(glm::mat4 mat, Mesh<prim> m) { return transform(m, mat); }
template<unsigned int prim>
Mesh<prim> simplify(Mesh<prim> m) {
// todo remove redundant vertices and primitives
return Mesh<prim>({}, {});
}
#endif //SIMPLEX_MESH_H

View File

@@ -1,40 +1,80 @@
#ifndef GL_TEMPLATE_ROTOR_H
#define GL_TEMPLATE_ROTOR_H
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <vsr/vsr.h>
#include <math.h>
glm::mat4 rotor(glm::vec4 u, glm::vec4 v, float angle) {
using Vec = vsr::euclidean_vector<4, float>;
glm::mat4 rotor_xy(float t) {
float c = cos(t);
float s = sin(t);
auto eu = *((Vec *) (void *) &u);
auto ev = *((Vec *) (void *) &v);
auto biv = (eu ^ ev).unit() * angle / 2;
Vec col[4] = {
Vec(1, 0, 0, 0).rotate(biv),
Vec(0, 1, 0, 0).rotate(biv),
Vec(0, 0, 1, 0).rotate(biv),
Vec(0, 0, 0, 1).rotate(biv)
};
return glm::make_mat4((float *) col);
return glm::mat4(
+c, s, 0, 0,
-s, c, 0, 0,
+0, 0, 1, 0,
+0, 0, 0, 1
);
}
glm::mat4 rot_xy(float angle) { return rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 1, 0, 0), angle); }
glm::mat4 rotor_xz(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rot_xz(float angle) { return rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 1, 0), angle); }
return glm::mat4(
+c, 0, s, 0,
+0, 1, 0, 0,
-s, 0, c, 0,
+0, 0, 0, 1
);
}
glm::mat4 rot_xw(float angle) { return rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 0, 1), angle); }
glm::mat4 rotor_xw(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rot_yz(float angle) { return rotor(glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 1, 0), angle); }
return glm::mat4(
+c, 0, 0, s,
+0, 1, 0, 0,
+0, 0, 1, 0,
-s, 0, 0, c
);
}
glm::mat4 rot_yw(float angle) { return rotor(glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 0, 1), angle); }
glm::mat4 rotor_yz(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rot_zw(float angle) { return rotor(glm::vec4(0, 0, 1, 0), glm::vec4(0, 0, 0, 1), angle); }
return glm::mat4(
1, +0, 0, 0,
0, +c, s, 0,
0, -s, c, 0,
0, +0, 0, 1
);
}
glm::mat4 rotor_yw(float t) {
float c = cos(t);
float s = sin(t);
return glm::mat4(
1, +0, 0, 0,
0, +c, 0, s,
0, +0, 1, 0,
0, -s, 0, c
);
}
glm::mat4 rotor_zw(float t) {
float c = cos(t);
float s = sin(t);
return glm::mat4(
1, 0, +0, 0,
0, 1, +0, 0,
0, 0, +c, s,
0, 0, -s, c
);
}
#endif //GL_TEMPLATE_ROTOR_H

View File

@@ -1,86 +0,0 @@
#ifndef SIMPLEX_SOLIDS_H
#define SIMPLEX_SOLIDS_H
#include "mesh.h"
#include "rotor.h"
static auto T = (float) PI / 2;
Mesh<2> poly(int sides) {
Mesh<2> res({}, {});
auto t = (float) (PI * 2 / sides);
float t0 = t / 2;
auto r = 1 / cos(t0);
for (int i = 0; i < sides; i++) {
glm::vec2 p = r * glm::vec2(cos(t0 + t * i), sin(t0 + t * i));
res.verts.emplace_back(p, 0, 0);
}
for (unsigned i = 0; i < sides - 1; i++) {
res.inds.push_back(i);
res.inds.push_back(i + 1);
}
return res;
}
Mesh<3> cube() {
glm::vec4 off = glm::vec4(0, 0, 1, 0);
Mesh<3> face = fill(poly(4));
Mesh<3> pair = (face + off) + (face - off);
return pair +
rot_xz(T) * pair +
rot_yz(T) * pair;
}
Mesh<4> tesseract() {
glm::vec4 off = glm::vec4(0, 0, 0, 1);
Mesh<4> cell = fill(cube());
Mesh<4> pair = (cell + off) + (cell - off);
return pair +
rot_xw(T) * pair +
rot_yw(T) * pair +
rot_zw(T) * pair;
}
Mesh<4> tesseract_edge_frame(float width) {
Mesh<4> edge = tesseract() * glm::vec4(width, width, width, 1);
auto o = glm::vec3(1 - width);
Mesh<4> set = (edge + glm::vec4(+o.x, +o.y, +o.z, 0)) +
(edge + glm::vec4(+o.x, +o.y, -o.z, 0)) +
(edge + glm::vec4(+o.x, -o.y, +o.z, 0)) +
(edge + glm::vec4(+o.x, -o.y, -o.z, 0)) +
(edge + glm::vec4(-o.x, +o.y, +o.z, 0)) +
(edge + glm::vec4(-o.x, +o.y, -o.z, 0)) +
(edge + glm::vec4(-o.x, -o.y, +o.z, 0)) +
(edge + glm::vec4(-o.x, -o.y, -o.z, 0));
return set +
rot_xw(T) * set +
rot_yw(T) * set +
rot_zw(T) * set;
}
Mesh<4> tesseract_face_frame(float width) {
//todo - not even sure what this would mean, but it should be possible.
return Mesh<4>({}, {});
}
Mesh<4> tesseract_cell_frame(float width) {
glm::vec4 off = glm::vec4(0, 0, 0, 1);
Mesh<4> cell = join(cube() * (1 - width), cube());
cell = cell + (cell - glm::vec4(0, 0, 0, width));
Mesh<4> pair = (cell + off) + (cell + off) * -1.f;
return pair +
rot_xw(T) * pair +
rot_yw(T) * pair +
rot_zw(T) * pair;
}
#endif //SIMPLEX_SOLIDS_H

View File

@@ -11,11 +11,7 @@ vec3 hsv2rgb(vec3 c) {
}
void main() {
float h = pos.w / 3 + .6;
float s = 1;
float v = smoothstep(3, -3, pos.z) / 2;
vec3 hsv = vec3(h, s, v);
vec3 hsv = vec3(pos.w/3 + .6, 1, 1);
fcolor = vec4(hsv2rgb(hsv), 1);
}

View File

@@ -1,11 +1,16 @@
#version 440 core
layout(location=0) in ivec4 vInds;
layout(location=0) in vec4 pos4;
out ivec4 inds;
layout(std140, binding=1) uniform Matrices {
mat4 model;
mat4 view;
mat4 proj;
};
out vec4 pos;
void main() {
inds = vInds;
gl_Position = vec4(0, 0, 0, 1);
pos = model * pos4;
gl_Position = proj * view * vec4(pos.xyz, 1);
}

View File

@@ -1,20 +0,0 @@
#version 440 core
out vec4 fcolor;
in vec4 pos;
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main() {
// float h = pos.w / 3 + .6;
float h = 0;
float s = 0;
float v = smoothstep(4, -4, pos.z);
fcolor = vec4(hsv2rgb(vec3(h, s, v)), 1);
}

View File

@@ -1,58 +0,0 @@
#version 440 core
layout(points) in;
layout(triangle_strip, max_vertices=4) out;
layout(std430, binding=1) buffer Positions {
vec4 verts[];
};
layout(std140, binding=1) uniform Matrices {
mat4 model;
vec4 offset;
mat4 view;
mat4 proj;
};
in ivec4 inds[];
out vec4 pos;
void emit(vec4 v) {
pos = v;
gl_Position = proj * view * vec4(v.xyz, 1);
EmitVertex();
}
void main() {
vec4 pos4[4];
for(int i = 0; i < 4; ++i) pos4[i] = offset + model * verts[inds[0][i]];
int lo[4], L = 0;
int hi[4], H = 0;
for(int i = 0; i < 4; ++i) {
if (pos4[i].w < 0) {
lo[L++] = i;
} else {
hi[H++] = i;
}
}
vec4 sect[4]; int S = 0;
for (int l = 0; l < L; ++l) {
for (int h = 0; h < H; ++h) {
vec4 a = pos4[lo[l]];
vec4 b = pos4[hi[h]];
sect[S++] = (0 - a.w) / (b.w - a.w) * (b-a) + a;
}
}
for(int s = 0; s < S; ++s) {
emit(sect[s]);
}
EndPrimitive();
}

View File

@@ -1,39 +0,0 @@
#version 440 core
layout(points) in;
layout(line_strip, max_vertices=20) out;
layout(std430, binding=1) buffer Positions {
vec4 verts[];
};
layout(std140, binding=1) uniform Matrices {
mat4 model;
vec4 offset;
mat4 view;
mat4 proj;
};
in ivec4 inds[];
out vec4 pos;
void emit(vec4 v) {
pos = v;
gl_Position = proj * view * vec4(v.xyz, 1 - v.w / 2);
EmitVertex();
}
void main() {
vec4 pos4[4];
for(int i = 0; i < 4; ++i) pos4[i] = offset + model * verts[inds[0][i]];
for(int i = 0; i < 4; ++i) {
for(int j = i + 1; j < 4; ++j) {
emit(pos4[i]);
emit(pos4[j]);
EndPrimitive();
}
}
}

View File

@@ -1,84 +1,137 @@
#include <unordered_map>
#include <vector>
#include <framework.h>
#include <gl_util.h>
#include <vsr/vsr.h>
#include <util.h>
#include "glmutil.h"
#include "mesh.h"
#include "rotor.h"
#include "solids.h"
extern "C" {
__attribute__((dllexport)) DWORD NvOptimusEnablement = 0x00000001;
}
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/trigonometric.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <glm/ext.hpp>
#include <cstdlib>
#include <cstdio>
#include <vector>
#define PI 3.14159f
struct Matrices {
glm::mat4 model;
glm::vec4 offset;
glm::mat4 view;
glm::mat4 proj;
};
class GLApp : public App {
Mesh<4> mesh = Mesh<4>({}, {});
void push_point(
std::vector<glm::vec4> &verts, std::vector<unsigned> &elems,
float xi_1, float xi_2, float eta) {
float x = cos((xi_2 + xi_1) / 2) * cos(eta);
float y = sin((xi_2 + xi_1) / 2) * cos(eta);
float z = cos((xi_2 - xi_1) / 2) * sin(eta);
float w = sin((xi_2 - xi_1) / 2) * sin(eta);
verts.emplace_back(x / (1 - w), y / (1 - w), z / (1 - w), w); // stereographic
// verts.emplace_back(x, y, z, w); // orthographic
}
void push_circle(
std::vector<glm::vec4> &verts, std::vector<unsigned> &elems,
float xi_1, float eta) {
const auto N = (unsigned) 128;
const auto R = (unsigned) verts.size();
for (unsigned k = 0; k < N; ++k) {
float xi_2 = 4 * PI * k / N;
push_point(verts, elems, xi_1, xi_2, eta);
elems.push_back(R + (k) % N);
elems.push_back(R + (k + 1) % N);
}
}
class GLApp : public App {
std::vector<glm::vec4> cell_verts{};
std::vector<unsigned> cell_elems{};
Matrices matrices{};
GLuint cell_array{};
GLuint cell_vert_buf{}, cell_elem_arr_buf{};
GLuint wire_prog{};
GLuint cell_vert_buf{}, cell_elem_arr_buf{}, matrix_buffer{};
GLuint matrix_buffer{};
GLuint matrix_binding_point = 1;
GLuint verts_binding_point = 1;
GLuint wire_prog{}, sect_prog{};
void generate() {
cell_verts.clear();
cell_elems.clear();
bool DRAW_WIRE = true;
// xi_1 from 0 to 2pi
// xi_2 from 0 to 4pi
// eta from 0 to pi/2
const unsigned M = 2;
const unsigned N = 32;
const float PAD = 0.025;
for (unsigned j = 0; j <= M; ++j) {
float eta = (PI / 2 - PAD * 2) * (1 + cos(getTime() / 6)) / 2 * j / M + PAD;
for (unsigned k = 0; k < N; ++k) {
float xi_1 = PI * 2 * k / N;
push_circle(cell_verts, cell_elems, xi_1, eta);
}
}
const unsigned O = 256;
for (unsigned k = 0; k < O; ++k) {
float t = (float) k / O;
int loops = 10;
float xi_1 = PI * 2 * (t + cos(loops * PI * t + getTime() / 6) / loops);
float eta =
sin(loops * PI * t) / loops + .5f + (cos(xi_1 + getTime() * 2) + cos(xi_1 + getTime() * 1.6f)) / 12;
push_circle(cell_verts, cell_elems, xi_1, eta);
}
glBindBuffer(GL_ARRAY_BUFFER, cell_vert_buf);
util::bufferData(GL_ARRAY_BUFFER, cell_verts, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cell_elem_arr_buf);
util::bufferData(GL_ELEMENT_ARRAY_BUFFER, cell_elems, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void init() override {
mesh = tesseract_cell_frame(.125f);
//region Uniforms
matrices = {
glm::identity<glm::mat4>(),
glm::vec4(0),
glm::identity<glm::mat4>(),
glm::identity<glm::mat4>(),
};
//endregion
//region Shaders
GLuint main_vs = util::buildShader(GL_VERTEX_SHADER, {"shaders/main.vert"});
GLuint sect_fs = util::buildShader(GL_FRAGMENT_SHADER, {"shaders/sect.frag"});
GLuint wire_fs = util::buildShader(GL_FRAGMENT_SHADER, {"shaders/wire.frag"});
GLuint sect_gs = util::buildShader(GL_GEOMETRY_SHADER, {"shaders/sect.geom"});
GLuint wire_gs = util::buildShader(GL_GEOMETRY_SHADER, {"shaders/wire.geom"});
wire_prog = util::buildProgram(false, {main_vs, wire_fs, wire_gs});
sect_prog = util::buildProgram(false, {main_vs, sect_fs, sect_gs});
glDeleteShader(main_vs);
glDeleteShader(sect_fs);
glDeleteShader(wire_fs);
glDeleteShader(sect_gs);
glDeleteShader(wire_gs);
GLuint vs = util::buildShader(GL_VERTEX_SHADER, {"shaders/main.vert"});
GLuint fs = util::buildShader(GL_FRAGMENT_SHADER, {"shaders/main.frag"});
wire_prog = util::buildProgram(false, {vs, fs});
glDeleteShader(vs);
glDeleteShader(fs);
//endregion
//region Buffers
glGenBuffers(1, &cell_vert_buf);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, verts_binding_point, cell_vert_buf);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, cell_vert_buf);
util::bufferData(GL_SHADER_STORAGE_BUFFER, mesh.verts, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glGenBuffers(1, &cell_elem_arr_buf);
glBindBuffer(GL_ARRAY_BUFFER, cell_elem_arr_buf);
util::bufferData(GL_ARRAY_BUFFER, mesh.inds, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &matrix_buffer);
glBindBufferBase(GL_UNIFORM_BUFFER, matrix_binding_point, matrix_buffer);
@@ -87,16 +140,19 @@ class GLApp : public App {
glBindBuffer(GL_UNIFORM_BUFFER, 0);
//endregion
generate();
//region Vertex Arrays
glGenVertexArrays(1, &cell_array);
glBindVertexArray(cell_array);
glBindBuffer(GL_ARRAY_BUFFER, cell_elem_arr_buf);
auto ind_loc = (GLuint) glGetAttribLocation(wire_prog, "vInds");
glEnableVertexAttribArray(ind_loc);
glVertexAttribIPointer(ind_loc, 4, GL_UNSIGNED_INT, sizeof(int) * 4, (void *) nullptr);
glBindBuffer(GL_ARRAY_BUFFER, cell_vert_buf);
auto pos4_loc = (GLuint) glGetAttribLocation(wire_prog, "pos4");
glEnableVertexAttribArray(pos4_loc);
glVertexAttribPointer(pos4_loc, 4, GL_FLOAT, GL_FALSE, sizeof(glm::vec4), (void *) nullptr);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cell_elem_arr_buf);
glBindVertexArray(0);
//endregion
};
@@ -106,22 +162,21 @@ class GLApp : public App {
glfwGetFramebufferSize(getWindow(), &width, &height);
float ratio = (float) width / height;
matrices.model = glm::identity<glm::mat4>() *
// rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 0, 1), getTime() / 3) *
// rotor(glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 1, 0), getTime() / 3) *
// matrices.model = rotor_yw(getTime() / 5) * rotor_xz(getTime() / 2);
//
float t = getTime() / 5;
// matrices.view = glm::lookAt(glm::vec3(0, 0, 0), -glm::vec3(cos(t), sin(t), .25), glm::vec3(0, 0, 1));
rotor(glm::vec4(1, 1, 1, 0), glm::vec4(0, 0, 0, 1), getTime() / 3) *
rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 1, 0), getTime() / 3) *
1.f;
matrices.offset = glm::vec4(0,0,0,sin(getTime() / 2) * 0.9f);
matrices.view = glm::lookAt(glm::vec3(0, 0, -4), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
matrices.proj = glm::perspective(1.f, ratio, 0.1f, 20.0f);
// matrices.proj = glm::perspective(1.f, ratio, 0.1f, 100.0f);
float W = 2;
float D = 10;
matrices.proj = glm::ortho(-ratio * W, ratio * W, -W, W, -D, D);
glBindBuffer(GL_UNIFORM_BUFFER, matrix_buffer);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(Matrices), &matrices);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
generate();
}
void display() override {
@@ -132,21 +187,13 @@ class GLApp : public App {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPointSize(10);
glLineWidth(2);
glLineWidth(5);
glEnable(GL_DEPTH_TEST);
glUseProgram(wire_prog);
glBindVertexArray(cell_array);
glUseProgram(sect_prog);
glDrawArrays(GL_POINTS, 0, mesh.size());
if (DRAW_WIRE) {
glClear(GL_DEPTH_BUFFER_BIT);
glUseProgram(wire_prog);
glDrawArrays(GL_POINTS, 0, mesh.size());
}
glDrawElements(GL_LINES, (GLsizei) cell_elems.size(), GL_UNSIGNED_INT, nullptr);
// glDrawArrays(GL_POINTS, 0, (GLsizei) cell_verts.size());
glBindVertexArray(0);
glFinish();
@@ -157,10 +204,26 @@ class GLApp : public App {
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) {
glfwSetWindowShouldClose(getWindow(), true);
}
}
if (action == GLFW_PRESS && key == GLFW_KEY_SPACE) {
DRAW_WIRE = !DRAW_WIRE;
glm::vec3 euler{};
double x_ = 0, y_ = 0;
void onCursorPos(double x, double y) override {
auto dx = (float) (x - x_) / 100;
auto dy = (float) (y - y_) / 100;
if (glfwGetMouseButton(getWindow(), 0)) {
euler += glm::vec3(dy, 0, dx);
matrices.view = glm::identity<glm::mat4>();
matrices.view = glm::rotate(matrices.view, euler.x, glm::vec3(1, 0, 0));
matrices.view = glm::rotate(matrices.view, euler.y, glm::vec3(0, 1, 0));
matrices.view = glm::rotate(matrices.view, euler.z, glm::vec3(0, 0, 1));
}
x_ = x;
y_ = y;
}
public:

1
vendor/versor vendored

Submodule vendor/versor deleted from 0d9dae3d71