22 static int handle_sball_event(sball_event *ev);
23 static void recalc_sball_matrix(float *xform);
30 static vec3_t pos = {0, 0, 0};
31 static quat_t rot = {0, 0, 0, 1};
33 int main(int argc, char **argv)
36 __djgpp_nearptr_enable();
39 fbsize = fb_width * fb_height * fb_bpp / 8;
41 init_logger("demo.log");
48 if((use_mouse = have_mouse())) {
49 printf("initializing mouse input\n");
50 set_mouse_limits(0, 0, fb_width, fb_height);
51 set_mouse(fb_width / 2, fb_height / 2);
54 /* now start_loadscr sets up fb_pixels to the space used by the loading image,
55 * so no need to allocate another framebuffer
58 /* allocate a couple extra rows as a guard band, until we fucking fix the rasterizer */
59 if(!(fb_pixels = malloc(fbsize + (fb_width * fb_bpp / 8) * 2))) {
60 fprintf(stderr, "failed to allocate backbuffer\n");
63 fb_pixels += fb_width;
66 if(!(vmem = set_video_mode(fb_width, fb_height, fb_bpp, 1))) {
70 if(demo_init(argc, argv) == -1) {
75 if(opt.sball && sball_init() == 0) {
84 while((key = kb_getkey()) != -1) {
85 demo_keyboard(key, 1);
89 demo_keyboard(getch(), 1);
92 if(quit) goto break_evloop;
95 mouse_bmask = read_mouse(&mouse_x, &mouse_y);
97 if(use_sball && sball_pending()) {
99 while(sball_getevent(&ev)) {
100 handle_sball_event(&ev);
102 recalc_sball_matrix(sball_matrix);
105 time_msec = get_msec();
126 void swap_buffers(void *pixels)
132 demo_post_draw(pixels);
134 /* just memcpy to the front buffer */
138 memcpy(vmem, pixels, fbsize);
142 #define TX(ev) ((ev)->motion.motion[0])
143 #define TY(ev) ((ev)->motion.motion[1])
144 #define TZ(ev) ((ev)->motion.motion[2])
145 #define RX(ev) ((ev)->motion.motion[3])
146 #define RY(ev) ((ev)->motion.motion[4])
147 #define RZ(ev) ((ev)->motion.motion[5])
149 static int handle_sball_event(sball_event *ev)
152 case SBALL_EV_MOTION:
153 if(RX(ev) | RY(ev) | RZ(ev)) {
154 float rx = (float)RX(ev);
155 float ry = (float)RY(ev);
156 float rz = (float)RZ(ev);
157 float axis_len = sqrt(rx * rx + ry * ry + rz * rz);
159 rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len,
160 -ry / axis_len, -rz / axis_len);
164 pos.x += TX(ev) * 0.001;
165 pos.y += TY(ev) * 0.001;
166 pos.z += TZ(ev) * 0.001;
169 case SBALL_EV_BUTTON:
170 if(ev->button.pressed) {
171 pos = v3_cons(0, 0, 0);
172 rot = quat_cons(1, 0, 0, 0);
180 void recalc_sball_matrix(float *xform)
182 quat_to_mat(xform, rot);