X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fdos%2Fmain.c;h=566d47e9f8939e50e61fbdced4f0e22adab15c3c;hp=e1d33c232d46327a73d25cfa39d3308ea02f8b9b;hb=0ce0f59d2afd26e0956716fae169075368020a02;hpb=77c1d84c258ca14e1bba06ab711426668ff24290 diff --git a/src/dos/main.c b/src/dos/main.c index e1d33c2..566d47e 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -1,46 +1,166 @@ #include +#include +#include #include "demo.h" #include "keyb.h" #include "timer.h" #include "gfx.h" +#include "logger.h" +#include "cdpmi.h" +#include "audio.h" +#include "sball.h" +#include "vmath.h" + +static int handle_sball_event(sball_event *ev); +static void recalc_sball_matrix(float *xform); static int quit; +int force_snd_config; + +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) { + int i; + int vmidx, status = 0; + + for(i=1; imotion.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; +}