16 static int handle_sball_event(sball_event *ev);
17 static void recalc_sball_matrix(float *xform);
24 static vec3_t pos = {0, 0, 0};
25 static quat_t rot = {0, 0, 0, 1};
28 int main(int argc, char **argv)
31 int vmidx, status = 0;
33 for(i=1; i<argc; i++) {
34 if(strcmp(argv[i], "-setup") == 0) {
40 __djgpp_nearptr_enable();
43 init_logger("demo.log");
46 printf("watcom build\n");
47 #elif defined(__DJGPP__)
48 printf("djgpp build\n");
51 if(read_cpuid(&cpuid) == 0) {
55 /* au_init needs to be called early, before init_timer, and also before
56 * we enter graphics mode, to use the midas configuration tool if necessary
65 if(init_pci() != -1) {
66 /* TODO detect and initialize S3 virge */
69 if(init_video() == -1) {
73 if((vmidx = match_video_mode(FB_WIDTH, FB_HEIGHT, FB_BPP)) == -1) {
76 if(!(vmem = set_video_mode(vmidx, 1))) {
81 if((opt.mouse = have_mouse())) {
82 printf("initializing mouse input\n");
83 set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1);
84 set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2);
88 if(demo_init(argc, argv) == -1) {
93 if(opt.sball && sball_init() == 0) {
101 while((key = kb_getkey()) != -1) {
102 demo_keyboard(key, 1);
103 if(quit) goto break_evloop;
107 mouse_bmask = read_mouse(&mouse_x, &mouse_y);
109 if(use_sball && sball_pending()) {
111 while(sball_getevent(&ev)) {
112 handle_sball_event(&ev);
114 recalc_sball_matrix(sball_matrix);
117 time_msec = get_msec();
138 void demo_abort(void)
142 printf("demo_abort called. see demo.log for details. Last lines:\n\n");
143 print_tail("demo.log");
147 #define TX(ev) ((ev)->motion.motion[0])
148 #define TY(ev) ((ev)->motion.motion[1])
149 #define TZ(ev) ((ev)->motion.motion[2])
150 #define RX(ev) ((ev)->motion.motion[3])
151 #define RY(ev) ((ev)->motion.motion[4])
152 #define RZ(ev) ((ev)->motion.motion[5])
154 static int handle_sball_event(sball_event *ev)
157 case SBALL_EV_MOTION:
158 if(RX(ev) | RY(ev) | RZ(ev)) {
159 float rx = (float)RX(ev);
160 float ry = (float)RY(ev);
161 float rz = (float)RZ(ev);
162 float axis_len = sqrt(rx * rx + ry * ry + rz * rz);
164 rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len,
165 -ry / axis_len, -rz / axis_len);
169 pos.x += TX(ev) * 0.001;
170 pos.y += TY(ev) * 0.001;
171 pos.z += TZ(ev) * 0.001;
174 case SBALL_EV_BUTTON:
175 if(ev->button.pressed) {
176 pos = v3_cons(0, 0, 0);
177 rot = quat_cons(1, 0, 0, 0);
185 void recalc_sball_matrix(float *xform)
187 quat_to_mat(xform, rot);