15 static int handle_sball_event(sball_event *ev);
16 static void recalc_sball_matrix(float *xform);
23 static vec3_t pos = {0, 0, 0};
24 static quat_t rot = {0, 0, 0, 1};
27 int main(int argc, char **argv)
30 int vmidx, status = 0;
32 for(i=1; i<argc; i++) {
33 if(strcmp(argv[i], "-setup") == 0) {
39 __djgpp_nearptr_enable();
42 if(read_cpuid(&cpuid) == 0) {
46 init_logger("demo.log");
48 /* au_init needs to be called early, before init_timer, and also before
49 * we enter graphics mode, to use the midas configuration tool if necessary
58 if(init_video() == -1) {
62 if((vmidx = match_video_mode(FB_WIDTH, FB_HEIGHT, FB_BPP)) == -1) {
65 if(!(vmem = set_video_mode(vmidx, 1))) {
70 if((opt.mouse = have_mouse())) {
71 printf("initializing mouse input\n");
72 set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1);
73 set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2);
77 if(demo_init(argc, argv) == -1) {
82 if(opt.sball && sball_init() == 0) {
90 while((key = kb_getkey()) != -1) {
91 demo_keyboard(key, 1);
92 if(quit) goto break_evloop;
96 mouse_bmask = read_mouse(&mouse_x, &mouse_y);
98 if(use_sball && sball_pending()) {
100 while(sball_getevent(&ev)) {
101 handle_sball_event(&ev);
103 recalc_sball_matrix(sball_matrix);
106 time_msec = get_msec();
127 #define TX(ev) ((ev)->motion.motion[0])
128 #define TY(ev) ((ev)->motion.motion[1])
129 #define TZ(ev) ((ev)->motion.motion[2])
130 #define RX(ev) ((ev)->motion.motion[3])
131 #define RY(ev) ((ev)->motion.motion[4])
132 #define RZ(ev) ((ev)->motion.motion[5])
134 static int handle_sball_event(sball_event *ev)
137 case SBALL_EV_MOTION:
138 if(RX(ev) | RY(ev) | RZ(ev)) {
139 float rx = (float)RX(ev);
140 float ry = (float)RY(ev);
141 float rz = (float)RZ(ev);
142 float axis_len = sqrt(rx * rx + ry * ry + rz * rz);
144 rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len,
145 -ry / axis_len, -rz / axis_len);
149 pos.x += TX(ev) * 0.001;
150 pos.y += TY(ev) * 0.001;
151 pos.z += TZ(ev) * 0.001;
154 case SBALL_EV_BUTTON:
155 if(ev->button.pressed) {
156 pos = v3_cons(0, 0, 0);
157 rot = quat_cons(1, 0, 0, 0);
165 void recalc_sball_matrix(float *xform)
167 quat_to_mat(xform, rot);