14 static int handle_sball_event(sball_event *ev);
15 static void recalc_sball_matrix(float *xform);
22 static vec3_t pos = {0, 0, 0};
23 static quat_t rot = {0, 0, 0, 1};
26 int main(int argc, char **argv)
29 int vmidx, status = 0;
31 for(i=1; i<argc; i++) {
32 if(strcmp(argv[i], "-setup") == 0) {
38 __djgpp_nearptr_enable();
41 init_logger("demo.log");
43 /* au_init needs to be called early, before init_timer, and also before
44 * we enter graphics mode, to use the midas configuration tool if necessary
53 if(init_video() == -1) {
57 if((vmidx = match_video_mode(FB_WIDTH, FB_HEIGHT, FB_BPP)) == -1) {
60 if(!(vmem = set_video_mode(vmidx, 1))) {
65 if((opt.mouse = have_mouse())) {
66 printf("initializing mouse input\n");
67 set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1);
68 set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2);
72 if(demo_init(argc, argv) == -1) {
77 if(opt.sball && sball_init() == 0) {
85 while((key = kb_getkey()) != -1) {
86 demo_keyboard(key, 1);
87 if(quit) goto break_evloop;
91 mouse_bmask = read_mouse(&mouse_x, &mouse_y);
93 if(use_sball && sball_pending()) {
95 while(sball_getevent(&ev)) {
96 handle_sball_event(&ev);
98 recalc_sball_matrix(sball_matrix);
101 time_msec = get_msec();
122 #define TX(ev) ((ev)->motion.motion[0])
123 #define TY(ev) ((ev)->motion.motion[1])
124 #define TZ(ev) ((ev)->motion.motion[2])
125 #define RX(ev) ((ev)->motion.motion[3])
126 #define RY(ev) ((ev)->motion.motion[4])
127 #define RZ(ev) ((ev)->motion.motion[5])
129 static int handle_sball_event(sball_event *ev)
132 case SBALL_EV_MOTION:
133 if(RX(ev) | RY(ev) | RZ(ev)) {
134 float rx = (float)RX(ev);
135 float ry = (float)RY(ev);
136 float rz = (float)RZ(ev);
137 float axis_len = sqrt(rx * rx + ry * ry + rz * rz);
139 rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len,
140 -ry / axis_len, -rz / axis_len);
144 pos.x += TX(ev) * 0.001;
145 pos.y += TY(ev) * 0.001;
146 pos.z += TZ(ev) * 0.001;
149 case SBALL_EV_BUTTON:
150 if(ev->button.pressed) {
151 pos = v3_cons(0, 0, 0);
152 rot = quat_cons(1, 0, 0, 0);
160 void recalc_sball_matrix(float *xform)
162 quat_to_mat(xform, rot);