9 void destroy_gfx(void);
10 int handle_dev_event(device_event *ev);
12 vec3_t pos = {0, 0, -6};
13 quat_t rot = {0, 0, 0, 1}; /* that's 1 + 0i + 0j + 0k */
15 static struct device *dev;
24 if(!(dev = dev_init(0))) {
25 fprintf(stderr, "failed to initialize 6dof serial device at COM1\n");
28 if((devfd = dev->start()) == -1) {
37 if(kbhit() && getch() == 27) {
41 while(dev->getevent(&ev)) {
42 handle_dev_event(&ev);
58 void destroy_gfx(void)
62 #define TX(ev) ((ev)->motion.motion[0])
63 #define TY(ev) ((ev)->motion.motion[1])
64 #define TZ(ev) ((ev)->motion.motion[2])
65 #define RX(ev) ((ev)->motion.motion[3])
66 #define RY(ev) ((ev)->motion.motion[4])
67 #define RZ(ev) ((ev)->motion.motion[5])
69 int handle_dev_event(device_event *ev)
73 printf("t: %5d %5d %5d - r: %5d %5d %5d\n", TX(ev), TY(ev), TZ(ev),
74 RX(ev), RY(ev), RZ(ev));
75 if(RX(ev) | RY(ev) | RZ(ev)) {
76 float axis_len = sqrt(RX(ev) * RX(ev) + RY(ev) * RY(ev) + RZ(ev) * RZ(ev));
78 rot = quat_rotate(rot, axis_len * 0.001, -RX(ev) / axis_len,
79 -RY(ev) / axis_len, -RZ(ev) / axis_len);
83 pos.x += TX(ev) * 0.001;
84 pos.y += TY(ev) * 0.001;
85 pos.z += TZ(ev) * 0.001;
89 if(ev->button.pressed) {
90 pos = v3_cons(0, 0, -6);
91 rot = quat_cons(1, 0, 0, 0);