feat(input): Add arrow key input
This commit is contained in:
1
Makefile
1
Makefile
@@ -16,6 +16,7 @@ EXAMPLES = \
|
|||||||
example/riemman \
|
example/riemman \
|
||||||
example/n-cube \
|
example/n-cube \
|
||||||
example/n-hilbert-cube \
|
example/n-hilbert-cube \
|
||||||
|
example/light-cone \
|
||||||
example/lens
|
example/lens
|
||||||
|
|
||||||
CFLAGS = \
|
CFLAGS = \
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ void mobius(float *d_surface, int *coord, unsigned char *grid)
|
|||||||
|
|
||||||
void torus(float *d_surface, int *coord, unsigned char *grid)
|
void torus(float *d_surface, int *coord, unsigned char *grid)
|
||||||
{
|
{
|
||||||
float u = (2 * M_PI) * ((float)coord[0] / grid[0]);
|
float u = (M_PI) * ((float)coord[0] / grid[0]) + M_PI;
|
||||||
float v = (2 * M_PI) * ((float)coord[1] / grid[1]);
|
float v = (2 * M_PI) * ((float)coord[1] / grid[1]);
|
||||||
|
|
||||||
d_surface[0] = (1 + 0.5 * cos(v)) * cos(u);
|
d_surface[0] = (1 + 0.5 * cos(v)) * cos(u);
|
||||||
@@ -57,12 +57,14 @@ int main(void)
|
|||||||
{
|
{
|
||||||
unsigned char i = 0;
|
unsigned char i = 0;
|
||||||
const char *file_name[] = {"mobius.klein", "torus.klein", "klein.klein"};
|
const char *file_name[] = {"mobius.klein", "torus.klein", "klein.klein"};
|
||||||
struct parm parametrization[] = {{
|
struct parm parametrization[] = {
|
||||||
.grid = (unsigned char[]){16, 4},
|
{
|
||||||
.m = 2,
|
.grid = (unsigned char[]){16, 4},
|
||||||
.n = 3,
|
|
||||||
.f = mobius,
|
.m = 2,
|
||||||
},
|
.n = 3,
|
||||||
|
.f = mobius,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.grid = (unsigned char[]){16, 8},
|
.grid = (unsigned char[]){16, 8},
|
||||||
.m = 2,
|
.m = 2,
|
||||||
@@ -74,9 +76,10 @@ int main(void)
|
|||||||
.m = 2,
|
.m = 2,
|
||||||
.n = 4,
|
.n = 4,
|
||||||
.f = klein,
|
.f = klein,
|
||||||
}};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
struct klein klein;
|
struct klein klein;
|
||||||
printf("writing %s\n", file_name[i]);
|
printf("writing %s\n", file_name[i]);
|
||||||
|
|||||||
22
src/input.c
22
src/input.c
@@ -187,6 +187,28 @@ quat_t poll_input(window_t window)
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey((GLFWwindow *)window, GLFW_KEY_UP) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
glm_quatv(p, ANGLE, (vec3){1,0,0});
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (glfwGetKey((GLFWwindow *)window, GLFW_KEY_DOWN) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
glm_quatv(p, -ANGLE, (vec3){1,0,0});
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (glfwGetKey((GLFWwindow *)window, GLFW_KEY_RIGHT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
glm_quatv(p, ANGLE, (vec3){0,1,0});
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (glfwGetKey((GLFWwindow *)window, GLFW_KEY_LEFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
glm_quatv(p, -ANGLE, (vec3){0,1,0});
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
glm_quat_mul(p, q, q);
|
glm_quat_mul(p, q, q);
|
||||||
glm_quat_rotatev(p, axis[0], axis[0]);
|
glm_quat_rotatev(p, axis[0], axis[0]);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ void draw_mesh_lines(id_t shader, mesh_t p)
|
|||||||
{
|
{
|
||||||
struct obj *obj = p;
|
struct obj *obj = p;
|
||||||
|
|
||||||
|
glLineWidth(4);
|
||||||
glUseProgram(shader);
|
glUseProgram(shader);
|
||||||
glBindVertexArray(obj->vao);
|
glBindVertexArray(obj->vao);
|
||||||
#ifndef EMSCRIPTEN
|
#ifndef EMSCRIPTEN
|
||||||
|
|||||||
Reference in New Issue
Block a user