22 static int handle_sball_event(sball_event *ev);
23 static void recalc_sball_matrix(float *xform);
29 static vec3_t pos = {0, 0, 0};
30 static quat_t rot = {0, 0, 0, 1};
32 int main(int argc, char **argv)
35 __djgpp_nearptr_enable();
38 fbsize = FB_WIDTH * FB_HEIGHT * FB_BPP / 8;
40 init_logger("demo.log");
47 /* now start_loadscr sets up fb_pixels to the space used by the loading image,
48 * so no need to allocate another framebuffer
51 /* allocate a couple extra rows as a guard band, until we fucking fix the rasterizer */
52 if(!(fb_pixels = malloc(fbsize + (FB_WIDTH * FB_BPP / 8) * 2))) {
53 fprintf(stderr, "failed to allocate backbuffer\n");
56 fb_pixels += FB_WIDTH;
59 if(!(vmem = set_video_mode(FB_WIDTH, FB_HEIGHT, FB_BPP, 1))) {
64 if((opt.mouse = have_mouse())) {
65 printf("initializing mouse input\n");
66 set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1);
67 set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2);
71 if(demo_init(argc, argv) == -1) {
76 if(opt.sball && sball_init() == 0) {
85 while((key = kb_getkey()) != -1) {
86 demo_keyboard(key, 1);
90 demo_keyboard(getch(), 1);
93 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 void swap_buffers(void *pixels)
133 demo_post_draw(pixels);
135 /* just memcpy to the front buffer */
139 memcpy(vmem, pixels, fbsize);
143 #define TX(ev) ((ev)->motion.motion[0])
144 #define TY(ev) ((ev)->motion.motion[1])
145 #define TZ(ev) ((ev)->motion.motion[2])
146 #define RX(ev) ((ev)->motion.motion[3])
147 #define RY(ev) ((ev)->motion.motion[4])
148 #define RZ(ev) ((ev)->motion.motion[5])
150 static int handle_sball_event(sball_event *ev)
153 case SBALL_EV_MOTION:
154 if(RX(ev) | RY(ev) | RZ(ev)) {
155 float rx = (float)RX(ev);
156 float ry = (float)RY(ev);
157 float rz = (float)RZ(ev);
158 float axis_len = sqrt(rx * rx + ry * ry + rz * rz);
160 rot = quat_rotate(rot, axis_len * 0.001, -rx / axis_len,
161 -ry / axis_len, -rz / axis_len);
165 pos.x += TX(ev) * 0.001;
166 pos.y += TY(ev) * 0.001;
167 pos.z += TZ(ev) * 0.001;
170 case SBALL_EV_BUTTON:
171 if(ev->button.pressed) {
172 pos = v3_cons(0, 0, 0);
173 rot = quat_cons(1, 0, 0, 0);
181 void recalc_sball_matrix(float *xform)
183 quat_to_mat(xform, rot);