10 Commits
hopf ... master

Author SHA1 Message Date
62a0552bd8 Update readme.md 2020-01-04 12:57:21 -05:00
5866c190ca separate edge, face, and cell frame. face frame not implemented. 2018-12-21 09:17:33 -05:00
d77e347bf4 add tesseract frame 2018-12-21 09:07:24 -05:00
876f1edb85 refactor mesh composition 2018-12-21 08:42:14 -05:00
0b87482276 cube and tesseract frame toggles, rotation experiments 2018-12-20 22:46:58 -05:00
5580899074 tesseract frame 2018-12-20 21:12:39 -05:00
7211e9fc1a primitive functions 2018-12-20 20:50:04 -05:00
1e842b8dda rotating tesseract 2018-12-20 20:23:08 -05:00
1ee97c5154 working intersection - rotating simplex 2018-12-20 11:26:18 -05:00
78195ef8ec add versor dependency, generate rotor matrix 2018-12-19 22:59:38 -05:00
15 changed files with 490 additions and 155 deletions

3
.gitmodules vendored
View File

@@ -8,3 +8,6 @@
[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,5 +14,9 @@ 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,7 +1,3 @@
#include <utility>
#include <utility>
#ifndef GL_TEMPLATE_UTIL_H
#define GL_TEMPLATE_UTIL_H
@@ -73,6 +69,8 @@ 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);
}
@@ -88,6 +86,8 @@ 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,11 +1,3 @@
# OpenGL Application Template
# Simplex Visualizations
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+
Features are being merged into https://github.com/JCRaymond/toddcox-faster. Favor that instead.

View File

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

159
simplex/include/mesh.h Normal file
View File

@@ -0,0 +1,159 @@
#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,80 +1,40 @@
#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 <math.h>
#include <vsr/vsr.h>
glm::mat4 rotor_xy(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rotor(glm::vec4 u, glm::vec4 v, float angle) {
using Vec = vsr::euclidean_vector<4, float>;
return glm::mat4(
+c, s, 0, 0,
-s, c, 0, 0,
+0, 0, 1, 0,
+0, 0, 0, 1
);
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);
}
glm::mat4 rotor_xz(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rot_xy(float angle) { return rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 1, 0, 0), angle); }
return glm::mat4(
+c, 0, s, 0,
+0, 1, 0, 0,
-s, 0, c, 0,
+0, 0, 0, 1
);
}
glm::mat4 rot_xz(float angle) { return rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 1, 0), angle); }
glm::mat4 rotor_xw(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rot_xw(float angle) { return rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 0, 1), angle); }
return glm::mat4(
+c, 0, 0, s,
+0, 1, 0, 0,
+0, 0, 1, 0,
-s, 0, 0, c
);
}
glm::mat4 rot_yz(float angle) { return rotor(glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 1, 0), angle); }
glm::mat4 rotor_yz(float t) {
float c = cos(t);
float s = sin(t);
glm::mat4 rot_yw(float angle) { return rotor(glm::vec4(0, 1, 0, 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
);
}
glm::mat4 rot_zw(float angle) { return rotor(glm::vec4(0, 0, 1, 0), glm::vec4(0, 0, 0, 1), angle); }
#endif //GL_TEMPLATE_ROTOR_H

86
simplex/include/solids.h Normal file
View File

@@ -0,0 +1,86 @@
#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

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

20
simplex/shaders/sect.frag Normal file
View File

@@ -0,0 +1,20 @@
#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);
}

58
simplex/shaders/sect.geom Normal file
View File

@@ -0,0 +1,58 @@
#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

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

39
simplex/shaders/wire.geom Normal file
View File

@@ -0,0 +1,39 @@
#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,90 +1,84 @@
#include <unordered_map>
#include <vector>
#include <framework.h>
#include <util.h>
#include <gl_util.h>
#include <vsr/vsr.h>
#include "glmutil.h"
#include "mesh.h"
#include "rotor.h"
#include "solids.h"
#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 <cstdlib>
#include <cstdio>
#include <vector>
extern "C" {
__attribute__((dllexport)) DWORD NvOptimusEnablement = 0x00000001;
}
struct Matrices {
glm::mat4 model;
glm::vec4 offset;
glm::mat4 view;
glm::mat4 proj;
};
class GLApp : public App {
std::vector<glm::vec4> cell_verts{};
std::vector<unsigned> cell_elems{};
Mesh<4> mesh = Mesh<4>({}, {});
Matrices matrices{};
GLuint cell_array{};
GLuint cell_vert_buf{}, cell_elem_arr_buf{};
GLuint wire_prog{};
GLuint matrix_buffer{};
GLuint cell_vert_buf{}, cell_elem_arr_buf{}, matrix_buffer{};
GLuint matrix_binding_point = 1;
GLuint verts_binding_point = 1;
GLuint wire_prog{}, sect_prog{};
bool DRAW_WIRE = true;
void init() override {
cell_verts = {
glm::vec4(-0.5, -0.5, -0.5, -0.5),
glm::vec4(-0.5, -0.5, -0.5, +0.5),
glm::vec4(-0.5, -0.5, +0.5, -0.5),
glm::vec4(-0.5, -0.5, +0.5, +0.5),
glm::vec4(-0.5, +0.5, -0.5, -0.5),
glm::vec4(-0.5, +0.5, -0.5, +0.5),
glm::vec4(-0.5, +0.5, +0.5, -0.5),
glm::vec4(-0.5, +0.5, +0.5, +0.5),
glm::vec4(+0.5, -0.5, -0.5, -0.5),
glm::vec4(+0.5, -0.5, -0.5, +0.5),
glm::vec4(+0.5, -0.5, +0.5, -0.5),
glm::vec4(+0.5, -0.5, +0.5, +0.5),
glm::vec4(+0.5, +0.5, -0.5, -0.5),
glm::vec4(+0.5, +0.5, -0.5, +0.5),
glm::vec4(+0.5, +0.5, +0.5, -0.5),
glm::vec4(+0.5, +0.5, +0.5, +0.5),
};
cell_elems = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15,
0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15,
};
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 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);
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);
//endregion
//region Buffers
glGenBuffers(1, &cell_vert_buf);
glBindBuffer(GL_ARRAY_BUFFER, cell_vert_buf);
util::bufferData(GL_ARRAY_BUFFER, cell_verts, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
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_ELEMENT_ARRAY_BUFFER, cell_elem_arr_buf);
util::bufferData(GL_ELEMENT_ARRAY_BUFFER, cell_elems, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
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);
@@ -97,13 +91,12 @@ class GLApp : public App {
glGenVertexArrays(1, &cell_array);
glBindVertexArray(cell_array);
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, 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, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cell_elem_arr_buf);
glBindVertexArray(0);
//endregion
};
@@ -113,10 +106,18 @@ class GLApp : public App {
glfwGetFramebufferSize(getWindow(), &width, &height);
float ratio = (float) width / height;
matrices.model = rotor_yw(getTime() / 5) * rotor_xz(getTime() / 2);
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.view = glm::lookAt(glm::vec3(0, 0, -2), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
matrices.proj = glm::perspective(1.f, ratio, 0.1f, 10.0f);
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);
glBindBuffer(GL_UNIFORM_BUFFER, matrix_buffer);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(Matrices), &matrices);
@@ -133,11 +134,19 @@ class GLApp : public App {
glPointSize(10);
glLineWidth(2);
glEnable(GL_DEPTH_BUFFER_BIT);
glUseProgram(wire_prog);
glEnable(GL_DEPTH_TEST);
glBindVertexArray(cell_array);
glDrawElements(GL_LINES, (GLsizei) cell_elems.size(), GL_UNSIGNED_INT, nullptr);
// glDrawArrays(GL_POINTS, 0, (GLsizei) cell_verts.size());
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());
}
glBindVertexArray(0);
glFinish();
@@ -148,6 +157,10 @@ 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;
}
}
public:

1
vendor/versor vendored Submodule

Submodule vendor/versor added at 0d9dae3d71