Add src/input.c
This commit is contained in:
58
src/input.c
Normal file
58
src/input.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user