Skip to content

Commit

Permalink
I don't know about this one chief
Browse files Browse the repository at this point in the history
  • Loading branch information
sz3 committed Feb 20, 2021
1 parent 355ef7c commit f6b6496
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
10 changes: 3 additions & 7 deletions src/exe/cimbar_send/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ int main(int argc, char** argv)
bool use_rotatecam = result.count("rotatecam");
bool use_shakycam = result.count("shakycam");

cimbar::shaky_cam cam(cimbar::Config::image_size(), 1080, 1080, dark);
cam.toggle();

cimbar::window w(cam.width(), cam.height(), "cimbar_send");
cimbar::window w(1080, 1080, "cimbar_send");
if (!w.is_good())
{
std::cerr << "failed to create window :(" << std::endl;
Expand All @@ -72,13 +69,12 @@ int main(int argc, char** argv)
bool running = true;
bool start = true;

auto draw = [&w, &cam, use_rotatecam, use_shakycam, delay, &running, &start] (const cv::Mat& frame, unsigned) {
auto draw = [&w, use_rotatecam, use_shakycam, delay, &running, &start] (const cv::Mat& frame, unsigned) {
if (!start and w.should_close())
return running = false;
start = false;

cv::Mat& windowImg = cam.draw(frame);
w.show(windowImg, delay);
w.show(frame, delay);
if (use_rotatecam)
w.rotate();
if (use_shakycam)
Expand Down
30 changes: 24 additions & 6 deletions src/lib/gui/gl_2d_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <GLES3/gl3.h>
#include <GLES2/gl2ext.h>

#include <iostream>
#include <memory>

namespace cimbar {
Expand All @@ -32,16 +33,27 @@ class gl_2d_display
{0, -1, -1, 0} // right 270
}};

static std::array<std::pair<GLfloat, GLfloat>, 8> computeShakePos(unsigned dim)
static std::array<std::pair<GLfloat, GLfloat>, 8> computeShakePos(float dim)
{
float shake = 8.0f / dim;
return {{ {0, 0}, {-shake, -shake}, {0, 0}, {shake, shake}, {0, 0}, {-shake, shake}, {0, 0}, {shake, -shake} }};
float shake = 8.0f / dim; // 1080
float zero = (dim - 1000.0) / (dim*2);
return {{
{zero, zero},
{zero-shake, zero-shake},
{zero, zero},
{zero+shake, zero+shake},
{zero, zero},
{zero-shake, zero+shake},
{zero, zero},
{zero+shake, zero-shake}
}};
}

public:
gl_2d_display(unsigned width, unsigned height)
: _p(create())
, _shakePos(computeShakePos(std::min(width, height)))
, _dimension(std::min(width, height))
, _shakePos(computeShakePos(_dimension))
, _shake(_shakePos)
, _rotation(ROTATIONS)
{
Expand Down Expand Up @@ -76,6 +88,10 @@ class gl_2d_display
glBindTexture(GL_TEXTURE_2D, texture);
glUniform1i(textureUniform, 0);

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

// pass in rotation matrix
GLuint rotateUniform = glGetUniformLocation(prog, "rot");
std::array<GLfloat, 4> rot = *_rotation;
Expand Down Expand Up @@ -133,14 +149,15 @@ class gl_2d_display
static const std::string VERTEX_SHADER_SRC = R"(#version 300 es
uniform mat2 rot;
uniform vec2 tform;
uniform float scaling;
in vec4 vert;
out vec2 texCoord;
void main() {
gl_Position = vec4(vert.x, vert.y, 0.0f, 1.0f);
vec2 ori = vec2(vert.x, vert.y);
ori *= rot;
texCoord = vec2(1.0f - ori.x, 1.0f - ori.y) / 2.0;
texCoord += tform;
texCoord = vec2(1.0f - ori.x, 1.0f - ori.y) / scaling;
texCoord -= tform;
})";

static const std::string FRAGMENT_SHADER_SRC = R"(#version 300 es
Expand All @@ -162,6 +179,7 @@ class gl_2d_display
std::array<GLuint, 3> _vbo;
GLuint _vao;
unsigned _i = 0;
float _dimension;

std::array<std::pair<GLfloat, GLfloat>, 8> _shakePos;
loop_iterator<decltype(_shakePos)> _shake;
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/cimbar_js/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int render()
}

_window->show(*img, 0);
_window->rotate();
_window->shake();
return ++_renders;
}

Expand Down
6 changes: 3 additions & 3 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ return {
{
console.log("init for canvas " + canvas);

Module._initialize_GL(1024, 1024);
Module._initialize_GL(1040, 1040);
Main.scaleCanvas(canvas, width, height);
Main.alignInvisibleClick(canvas);
},
Expand All @@ -45,8 +45,8 @@ return {
dim = height;
}
console.log(dim);
if (dim > 1024) {
dim = 1024;
if (dim > 1040) {
dim = 1040;
}
canvas.style.width = dim + "px";
canvas.style.height = dim + "px";
Expand Down

0 comments on commit f6b6496

Please sign in to comment.