X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fdos%2Fmain.c;h=7564be3805e929f84bc51e53dc11f8d8cd8d8892;hp=051cdb518718ac34acc8641bfb7eee0b5294bd4f;hb=6c5e65928b425dd6a7f5192841e1d4ef9d90789a;hpb=157a4056159e45cd61e9427e126807aaa8bd3d9a diff --git a/src/dos/main.c b/src/dos/main.c index 051cdb5..7564be3 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "demo.h" @@ -7,12 +8,22 @@ #include "mouse.h" #include "timer.h" #include "gfx.h" +#include "vmath.h" +#include "sball.h" +#include "cfgopt.h" #include "logger.h" +static int handle_sball_event(sball_event *ev); +static void recalc_sball_matrix(float *xform); + static int quit; static int use_mouse; static long fbsize; +static int use_sball; +static vec3_t pos = {0, 0, 0}; +static quat_t rot = {0, 0, 0, 1}; + int main(int argc, char **argv) { fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT; @@ -42,6 +53,11 @@ int main(int argc, char **argv) set_text_mode(); return 1; } + + if(opt.sball && sball_init() == 0) { + use_sball = 1; + } + reset_timer(); while(!quit) { @@ -54,6 +70,14 @@ int main(int argc, char **argv) if(use_mouse) { mouse_bmask = read_mouse(&mouse_x, &mouse_y); } + if(use_sball && sball_pending()) { + sball_event ev; + printf("got sball event\n"); + while(sball_getevent(&ev)) { + handle_sball_event(&ev); + } + recalc_sball_matrix(sball_matrix); + } time_msec = get_msec(); demo_draw(); @@ -63,6 +87,9 @@ break_evloop: set_text_mode(); demo_cleanup(); kb_shutdown(); + if(use_sball) { + sball_shutdown(); + } return 0; } @@ -82,3 +109,50 @@ void swap_buffers(void *pixels) drawFps(vmem_back); } } + + +#define TX(ev) ((ev)->motion.motion[0]) +#define TY(ev) ((ev)->motion.motion[1]) +#define TZ(ev) ((ev)->motion.motion[2]) +#define RX(ev) ((ev)->motion.motion[3]) +#define RY(ev) ((ev)->motion.motion[4]) +#define RZ(ev) ((ev)->motion.motion[5]) + +static int handle_sball_event(sball_event *ev) +{ + switch(ev->type) { + case SBALL_EV_MOTION: + if(RX(ev) | RY(ev) | RZ(ev)) { + float rx = (float)RX(ev); + float ry = (float)RY(ev); + float rz = (float)RZ(ev); + float axis_len = sqrt(rx * rx + ry * ry + rz * rz); + if(axis_len > 0.0) { + rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len, + -ry / axis_len, -rz / axis_len); + } + } + + pos.x += TX(ev) * 0.001; + pos.y += TY(ev) * 0.001; + pos.z += TZ(ev) * 0.001; + break; + + case SBALL_EV_BUTTON: + if(ev->button.pressed) { + pos = v3_cons(0, 0, 0); + rot = quat_cons(1, 0, 0, 0); + } + break; + } + + return 0; +} + +void recalc_sball_matrix(float *xform) +{ + quat_to_mat(xform, rot); + xform[12] = pos.x; + xform[13] = pos.y; + xform[14] = pos.z; +}