From cc884ee71f017d9493da22565fc33e6828da123d Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Sun, 28 Jan 2018 22:26:04 +0100 Subject: Added point and click functionality --- src/render_cpu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'src/render_cpu.c') diff --git a/src/render_cpu.c b/src/render_cpu.c index 5065d4d..8f8d439 100644 --- a/src/render_cpu.c +++ b/src/render_cpu.c @@ -8,6 +8,15 @@ #include "render_cpu.h" #define HAVE_STRUCT_TIMESPEC +void idle_cpu_dummy(void) +{ +// glBindTexture(GL_TEXTURE_2D, config_cpu->tex); +// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_cpu->width, +// config_cpu->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_cpu->arr); +// glBindTexture(GL_TEXTURE_2D, 0); + glutPostRedisplay(); +} + void init_cpu(CpuConfig *config) { config_cpu = config; @@ -21,10 +30,15 @@ void init_cpu(CpuConfig *config) y_max = y_max_s; calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr); + t_old_cpu = glutGet(GLUT_ELAPSED_TIME); } void render_cpu(void) { + glBindTexture(GL_TEXTURE_2D, config_cpu->tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, config_cpu->width, + config_cpu->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, config_cpu->arr); + glBindTexture(GL_TEXTURE_2D, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, config_cpu->tex); glEnable(GL_TEXTURE_2D); @@ -66,6 +80,9 @@ void calculate_t(void *args) x_math = _args->x_min + ((d64) x * (_args->x_max - _args->x_min)) / config_cpu->width; y_math = _args->y_min + ((d64) (config_cpu->height - y) * (_args->y_max - _args->y_min)) / config_cpu->height; iterations = _args->sfunc(x_math, y_math, config_cpu->iterations); +// color[2].s0 = ((1.0f + native_cos(c)) * 0.5f) * 255; +// color[2].s1 = ((1.0f + native_cos(2.0f * c + 2.0f * 3.1416f / 3.0f)) * 0.5f) * 255; +// color[2].s2 = ((1.0f + native_cos(c - 2.0f * 3.1416f / 3.0f)) * 0.5f) * 255; _args->arr[COORDS(x, y, config_cpu->width)] = (((1<<24)-1)*iterations)/config_cpu->iterations; } } @@ -73,15 +90,14 @@ void calculate_t(void *args) void idle_cpu(void) { - static int t_old; int t = 0, delta = 0; do { t = glutGet(GLUT_ELAPSED_TIME); - delta = t - t_old; + delta = t - t_old_cpu; } while(delta < 16); // TODO: Hardcoded FPS - t_old = t; + t_old_cpu = t; calculate(x_min, y_min, x_max, y_max, config_cpu->set_func, config_cpu->arr); //glGenTextures(1, &tex); @@ -97,3 +113,35 @@ void idle_cpu(void) y_max = y_max_s - config_cpu->zoom_func(ft, (d64)1.0 - config_cpu->to_y); glutPostRedisplay(); } + +void keyboard_cpu(unsigned char key, int mouseX, int mouseY) +{ + switch(key) + { + case 'i': + config_cpu->iterations++; + break; + case 'd': + config_cpu->iterations--; + break; + } +} + +void mouse_cpu(int button, int state, int x, int y) +{ + if (state == GLUT_DOWN) + { + switch(button) + { + case GLUT_LEFT_BUTTON: + config_cpu->to_x = x_min + ((d64) x * (x_max - x_min)) / config_cpu->width; + config_cpu->to_y = y_min + ((d64) (config_cpu->height - y) * (y_max - y_min)) / config_cpu->height; + t_old_cpu = glutGet(GLUT_ELAPSED_TIME); + glutIdleFunc(idle_cpu); + break; + case GLUT_RIGHT_BUTTON: + glutIdleFunc(idle_cpu_dummy); + break; + } + } +} -- cgit v1.2.1 From f6ecdf87b278d62a7259bca573e81484ad9932f6 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Wed, 31 Jan 2018 23:23:46 +0100 Subject: improved controls - hold mouse left to zoom to desired point - hold mouse right to zoom out from that point - press/hold i to increase iterations - press/hold d to decrease iterations - dont press anything to pause --- src/render_cpu.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/render_cpu.c') diff --git a/src/render_cpu.c b/src/render_cpu.c index 8f8d439..64fc9ec 100644 --- a/src/render_cpu.c +++ b/src/render_cpu.c @@ -131,17 +131,26 @@ void mouse_cpu(int button, int state, int x, int y) { if (state == GLUT_DOWN) { - switch(button) + switch (button) { case GLUT_LEFT_BUTTON: - config_cpu->to_x = x_min + ((d64) x * (x_max - x_min)) / config_cpu->width; - config_cpu->to_y = y_min + ((d64) (config_cpu->height - y) * (y_max - y_min)) / config_cpu->height; - t_old_cpu = glutGet(GLUT_ELAPSED_TIME); - glutIdleFunc(idle_cpu); + if (config_cpu->speed < 0) + config_cpu->speed = (-1) * config_cpu->speed; break; case GLUT_RIGHT_BUTTON: - glutIdleFunc(idle_cpu_dummy); + if (config_cpu->speed > 0) + config_cpu->speed = (-1) * config_cpu->speed; break; } + config_cpu->to_x = x_min + + ((d64) x * (x_max - x_min)) / config_cpu->width; + config_cpu->to_y = y_min + + ((d64) y * (y_max - y_min)) / config_cpu->height; + t_old_cpu = glutGet(GLUT_ELAPSED_TIME); + glutIdleFunc(idle_cpu); + } + else if (state == GLUT_UP) + { + glutIdleFunc(idle_cpu_dummy); } } -- cgit v1.2.1