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

View File

@@ -22,7 +22,7 @@ CFLAGS = \
-I./ext/glfw/include \
-Wall -Wno-unused-function -std=c89
all: $(DOC) $(BIN) $(LIB)
all: $(BIN) $(LIB)
$(BIN): $(OBJ) $(LIB)
$(CC) -lGL -lglfw -L. -o $(BIN) $(OBJ)
@@ -39,10 +39,13 @@ clean:
clean-all:
rm $(OBJ) $(DOC) $(LIB) $(BIN)
.SUFFIXES: .ms .pdf .c .o
.SUFFIXES: .ms .pdf .html .c .o
.ms.pdf:
cat $< | sed -e "s/^\s*//g" -e "/^$$/d" | groff -Tpdf -fC -ms > $@
cat $< | sed -e "s/^\s*//g" -e "/^$$/d" | tbl| groff -Tpdf -fC -ms > $@
.ms.html:
cat $< | sed -e "s/^\s*//g" -e "/^$$/d"| tbl | groff -Thtml -fC -ms > $@
.c.o:
$(CC) $(CFLAGS) $< -c -o $@

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;
}