Explorar o código

Moved translation of TUIO to pixel coordinates to TUIO server instead of gesture server.

Taddeus Kroes %!s(int64=13) %!d(string=hai) anos
pai
achega
b7c9d41d51
Modificáronse 3 ficheiros con 14 adicións e 16 borrados
  1. 0 1
      TODO.txt
  2. 2 9
      src/server.py
  3. 12 6
      src/tuio_server.py

+ 0 - 1
TODO.txt

@@ -2,7 +2,6 @@ Code:
 - Connect to VTK.
 - Rotation has a 'bump' at 0.
 - tracker.gesture(...) instead of tracker.bind('gesture', ...)
-- TODO: vertaling coordinaten doen in InputServer ipv GestureServer
 
 Thesis:
 - Network protocol.

+ 2 - 9
src/server.py

@@ -2,7 +2,6 @@ from input_server import InputServerHandler
 from tuio_server import TuioServer2D
 from window import FullscreenWindow
 from point import TouchPoint
-from screen import pixel_coords
 
 
 class GestureServer(InputServerHandler):
@@ -33,11 +32,8 @@ class GestureServer(InputServerHandler):
         if sid in self.points:
             raise ValueError('Point with sid %d already exists.' % sid)
 
-        # Translate to pixel coordinates
-        px, py = pixel_coords(x, y)
-
         # Create a new touch point
-        self.points[sid] = point = TouchPoint(px, py, sid)
+        self.points[sid] = point = TouchPoint(x, y, sid)
 
         # Save the windows containing the point in a dictionary, and update
         # their trackers
@@ -50,12 +46,9 @@ class GestureServer(InputServerHandler):
         if sid not in self.points:
             raise KeyError('No point with sid %d exists.' % sid)
 
-        # Translate to pixel coordinates
-        px, py = pixel_coords(x, y)
-
         # Update point position and corresponding window trackers
         point = self.points[sid]
-        point.set_position(px, py)
+        point.set_position(x, y)
         point.update_window_trackers('move')
 
     def on_point_up(self, sid):

+ 12 - 6
src/tuio_server.py

@@ -2,6 +2,7 @@ from OSC import OSCServer
 OSCServer.print_tracebacks = True
 
 from input_server import InputServer
+from screen import pixel_coords
 
 
 class TuioServer2D(InputServer):
@@ -51,15 +52,20 @@ class TuioServer2D(InputServer):
             if sid not in self.alive:
                 raise ValueError('Point with sid "%d" is not alive.' % sid)
 
+            # Translate to pixel coordinates
+            px, py = pixel_coords(x, y)
+
             # Check if 'point_down' has already been triggered. If so, trigger
             # a 'point_move' event instead
             if sid in self.down:
-                self.debug('Moved %d to (%s, %s).' % (sid, x, y))
-                self.handler_obj.on_point_move(sid, x, y)
+                self.debug('Moved %d to (%.4f, %.4f) or (%d, %d).'
+                           % (sid, x, y, px, py))
+                self.handler_obj.on_point_move(sid, px, py)
             else:
-                self.debug('Down %d at (%s, %s).' % (sid, x, y))
+                self.debug('Down %d at (%.4f, %.4f) or (%d, %d).'
+                           % (sid, x, y, px, py))
                 self.down.add(sid)
-                self.handler_obj.on_point_down(sid, x, y)
+                self.handler_obj.on_point_down(sid, px, py)
 
     def run(self):
         self.server.handle_request()
@@ -98,13 +104,13 @@ if __name__ == '__main__':
     # Define handlers
     class Handler(InputServerHandler, Logger):
         def on_point_down(self, sid, x, y):
-            self.info('Point down: sid=%d (%s, %s)' % (sid, x, y))
+            self.info('Point down: sid=%d (%.4f, %.4f)' % (sid, x, y))
 
         def on_point_up(self, sid):
             self.info('Point up: sid=%d' % sid)
 
         def on_point_move(self, sid, x, y):
-            self.info('Point move: sid=%d (%s, %s)' % (sid, x, y))
+            self.info('Point move: sid=%d (%.4f, %.4f)' % (sid, x, y))
 
     server = TuioServer2D(Handler())