Skip to content

Commit

Permalink
It's something like this, but...
Browse files Browse the repository at this point in the history
  • Loading branch information
sz3 committed Feb 20, 2021
1 parent f6b6496 commit 396939a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/lib/gui/gl_2d_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class gl_2d_display
{0, -1, -1, 0} // right 270
}};

static std::array<std::pair<GLfloat, GLfloat>, 8> computeShakePos(float dim)
static std::array<std::pair<GLfloat, GLfloat>, 8> computeShakePos(float src_dim, float target_dim)
{
float shake = 8.0f / dim; // 1080
float zero = (dim - 1000.0) / (dim*2);
float shake = 8.0f / target_dim;
float zero = (target_dim - src_dim + 3) / (target_dim*2);
return {{
{zero, zero},
{zero-shake, zero-shake},
Expand All @@ -50,10 +50,11 @@ class gl_2d_display
}

public:
gl_2d_display(unsigned width, unsigned height)
gl_2d_display(unsigned src_dim, unsigned target_dim)
: _p(create())
, _dimension(std::min(width, height))
, _shakePos(computeShakePos(_dimension))
, _srcDim(src_dim)
, _targetDim(target_dim)
, _shakePos(computeShakePos(_srcDim, _targetDim))
, _shake(_shakePos)
, _rotation(ROTATIONS)
{
Expand Down Expand Up @@ -90,7 +91,7 @@ class gl_2d_display

// scaling
GLuint scalingUniform = glGetUniformLocation(prog, "scaling");
glUniform1f(scalingUniform, 2 * (1008 / _dimension));
glUniform1f(scalingUniform, 2 * (_srcDim / _targetDim));

// pass in rotation matrix
GLuint rotateUniform = glGetUniformLocation(prog, "rot");
Expand Down Expand Up @@ -179,7 +180,8 @@ class gl_2d_display
std::array<GLuint, 3> _vbo;
GLuint _vao;
unsigned _i = 0;
float _dimension;
float _srcDim;
float _targetDim;

std::array<std::pair<GLfloat, GLfloat>, 8> _shakePos;
loop_iterator<decltype(_shakePos)> _shake;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gui/window_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class window_glfw : public window_interface<window_glfw>
glfwMakeContextCurrent(_w);
glfwSwapInterval(1);

_display = std::make_shared<cimbar::gl_2d_display>(width, height);
_display = std::make_shared<cimbar::gl_2d_display>(1024, std::min(width, height));
glGenTextures(1, &_texid);
init_opengl(width, height);
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm/cimbar_js/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int render()
if (_fes->block_count() > required)
{
_fes->reset();
_window->rotate(0);
_window->shake(0);
}

SimpleEncoder enc(_ecc, cimbar::Config::symbol_bits(), _colorBits);
Expand Down Expand Up @@ -102,7 +102,7 @@ int configure(unsigned color_bits)
_fes = nullptr;
_window->clear();
}
_window->rotate(0);
_window->shake(0);
}
}
return 0;
Expand Down

0 comments on commit 396939a

Please sign in to comment.