aberant-tuio-ruby 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 2
2
+ :minor: 1
3
+ :patch: 0
4
4
  :major: 0
@@ -0,0 +1,5 @@
1
+ class Float
2
+ def approx_equal?(other,threshold=0.00001)
3
+ (self-other).abs < threshold
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class Object
2
+ def client_block_setter( *args )
3
+ args.each do | blk_setter_name |
4
+ self.class_eval <<-EOF
5
+ def on_#{blk_setter_name}( &#{blk_setter_name}_blk )
6
+ @#{blk_setter_name}_callback_blk = #{blk_setter_name}_blk
7
+ end
8
+ EOF
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ $: << File.dirname( __FILE__ )
2
+ $: << File.join( File.dirname(__FILE__), 'core_ext' )
3
+
4
+ require 'float'
5
+ require 'object'
6
+
@@ -1,13 +1,18 @@
1
1
  require 'rubygems'
2
2
  require 'osc'
3
3
 
4
+ require File.join( File.dirname( __FILE__ ), 'my_environment')
4
5
 
6
+ require "tuio_object"
7
+ require "tuio_cursor"
5
8
 
6
- class TUIOClient
9
+ class TuioClient
7
10
  include OSC
8
11
 
12
+ client_block_setter :object_creation, :object_update, :object_removal
13
+ client_block_setter :cursor_creation, :cursor_update, :cursor_removal
14
+
9
15
  def initialize( args = {} )
10
- @host = args[:host] || 'localhost'
11
16
  @port = args[:port] || 3333
12
17
 
13
18
  @tuio_objects = { }
@@ -15,25 +20,29 @@ class TUIOClient
15
20
 
16
21
  @osc = OSC::SimpleServer.new(@port)
17
22
 
18
- @osc.add_method '/tuio/2Dobj', nil do |msg|
23
+ @osc.add_method '/tuio/2Dobj' do |msg|
19
24
  args = msg.to_a
20
25
 
21
26
  case args.shift
22
27
  when "set"
23
- update_tuio_objects( args )
28
+ track_tuio_object( args )
24
29
  when "alive"
25
30
  keep_alive( :tuio_objects, args )
31
+ when "fseq"
32
+ # puts args
26
33
  end
27
34
  end
28
35
 
29
- @osc.add_method '/tuio/2Dcur', nil do |msg|
36
+ @osc.add_method '/tuio/2Dcur' do |msg|
30
37
  args = msg.to_a
31
38
 
32
39
  case args.shift
33
40
  when "set"
34
- update_tuio_cursors args
41
+ track_tuio_cursor args
35
42
  when "alive"
36
43
  keep_alive( :tuio_cursors, args )
44
+ when "fseq"
45
+ # puts args
37
46
  end
38
47
  end
39
48
  end
@@ -44,6 +53,10 @@ class TUIOClient
44
53
  end
45
54
  end
46
55
 
56
+ ####################################
57
+ # getters #
58
+ ####################################
59
+
47
60
  def tuio_objects
48
61
  @tuio_objects
49
62
  end
@@ -60,55 +73,159 @@ class TUIOClient
60
73
  @tuio_cursors[id]
61
74
  end
62
75
 
76
+ ####################################
77
+ # call backs #
78
+ ####################################
79
+
80
+ # def on_cursor_update( &cur_update_blk )
81
+ # @cur_update_blk = cur_update_blk
82
+ # end
83
+
63
84
  private
64
- #TODO clean up these, each_with_index methinks
65
- def cur_args_to_hash( args )
66
- {
67
- :session_id => args[0],
68
- :x_pos => args[1],
69
- :y_pos => args[2],
70
- :x_move => args[3],
71
- :y_move => args[4],
72
- :motion_acc => args[5],
73
- }
85
+
86
+ def track_tuio_object( args )
87
+ session_id = session_id_from( args )
88
+
89
+ if tuio_object_previously_tracked?( session_id )
90
+
91
+ tuio_object = grab_tuio_object_by( session_id )
92
+
93
+ return if tuio_object.args_equal?( args )
94
+
95
+ tuio_object.update( *update_object_params_from( args ) )
96
+
97
+ trigger_object_update_callback( tuio_object )
98
+ else
99
+ tuio_object = track_new_tuio_object_with( session_id, args )
100
+
101
+ trigger_object_creation_callback( tuio_object )
102
+ end
103
+ end
104
+
105
+ def track_tuio_cursor( args )
106
+ session_id = session_id_from( args )
107
+
108
+ if tuio_cursor_previously_tracked?( session_id )
109
+ tuio_cursor = grab_tuio_cursor_by( session_id )
110
+
111
+ return if tuio_cursor.args_equal?( args )
112
+ tuio_cursor.update( *update_cursor_params_from( args ))
113
+
114
+ trigger_cursor_update_callback( tuio_cursor )
115
+
116
+ else # this is a new cursor
117
+ finger_id = @tuio_cursors.size
118
+ track_new_tuio_cursor_with( session_id, args )
119
+
120
+ trigger_cursor_creation_callback( grab_tuio_cursor_by( session_id ) )
121
+
122
+ end
123
+ end
124
+
125
+ def session_id_from( args )
126
+ args[0]
127
+ end
128
+
129
+ def new_object_params_from( args )
130
+ args[0..4]
131
+ end
132
+
133
+ def update_object_params_from( args )
134
+ args[2..9]
135
+ end
136
+
137
+ def new_cursor_params_from( args )
138
+ args[0..2]
139
+ end
140
+
141
+ def update_cursor_params_from( args )
142
+ args[1..5]
74
143
  end
75
144
 
76
- def obj_args_to_hash( args )
77
- { :session_id => args[0],
78
- :class_id => args[1],
79
- :x_pos => args[2],
80
- :y_pos => args[3],
81
- :angle => args[4],
82
- :x_move => args[5],
83
- :y_move => args[6],
84
- :angle_move => args[7],
85
- :motion_acc => args[8],
86
- :rotation_acc => args[9],
87
- }
88
- end
89
-
90
- def update_tuio_objects( args )
91
- tuio_object = obj_args_to_hash( args )
145
+
146
+ def tuio_object_previously_tracked?( session_id )
147
+ @tuio_objects.has_key?( session_id )
148
+ end
149
+
150
+ def tuio_cursor_previously_tracked?( session_id )
151
+ @tuio_cursors.has_key?( session_id )
152
+ end
153
+
154
+ def grab_tuio_object_by( session_id )
155
+ @tuio_objects[session_id]
156
+ end
157
+
158
+ def grab_tuio_cursor_by( session_id )
159
+ @tuio_cursors[session_id]
160
+ end
161
+
162
+ def track_new_tuio_object_with( session_id, args )
163
+ @tuio_objects[session_id] = TuioObject.new( *new_object_params_from( args ) )
164
+ end
165
+
166
+ def track_new_tuio_cursor_with( session_id, args )
167
+ @tuio_cursors[session_id] = TuioCursor.new( *new_cursor_params_from( args ) )
168
+ end
169
+
170
+ ####################################
171
+ # call backs #
172
+ ####################################
173
+
174
+ def trigger_object_update_callback( tuio_object )
175
+ @object_update_callback_blk.call( tuio_object ) if @object_update_callback_blk
176
+ end
177
+
178
+ def trigger_object_creation_callback( tuio_object )
179
+ @object_creation_callback_blk.call( tuio_object ) if @object_creation_callback_blk
180
+ end
181
+
182
+ def trigger_object_deletion_callback( tuio_object )
183
+ @object_removal_callback_blk.call( tuio_object ) if @object_removal_callback_blk
184
+ end
185
+
186
+ def trigger_cursor_creation_callback( tuio_cursor )
187
+ @cursor_creation_callback_blk.call( tuio_cursor ) if @cursor_creation_callback_blk
188
+ end
189
+
190
+ def trigger_cursor_update_callback( tuio_cursor )
191
+ @cursor_update_callback_blk.call( tuio_cursor ) if @cursor_update_callback_blk
192
+ end
193
+
194
+ def trigger_cursor_update_callback( tuio_cursor )
195
+ @cursor_update_callback_blk.call( tuio_cursor ) if @cursor_update_callback_blk
196
+ end
197
+
198
+ def trigger_cursor_deletion_callback( tuio_object )
199
+ @cursor_removal_callback_blk.call( tuio_object ) if @cursor_removal_callback_blk
200
+ end
201
+
202
+ def delete_tuio_objects( session_id )
203
+ tuio_object = grab_tuio_object_by( session_id )
92
204
 
93
- @tuio_objects[tuio_object[:session_id]] = tuio_object
205
+ trigger_object_deletion_callback( tuio_object )
94
206
  end
95
207
 
96
- def update_tuio_cursors( args )
97
- tuio_cursor = cur_args_to_hash( args )
98
- @tuio_cursors[tuio_cursor[:session_id]] = tuio_cursor
208
+ def delete_tuio_cursors( session_id )
209
+ tuio_cursor = grab_tuio_cursor_by( session_id )
210
+
211
+ trigger_cursor_deletion_callback( tuio_cursor )
99
212
  end
100
213
 
214
+
101
215
  def keep_alive( type, session_ids )
216
+ return if session_ids.nil?
102
217
  all_keys = send( type ).keys
103
218
 
104
219
  dead = all_keys.reject { |key| session_ids.include? key }
105
220
 
106
- dead.each do |d|
107
- send( type ).delete( d )
221
+ dead.each do | session_id |
222
+ send( "delete_#{type}", session_id )
223
+
224
+ send( type ).delete( session_id )
108
225
  end
109
226
  end
110
227
  end
111
228
 
112
229
  if $0 == __FILE__
113
- TUIOClient.new.start
230
+ TuioClient.new.start
114
231
  end
@@ -0,0 +1,50 @@
1
+ require 'tuio_point'
2
+
3
+ module TuioContainer
4
+ attr_accessor :session_id, :x_pos, :y_pos, :x_speed, :y_speed, :motion_accel
5
+
6
+
7
+ def initialize( session_id, x_pos, y_pos )
8
+ @session_id = session_id
9
+ @x_pos = x_pos
10
+ @y_pos = y_pos
11
+
12
+ @x_speed = 0.0
13
+ @y_speed = 0.0
14
+ @motion_accel = 0.0
15
+
16
+ add_point_to_path( TuioPoint.new( x_pos, y_pos ) )
17
+ end
18
+
19
+ def update( x_pos, y_pos, x_speed, y_speed, motion_accel )
20
+ @x_pos = x_pos
21
+ @y_pos = y_pos
22
+ @x_speed = x_speed
23
+ @y_speed = y_speed
24
+ @motion_accel = motion_accel
25
+
26
+ new_point = TuioPoint.new( x_pos, y_pos )
27
+ add_point_to_path( new_point ) unless new_point == @path.last
28
+ end
29
+
30
+ def path
31
+ @path
32
+ end
33
+
34
+ def args_equal?( args )
35
+ @session_id == args[0] &&
36
+ @x_pos.approx_equal?( args[1] ) &&
37
+ @y_pos.approx_equal?( args[2] ) &&
38
+ @x_speed.approx_equal?( args[3] ) &&
39
+ @y_speed.approx_equal?( args[4] ) &&
40
+ @motion_accel.approx_equal?( args[5] )
41
+ end
42
+
43
+ private
44
+
45
+ def add_point_to_path( tuio_point )
46
+ @path ||= []
47
+ @path << tuio_point
48
+ end
49
+ end
50
+
@@ -0,0 +1,53 @@
1
+ class TuioCursor
2
+ include TuioContainer
3
+
4
+ attr_reader :finger_id, :x_speed, :y_speed, :motion_accel
5
+
6
+ def initialize( session_id, x_pos, y_pos ) #, x_speed, y_speed, motion_accel )
7
+ super( session_id, x_pos, y_pos )
8
+
9
+ @x_speed = 0.0
10
+ @y_speed = 0.0
11
+ @motion_accel = 0.0
12
+ end
13
+
14
+ def args_equal?( args )
15
+ super( args_to_container_from_cursor( args ) ) &&
16
+
17
+ @x_speed.approx_equal?(args[3] ) &&
18
+ @y_speed.approx_equal?(args[4] ) &&
19
+ @motion_accel.approx_equal?(args[5] )
20
+ end
21
+
22
+ def inspect
23
+ puts "TuioCursor:"
24
+ puts "session_id >> #{session_id}"
25
+ puts "x_pos >> #{x_pos}"
26
+ puts "y_pos >> #{y_pos}"
27
+ puts "x_speed >> #{x_speed}"
28
+ puts "y_speed >> #{y_speed}"
29
+ puts "motion_accel >> #{motion_accel}"
30
+ end
31
+
32
+
33
+ private
34
+ def args_to_container_from_cursor( args )
35
+ #session_id,
36
+ [ args[0],
37
+
38
+ # x_pos
39
+ args[1],
40
+
41
+ # y_pos
42
+ args[2],
43
+
44
+ # x_speed
45
+ args[3],
46
+
47
+ # y_speed
48
+ args[4],
49
+
50
+ # motion_accel
51
+ args[5] ]
52
+ end
53
+ end
@@ -0,0 +1,80 @@
1
+ require 'tuio_container'
2
+
3
+ class TuioObject
4
+ attr_reader :angle, :fiducial_id, :rotation_speed, :rotation_accel
5
+
6
+ include TuioContainer
7
+
8
+ def initialize( session_id, fiducial_id, x_pos, y_pos, angle )
9
+ super( session_id, x_pos, y_pos )
10
+
11
+ @fiducial_id = fiducial_id
12
+ @angle = angle
13
+
14
+ @rotation_speed = 0.0
15
+ @rotation_accel = 0.0
16
+ end
17
+
18
+ def update( x_pos, y_pos, angle, x_speed, y_speed, rotation_speed, motion_accel, rotation_accel )
19
+ super( x_pos, y_pos, x_speed, y_speed, motion_accel )
20
+
21
+ @angle = angle
22
+ @rotation_speed = rotation_speed
23
+ @rotation_accel = rotation_accel
24
+ end
25
+
26
+ def args_equal?( args )
27
+ fiducial_id == args[1] &&
28
+ rotation_speed.approx_equal?( args[7] ) &&
29
+ rotation_accel.approx_equal?( args[9] ) &&
30
+ super( args_to_container_from_object( args ) )
31
+ end
32
+
33
+ def to_args
34
+ [ session_id,
35
+ fiducial_id,
36
+ x_pos,
37
+ y_pos,
38
+ angle,
39
+ x_speed,
40
+ y_speed,
41
+ rotation_speed,
42
+ motion_accel,
43
+ rotation_accel]
44
+ end
45
+
46
+ def inspect
47
+ puts "TuioObject:"
48
+ puts "session_id >> #{session_id}"
49
+ puts "fiducial_id >> #{fiducial_id}"
50
+ puts "x_pos >> #{x_pos}"
51
+ puts "y_pos >> #{y_pos}"
52
+ puts "angle >> #{angle}"
53
+ puts "x_speed >> #{x_speed}"
54
+ puts "y_speed >> #{y_speed}"
55
+ puts "rotation_speed >> #{rotation_speed}"
56
+ puts "motion_accel >> #{motion_accel}"
57
+ puts "rotation_accel >> #{rotation_accel}"
58
+ end
59
+
60
+ private
61
+ def args_to_container_from_object( args )
62
+ #session_id,
63
+ [ args[0],
64
+
65
+ # x_pos
66
+ args[2],
67
+
68
+ # y_pos
69
+ args[3],
70
+
71
+ # x_speed
72
+ args[5],
73
+
74
+ # y_speed
75
+ args[6],
76
+
77
+ # motion_accel
78
+ args[8] ]
79
+ end
80
+ end
@@ -0,0 +1,45 @@
1
+ class TuioPoint
2
+ attr_accessor :x_pos, :y_pos, :updated_at
3
+
4
+ def initialize( x_pos, y_pos )
5
+ @x_pos, @y_pos = x_pos, y_pos
6
+ end
7
+
8
+ def update( x_pos, y_pos )
9
+ @x_pos, @y_pos = x_pos, y_pos
10
+
11
+ clear_update_time
12
+ end
13
+
14
+ def distance_to( another_point )
15
+ dx = @x_pos - another_point.x_pos
16
+ dy = @y_pos - another_point.y_pos
17
+
18
+ Math.sqrt( dx*dx + dy*dy )
19
+ end
20
+
21
+ def radians_to( another_point )
22
+ side = another_point.x_pos - @x_pos
23
+ height = another_point.y_pos - @y_pos
24
+ distance = distance_to( another_point )
25
+
26
+ angle = Math.asin( side / distance ) + Math::PI / 2
27
+ angle = 2.0 * Math.PI - angle if height < 0
28
+ angle
29
+ end
30
+
31
+ def degrees_to( another_point )
32
+ ( radians_to( another_point ) / Math::PI ) * 180.0
33
+ end
34
+
35
+ def eql?( another_point )
36
+ @x_pos == another_point.x_pos &&
37
+ @y_pos == another_point.y_pos
38
+ end
39
+
40
+ private
41
+
42
+ def clear_update_time
43
+ @updated_at = nil
44
+ end
45
+ end
@@ -0,0 +1,165 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe "tuio object" do
4
+ before :each do
5
+ setup_server
6
+ end
7
+
8
+ describe "in general" do
9
+ it "should call the creation hook" do
10
+ @server.on_object_creation do | object |
11
+ raise "creation hook called!" if object.session_id == 49
12
+ end
13
+
14
+ lambda {
15
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
16
+ }.should raise_error
17
+
18
+ lambda {
19
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
20
+ }.should_not raise_error
21
+ end
22
+
23
+ it "should call the update hook when session_id is set again with different location" do
24
+ @server.on_object_update do | object |
25
+ raise "update hook called!" if object.session_id == 49
26
+ end
27
+
28
+ lambda {
29
+ # this one calls the create hook
30
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
31
+ send_message( '/tuio/2Dobj', "alive", 49)
32
+
33
+ #this one is the same as before, so nothing to update
34
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
35
+ send_message( '/tuio/2Dobj', "alive", 49)
36
+ }.should_not raise_error
37
+
38
+
39
+ lambda {
40
+ #this one calls the update hook
41
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.12, 0.12, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
42
+ send_message( '/tuio/2Dobj', "alive", 49)
43
+
44
+ }.should raise_error
45
+ end
46
+
47
+ it "should call the removal hook when an object is not on the alive list" do
48
+ @server.on_object_removal do | object |
49
+ raise "removal hook called!" if object.session_id == 51
50
+ end
51
+
52
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
53
+ send_message( '/tuio/2Dobj', "set", 51, 26, 0.12, 0.50, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
54
+
55
+ lambda {
56
+ send_message( '/tuio/2Dobj', "alive", 49)
57
+ }.should raise_error
58
+
59
+ end
60
+ end
61
+
62
+ describe "receiving message" do
63
+ before :each do
64
+ send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
65
+ end
66
+
67
+ describe "set" do
68
+ it 'should update tracking' do
69
+ @server.tuio_objects.size.should == 1
70
+ @server.tuio_objects[49].fiducial_id.should == 25
71
+ end
72
+ end
73
+
74
+ describe "alive" do
75
+ it 'should only keep alive the objects the client says are alive' do
76
+ send_message( '/tuio/2Dobj', "set", 51, 26, 0.12, 0.50, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
77
+ send_message( '/tuio/2Dobj', "alive", 49)
78
+
79
+ @server.tuio_objects.size.should == 1
80
+ end
81
+ end
82
+
83
+ describe "fseq" do
84
+ it "should probably have a test!"
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "tuio_cursors" do
90
+ before :each do
91
+ setup_server
92
+ end
93
+
94
+ it 'should update tracking' do
95
+ send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
96
+
97
+ @server.tuio_cursors.size.should == 1
98
+ end
99
+
100
+ it 'should update tracking for multiples' do
101
+ send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
102
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
103
+
104
+
105
+ @server.tuio_cursors.size.should == 2
106
+ end
107
+
108
+ it 'should only keep alive the cursors the client says are alive' do
109
+ send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
110
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
111
+
112
+ send_message( '/tuio/2Dcur', "alive", 22)
113
+
114
+ @server.tuio_cursors.size.should == 1
115
+ @server.tuio_cursors[22].session_id.should == 22
116
+ end
117
+
118
+ it "should call the creation hooks" do
119
+ @server.on_cursor_creation do | objects |
120
+ raise "create! hook called!"
121
+ end
122
+
123
+ lambda {
124
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
125
+ }.should raise_error
126
+ end
127
+
128
+ it "should call the update hooks" do
129
+ @server.on_cursor_update do | objects |
130
+ raise "update hook called!"
131
+ end
132
+
133
+ lambda {
134
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
135
+ send_message( '/tuio/2Dcur', "alive", 27)
136
+
137
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
138
+ send_message( '/tuio/2Dcur', "alive", 27)
139
+
140
+ }.should_not raise_error
141
+
142
+ lambda {
143
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.32, 0.0, 0.0, 0.0 )
144
+ send_message( '/tuio/2Dcur', "alive", 27)
145
+
146
+ }.should raise_error
147
+
148
+ end
149
+
150
+ it "should call the removal hooks" do
151
+ @server.on_cursor_removal do | objects |
152
+ raise "removal hook called!"
153
+ end
154
+
155
+ lambda {
156
+ send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
157
+ send_message( '/tuio/2Dcur', "set", 32, 0.18, 0.98, 0.0, 0.0, 0.0 )
158
+ }.should_not raise_error
159
+
160
+ lambda {
161
+ send_message( '/tuio/2Dcur', "alive", 27)
162
+
163
+ }.should raise_error
164
+ end
165
+ end
@@ -2,14 +2,15 @@ require 'rubygems'
2
2
  require 'spec'
3
3
  require 'rr'
4
4
  require 'osc'
5
- require 'lib/tuio_client'
5
+
6
+ require File.join( File.dirname( __FILE__ ), '..', 'lib', 'tuio_client' )
6
7
 
7
8
  Spec::Runner.configure do |config|
8
9
  config.mock_with RR::Adapters::Rspec
9
10
  end
10
11
 
11
12
  # monkey patch to get at osc core to send messages
12
- class TUIOClient
13
+ class TuioClient
13
14
  def osc
14
15
  @osc
15
16
  end
@@ -29,5 +30,5 @@ def setup_server
29
30
  stub(socket).bind("", 3333)
30
31
  stub(UDPSocket).new { socket }
31
32
 
32
- @server = TUIOClient.new
33
+ @server = TuioClient.new
33
34
  end
@@ -0,0 +1,74 @@
1
+ # require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+ #
3
+ # class TuioContainer
4
+ # # we want to be able to instantiate this class for testing
5
+ # def self.abstract?
6
+ # false
7
+ # end
8
+ # end
9
+ #
10
+ # describe TuioContainer do
11
+ # before :each do
12
+ # @session_id = 42
13
+ # @x_pos = 0.8
14
+ # @y_pos = 0.3
15
+ # @tc = TuioContainer.new( @session_id, @x_pos, @y_pos )
16
+ # end
17
+ #
18
+ # describe "in general" do
19
+ # it "should know it's session id" do
20
+ # @tc.session_id.should == @session_id
21
+ # end
22
+ #
23
+ # it "should know it's x position" do
24
+ # @tc.x_pos.should == @x_pos
25
+ # end
26
+ #
27
+ # it "should know its y position" do
28
+ # @tc.y_pos.should == @y_pos
29
+ # end
30
+ # end
31
+ #
32
+ # describe "updates" do
33
+ # before :each do
34
+ # @x_pos2 = 0.7
35
+ # @y_pos2 = 0.4
36
+ # @x_speed = 0.1
37
+ # @y_speed = 0.1
38
+ # @motion_accel = 0.1
39
+ #
40
+ # @tc.update( @x_pos2, @y_pos2, @x_speed, @y_speed, @motion_accel )
41
+ # end
42
+ #
43
+ # it "should know it's new x position" do
44
+ # @tc.x_pos.should == @x_pos2
45
+ # end
46
+ #
47
+ # it "should know it's new y position" do
48
+ # @tc.y_pos.should == @y_pos2
49
+ # end
50
+ #
51
+ # it "should know it's x speed" do
52
+ # @tc.x_speed.should == @x_speed
53
+ # end
54
+ #
55
+ # it "should know it's y speed" do
56
+ # @tc.y_speed.should == @y_speed
57
+ # end
58
+ #
59
+ # it "should know it's motion acceleration" do
60
+ # @tc.motion_accel.should == @motion_accel
61
+ # end
62
+ #
63
+ # it "should know the path it's traveled" do
64
+ # first = @tc.path.first
65
+ # second = @tc.path.last
66
+ #
67
+ # first.x_pos.should == 0.8
68
+ # first.y_pos.should == 0.3
69
+ #
70
+ # second.x_pos.should == 0.7
71
+ # second.y_pos.should == 0.4
72
+ # end
73
+ # end
74
+ # end
@@ -0,0 +1,29 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe TuioCursor do
4
+ before :each do
5
+ @args1 = [
6
+ @session_id = 42,
7
+ @x_pos = 0.8,
8
+ @y_pos = 0.4,
9
+ ]
10
+ @tc = TuioCursor.new( *@args1 )
11
+ end
12
+
13
+ describe "update" do
14
+ before :each do
15
+ @args2 = [
16
+ @x_pos2 = 0.23,
17
+ @y_pos2 = 0.54,
18
+ @x_speed = 0.01,
19
+ @y_speed = 0.03,
20
+ @motion_accel = 0.02
21
+ ]
22
+ @tc.update( *@args2 )
23
+ end
24
+
25
+ it "should it is equal to some arguments" do
26
+ @tc.args_equal?( [@session_id, @x_pos, @y_pos] )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,96 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe TuioObject do
4
+ before :each do
5
+ @args1 = [
6
+ @session_id = 42,
7
+ @fiducial_id = 1,
8
+ @x_pos = 0.8,
9
+ @y_pos = 0.4,
10
+ @angle = 1
11
+ ]
12
+ @to = TuioObject.new( *@args1 )
13
+ end
14
+
15
+ describe "in general" do
16
+ it "should know it's session id" do
17
+ @to.session_id.should == @session_id
18
+ end
19
+
20
+ it "should know it's fiducial id" do
21
+ @to.fiducial_id.should == @fiducial_id
22
+ end
23
+
24
+ it "should know it's x position" do
25
+ @to.x_pos.should == @x_pos
26
+ end
27
+
28
+ it "should know it's y postion" do
29
+ @to.y_pos.should == @y_pos
30
+ end
31
+
32
+ it "should know it's angle" do
33
+ @to.angle.should == @angle
34
+ end
35
+ end
36
+
37
+ describe "on update" do
38
+ before :each do
39
+ @args2 = [
40
+ @x_pos2 = 0.7,
41
+ @y_pos2 = 0.4,
42
+ @angle2 = 1.1,
43
+ @x_speed = 0.1,
44
+ @y_speed = 0.2,
45
+ @rotation_speed = 0.11,
46
+ @motion_accel = 0.12,
47
+ @rotation_accel = 0.13
48
+ ]
49
+
50
+ @to.update( *@args2 )
51
+ end
52
+
53
+ it "should be able to compare it's args" do
54
+ @to.args_equal?( [
55
+ @session_id,
56
+ @fiducial_id,
57
+ @x_pos2,
58
+ @y_pos2,
59
+ @angle2,
60
+ @x_speed,
61
+ @y_speed,
62
+ @rotation_speed,
63
+ @motion_accel,
64
+ @rotation_accel
65
+ ]).should be_true
66
+ end
67
+
68
+ it "should know it's new x position" do
69
+ @to.x_pos.should == @x_pos2
70
+ end
71
+
72
+ it "should know it's new y position" do
73
+ @to.y_pos.should == @y_pos2
74
+ end
75
+
76
+ it "should know it's new angle" do
77
+ @to.angle.should == @angle2
78
+ end
79
+
80
+ it "should know it's x speed" do
81
+ @to.x_speed.should == @x_speed
82
+ end
83
+
84
+ it "should know it's y speed" do
85
+ @to.y_speed.should == @y_speed
86
+ end
87
+
88
+ it "should know it's rotation speed" do
89
+ @to.rotation_speed.should == @rotation_speed
90
+ end
91
+
92
+ it "should know it's rotation accel" do
93
+ @to.rotation_accel.should == @rotation_accel
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,46 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe TuioPoint do
4
+ before :each do
5
+ @location1 = [0.1, 0.1]
6
+ @location2 = [0.1, 0.21]
7
+
8
+ @point1 = TuioPoint.new( *@location1 )
9
+ @point2 = TuioPoint.new( *@location2 )
10
+ end
11
+
12
+ describe "in general" do
13
+ it "should know the distance to another point" do
14
+ # not a wonderful test, but a sanity check
15
+ @point1.distance_to( @point2 ).should be_close( 0.11, 0.00001 )
16
+ end
17
+
18
+ it "should know the angle to another point" do
19
+ # not a wonderful test, but a sanity check
20
+ @point1.radians_to( @point2 ).should be_close( 1.5707963, 0.00001 )
21
+ end
22
+
23
+ it "should know when it was last updated" do
24
+ @point1.should respond_to(:updated_at)
25
+ end
26
+
27
+ it "should know if it is equal to another point" do
28
+ @other_point = TuioPoint.new( *@location1 )
29
+
30
+ @point1.should be_eql( @other_point )
31
+ end
32
+ end
33
+
34
+ describe "updates" do
35
+ before :each do
36
+ @point1.updated_at = Time.now
37
+
38
+ @point1.update( *@location2 )
39
+ end
40
+
41
+ it "should clear the updated at time" do
42
+ @point1.updated_at.should == nil
43
+ end
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aberant-tuio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aberant
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -07:00
12
+ date: 2009-04-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,9 +25,23 @@ extra_rdoc_files:
25
25
  files:
26
26
  - README.rdoc
27
27
  - VERSION.yml
28
+ - lib/core_ext
29
+ - lib/core_ext/float.rb
30
+ - lib/core_ext/object.rb
31
+ - lib/my_environment.rb
28
32
  - lib/tuio_client.rb
33
+ - lib/tuio_container.rb
34
+ - lib/tuio_cursor.rb
35
+ - lib/tuio_object.rb
36
+ - lib/tuio_point.rb
37
+ - spec/integration
38
+ - spec/integration/tuio_event_spec.rb
29
39
  - spec/spec_helper.rb
30
- - spec/tuio_event_spec.rb
40
+ - spec/unit
41
+ - spec/unit/tuio_container_spec.rb
42
+ - spec/unit/tuio_cursor_spec.rb
43
+ - spec/unit/tuio_object_spec.rb
44
+ - spec/unit/tuio_point_spec.rb
31
45
  - LICENSE
32
46
  has_rdoc: true
33
47
  homepage: http://github.com/aberant/tuio-ruby
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "tuio objects" do
4
- before :each do
5
- setup_server
6
- end
7
-
8
- it 'should update tracking' do
9
- send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
10
-
11
- @server.tuio_objects.size.should == 1
12
- @server.tuio_objects[49][:class_id].should == 25
13
- end
14
-
15
- it 'should only keep alive the objects the client says are alive' do
16
- send_message( '/tuio/2Dobj', "set", 49, 25, 0.38, 0.35, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
17
- send_message( '/tuio/2Dobj', "set", 51, 26, 0.12, 0.50, 3.14, 0.0, 0.0, 0.0, 0.0, 0.0 )
18
-
19
- send_message( '/tuio/2Dobj', "alive", 49)
20
-
21
- @server.tuio_objects.size.should == 1
22
- end
23
-
24
- end
25
-
26
- describe "tuio_cursors" do
27
- before :each do
28
- setup_server
29
- end
30
-
31
- it 'should update tracking' do
32
- send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
33
-
34
- @server.tuio_cursors.size.should == 1
35
- end
36
-
37
- it 'should update tracking for multiples' do
38
- send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
39
- send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
40
-
41
-
42
- @server.tuio_cursors.size.should == 2
43
- end
44
-
45
- it 'should only keep alive the cursors the client says are alive' do
46
- send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
47
- send_message( '/tuio/2Dcur', "set", 27, 0.12, 0.50, 0.0, 0.0, 0.0 )
48
-
49
- send_message( '/tuio/2Dcur', "alive", 22)
50
-
51
- @server.tuio_cursors.size.should == 1
52
- @server.tuio_cursors[22][:session_id].should == 22
53
-
54
- end
55
- end