Add src/input.c

This commit is contained in:
PedroEdiaz
2024-09-13 01:23:57 +06:00
parent 6161d310bc
commit 15dc499cd9
2 changed files with 64 additions and 3 deletions

58
src/input.c Normal file
View File

@@ -0,0 +1,58 @@
#include <GLFW/glfw3.h>
#include "main.h"
#define inline
#include <cglm/quat.h>
#define ANGLE ((float)0x01/0xff*2*GLM_PI)
versor q = GLM_QUAT_IDENTITY_INIT;
vec3 axis[3] =
{
{1,0,0},
{0,1,0},
{0,0,1},
};
float * poll_input( window_t window )
{
versor p = GLM_QUAT_IDENTITY_INIT;
if( glfwGetKey( (void*)window, 'Q' ) == GLFW_PRESS )
{
glm_quatv( p, ANGLE, axis[0] );
goto end;
}
if( glfwGetKey( (void*)window, 'W' ) == GLFW_PRESS )
{
glm_quatv( p, -ANGLE, axis[0] );
goto end;
}
if( glfwGetKey( (void*)window, 'A' ) == GLFW_PRESS )
{
glm_quatv( p, ANGLE, axis[1] );
goto end;
}
if( glfwGetKey( (void*)window, 'S' ) == GLFW_PRESS )
{
glm_quatv( p, -ANGLE, axis[1] );
goto end;
}
if( glfwGetKey( (void*)window, 'Z' ) == GLFW_PRESS )
{
glm_quatv( p, ANGLE, axis[2] );
goto end;
}
if( glfwGetKey( (void*)window, 'X' ) == GLFW_PRESS )
{
glm_quatv( p, -ANGLE, axis[2] );
goto end;
}
end:
glm_quat_mul( p, q, q );
glm_quat_rotatev( p, axis[0], axis[0] );
glm_quat_rotatev( p, axis[1], axis[1] );
glm_quat_rotatev( p, axis[2], axis[2] );
return q;
}