12 static int handle_sball_event(sball_event *ev);
13 static void recalc_sball_matrix(float *xform);
20 static vec3_t pos = {0, 0, 0};
21 static quat_t rot = {0, 0, 0, 1};
24 int main(int argc, char **argv)
27 int vmidx, status = 0;
29 for(i=1; i<argc; i++) {
30 if(strcmp(argv[i], "-setup") == 0) {
36 __djgpp_nearptr_enable();
39 init_logger("demo.log");
41 /* au_init needs to be called early, before init_timer, and also before
42 * we enter graphics mode, to use the midas configuration tool if necessary
51 if(init_video() == -1) {
55 if((vmidx = match_video_mode(640, 480, 16)) == -1) {
58 if(!(vmem = set_video_mode(vmidx, 1))) {
63 if((opt.mouse = have_mouse())) {
64 printf("initializing mouse input\n");
65 set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1);
66 set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2);
70 if(init(argc, argv) == -1) {
75 if(opt.sball && sball_init() == 0) {
83 while((key = kb_getkey()) != -1) {
85 if(quit) goto break_evloop;
89 mouse_bmask = read_mouse(&mouse_x, &mouse_y);
91 if(use_sball && sball_pending()) {
93 while(sball_getevent(&ev)) {
94 handle_sball_event(&ev);
96 recalc_sball_matrix(sball_matrix);
99 time_msec = get_msec();
120 #define TX(ev) ((ev)->motion.motion[0])
121 #define TY(ev) ((ev)->motion.motion[1])
122 #define TZ(ev) ((ev)->motion.motion[2])
123 #define RX(ev) ((ev)->motion.motion[3])
124 #define RY(ev) ((ev)->motion.motion[4])
125 #define RZ(ev) ((ev)->motion.motion[5])
127 static int handle_sball_event(sball_event *ev)
130 case SBALL_EV_MOTION:
131 if(RX(ev) | RY(ev) | RZ(ev)) {
132 float rx = (float)RX(ev);
133 float ry = (float)RY(ev);
134 float rz = (float)RZ(ev);
135 float axis_len = sqrt(rx * rx + ry * ry + rz * rz);
137 rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len,
138 -ry / axis_len, -rz / axis_len);
142 pos.x += TX(ev) * 0.001;
143 pos.y += TY(ev) * 0.001;
144 pos.z += TZ(ev) * 0.001;
147 case SBALL_EV_BUTTON:
148 if(ev->button.pressed) {
149 pos = v3_cons(0, 0, 0);
150 rot = quat_cons(1, 0, 0, 0);
158 void recalc_sball_matrix(float *xform)
160 quat_to_mat(xform, rot);