From 8f38659932677a2b0e00b7f4abda54ac76a8ecd9 Mon Sep 17 00:00:00 2001 From: kitty piapiac Date: Fri, 21 Apr 2023 23:50:06 -0700 Subject: SRS-style rotation skeleton --- input.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 8248ded..d22e2cb 100644 --- a/input.c +++ b/input.c @@ -4,10 +4,38 @@ #include"graph.h" #include"input.h" #define SDLBUT(x)SDL_BUTTON(SDL_BUTTON_##x) -InputPoint input_point(V){InputPoint ip;SDL_GetMouseState((S32*)&ip.x,(S32*)&ip.y);ip.y=graph_win_h-ip.y;R ip;} -InputButtons input_button(V){InputButtons ib={0};U32 mb;mb=SDL_GetMouseState(0,0); - Q(SDLBUT(LEFT)&mb, ib.f|=IB_1) - Q(SDLBUT(MIDDLE)&mb, ib.f|=IB_2) - Q(SDLBUT(RIGHT)&mb, ib.f|=IB_3) - Q(SDLBUT(X1)&mb, ib.f|=IB_4) - R ib;} +InputPoint input_point; +InputButtons input_buttons; + +_ U32 map_mouse[][2]={ + {SDLBUT(LEFT), IB_1}, + {SDLBUT(RIGHT), IB_2}, + {SDLBUT(MIDDLE),IB_3}, + {SDLBUT(X1), IB_4}}; + +_ U32 map_keeb[][2]={ + {SDL_SCANCODE_LEFT, IB_L}, + {SDL_SCANCODE_RIGHT, IB_R}, + {SDL_SCANCODE_UP, IB_U}, + {SDL_SCANCODE_DOWN, IB_D}, + {SDL_SCANCODE_SPACE, IB_S}, + {SDL_SCANCODE_Z, IB_Z}, + {SDL_SCANCODE_X, IB_X}, + {SDL_SCANCODE_C, IB_C}}; + +#define ip input_point +#define ib input_buttons +#define mm map_mouse +#define mk map_keeb +V input_update(V){U32 mb,mm_len,mk_len,i,kb_len;IM U8*kb;InputButtons nb={0,0}; + mb=SDL_GetMouseState((S32*)&ip.x,(S32*)&ip.y),ip.y=graph_win_h-ip.y, + kb=SDL_GetKeyboardState((S32*)&kb_len), + mm_len=(SZ mm)/(SZ mm[0]), + mk_len=(SZ mk)/(SZ mk[0]), + i=0;WH(i