Add src/input.c
This commit is contained in:
9
Makefile
9
Makefile
@@ -22,7 +22,7 @@ CFLAGS = \
|
|||||||
-I./ext/glfw/include \
|
-I./ext/glfw/include \
|
||||||
-Wall -Wno-unused-function -std=c89
|
-Wall -Wno-unused-function -std=c89
|
||||||
|
|
||||||
all: $(DOC) $(BIN) $(LIB)
|
all: $(BIN) $(LIB)
|
||||||
|
|
||||||
$(BIN): $(OBJ) $(LIB)
|
$(BIN): $(OBJ) $(LIB)
|
||||||
$(CC) -lGL -lglfw -L. -o $(BIN) $(OBJ)
|
$(CC) -lGL -lglfw -L. -o $(BIN) $(OBJ)
|
||||||
@@ -39,10 +39,13 @@ clean:
|
|||||||
clean-all:
|
clean-all:
|
||||||
rm $(OBJ) $(DOC) $(LIB) $(BIN)
|
rm $(OBJ) $(DOC) $(LIB) $(BIN)
|
||||||
|
|
||||||
.SUFFIXES: .ms .pdf .c .o
|
.SUFFIXES: .ms .pdf .html .c .o
|
||||||
|
|
||||||
.ms.pdf:
|
.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:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) $< -c -o $@
|
$(CC) $(CFLAGS) $< -c -o $@
|
||||||
|
|||||||
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