aberant-tuio-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,10 @@ You will need the OSC gem
12
12
 
13
13
  [sudo] gem install aberant-tuio-ruby
14
14
 
15
+ == EXAMPLE:
16
+
17
+ please see tuio_dump.rb in the example folder for basic useage
18
+
15
19
  == COPYRIGHT:
16
20
 
17
21
  Copyright (c) 2009 Colin Harris. See LICENSE for details.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
2
+ :minor: 2
3
3
  :patch: 0
4
4
  :major: 0
@@ -1,5 +1,5 @@
1
1
  class Float
2
- def approx_equal?(other,threshold=0.00001)
2
+ def approx_equal?(other,threshold=0.00000000001)
3
3
  (self-other).abs < threshold
4
4
  end
5
5
  end
@@ -1,9 +1,28 @@
1
+ # this is a little meta magic to clean up some of the repetition in the client
2
+ # i noticed that i kept making the same similiar methods for each event such as
3
+ #
4
+ # client_events :object_creation
5
+ #
6
+ # which causes these two methods to be created
7
+
8
+ # def on_object_creation( &object_creation_blk )
9
+ # @object_creation_callback_blk = object_creation_blk
10
+ # end
11
+ #
12
+ # def trigger_object_creation_callback( tuio )
13
+ # @object_creation_callback_blk.call( tuio ) if @object_creation_callback_blk
14
+ # end
15
+
1
16
  class Object
2
- def client_block_setter( *args )
3
- args.each do | blk_setter_name |
17
+ def client_events( *args )
18
+ args.each do | event |
4
19
  self.class_eval <<-EOF
5
- def on_#{blk_setter_name}( &#{blk_setter_name}_blk )
6
- @#{blk_setter_name}_callback_blk = #{blk_setter_name}_blk
20
+ def on_#{event}( &#{event}_blk )
21
+ @#{event}_callback_blk = #{event}_blk
22
+ end
23
+
24
+ def trigger_#{event}_callback( tuio )
25
+ @#{event}_callback_blk.call( tuio ) if @#{event}_callback_blk
7
26
  end
8
27
  EOF
9
28
  end
@@ -5,12 +5,18 @@ require File.join( File.dirname( __FILE__ ), 'my_environment')
5
5
 
6
6
  require "tuio_object"
7
7
  require "tuio_cursor"
8
+ require 'tuio_object_parameter'
9
+ require 'tuio_cursor_parameter'
10
+
8
11
 
9
12
  class TuioClient
10
13
  include OSC
11
14
 
12
- client_block_setter :object_creation, :object_update, :object_removal
13
- client_block_setter :cursor_creation, :cursor_update, :cursor_removal
15
+ attr_reader :tuio_objects, :tuio_cursors
16
+
17
+
18
+ client_events :object_creation, :object_update, :object_removal
19
+ client_events :cursor_creation, :cursor_update, :cursor_removal
14
20
 
15
21
  def initialize( args = {} )
16
22
  @port = args[:port] || 3333
@@ -57,98 +63,61 @@ class TuioClient
57
63
  # getters #
58
64
  ####################################
59
65
 
60
- def tuio_objects
61
- @tuio_objects
62
- end
63
-
64
66
  def tuio_object( id )
65
67
  @tuio_objects[id]
66
68
  end
67
69
 
68
- def tuio_cursors
69
- @tuio_cursors
70
- end
71
-
72
70
  def tuio_cursor( id )
73
71
  @tuio_cursors[id]
74
72
  end
75
73
 
76
- ####################################
77
- # call backs #
78
- ####################################
79
-
80
- # def on_cursor_update( &cur_update_blk )
81
- # @cur_update_blk = cur_update_blk
82
- # end
83
-
84
74
  private
85
75
 
86
76
  def track_tuio_object( args )
87
- session_id = session_id_from( args )
88
-
89
- if tuio_object_previously_tracked?( session_id )
77
+ params = TuioObjectParameter.new( *args )
78
+
79
+ if tuio_object_previously_tracked?( params )
90
80
 
91
- tuio_object = grab_tuio_object_by( session_id )
81
+ tuio_object = grab_tuio_object_by( params.session_id )
92
82
 
93
- return if tuio_object.args_equal?( args )
83
+ return if tuio_object.params_equal?( params )
94
84
 
95
- tuio_object.update( *update_object_params_from( args ) )
85
+ tuio_object.update_from_params( params )
96
86
 
97
87
  trigger_object_update_callback( tuio_object )
98
- else
99
- tuio_object = track_new_tuio_object_with( session_id, args )
88
+ else # this is a new object
89
+ tuio_object = track_new_tuio_object_with( params )
100
90
 
101
91
  trigger_object_creation_callback( tuio_object )
102
92
  end
103
93
  end
104
94
 
105
95
  def track_tuio_cursor( args )
106
- session_id = session_id_from( args )
96
+ params = TuioCursorParameter.new( *args )
107
97
 
108
- if tuio_cursor_previously_tracked?( session_id )
109
- tuio_cursor = grab_tuio_cursor_by( session_id )
98
+ if tuio_cursor_previously_tracked?( params )
110
99
 
111
- return if tuio_cursor.args_equal?( args )
112
- tuio_cursor.update( *update_cursor_params_from( args ))
100
+ tuio_cursor = grab_tuio_cursor_by( params.session_id )
101
+
102
+ return if tuio_cursor.params_equal?( params )
103
+ tuio_cursor.update_from_params( params )
113
104
 
114
105
  trigger_cursor_update_callback( tuio_cursor )
115
106
 
116
107
  else # this is a new cursor
117
108
  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
109
+ tuio_cursor = track_new_tuio_cursor_with( params )
140
110
 
141
- def update_cursor_params_from( args )
142
- args[1..5]
111
+ trigger_cursor_creation_callback( tuio_cursor )
112
+ end
143
113
  end
144
-
145
114
 
146
- def tuio_object_previously_tracked?( session_id )
147
- @tuio_objects.has_key?( session_id )
115
+ def tuio_object_previously_tracked?( params )
116
+ @tuio_objects.has_key?( params.session_id )
148
117
  end
149
118
 
150
- def tuio_cursor_previously_tracked?( session_id )
151
- @tuio_cursors.has_key?( session_id )
119
+ def tuio_cursor_previously_tracked?( params )
120
+ @tuio_cursors.has_key?( params.session_id )
152
121
  end
153
122
 
154
123
  def grab_tuio_object_by( session_id )
@@ -159,56 +128,32 @@ private
159
128
  @tuio_cursors[session_id]
160
129
  end
161
130
 
162
- def track_new_tuio_object_with( session_id, args )
163
- @tuio_objects[session_id] = TuioObject.new( *new_object_params_from( args ) )
131
+ def track_new_tuio_object_with( tuio_params )
132
+ @tuio_objects[tuio_params.session_id] = TuioObject.from_params( tuio_params )
164
133
  end
165
134
 
166
- def track_new_tuio_cursor_with( session_id, args )
167
- @tuio_cursors[session_id] = TuioCursor.new( *new_cursor_params_from( args ) )
135
+ def track_new_tuio_cursor_with( params )
136
+ new_cursor = TuioCursor.from_params( params )
137
+ @tuio_cursors[params.session_id] = new_cursor
138
+
139
+ new_cursor.finger_id = @tuio_cursors.size
140
+ new_cursor
168
141
  end
169
-
142
+
170
143
  ####################################
171
- # call backs #
144
+ # "alive" msgs #
172
145
  ####################################
173
146
 
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
147
  def delete_tuio_objects( session_id )
203
148
  tuio_object = grab_tuio_object_by( session_id )
204
149
 
205
- trigger_object_deletion_callback( tuio_object )
150
+ trigger_object_removal_callback( tuio_object )
206
151
  end
207
152
 
208
153
  def delete_tuio_cursors( session_id )
209
154
  tuio_cursor = grab_tuio_cursor_by( session_id )
210
155
 
211
- trigger_cursor_deletion_callback( tuio_cursor )
156
+ trigger_cursor_removal_callback( tuio_cursor )
212
157
  end
213
158
 
214
159
 
@@ -224,8 +169,4 @@ private
224
169
  send( type ).delete( session_id )
225
170
  end
226
171
  end
227
- end
228
-
229
- if $0 == __FILE__
230
- TuioClient.new.start
231
172
  end
@@ -1,14 +1,13 @@
1
1
  require 'tuio_point'
2
2
 
3
- module TuioContainer
3
+ class TuioContainer < TuioPoint
4
4
  attr_accessor :session_id, :x_pos, :y_pos, :x_speed, :y_speed, :motion_accel
5
5
 
6
6
 
7
7
  def initialize( session_id, x_pos, y_pos )
8
+ super( x_pos, y_pos )
9
+
8
10
  @session_id = session_id
9
- @x_pos = x_pos
10
- @y_pos = y_pos
11
-
12
11
  @x_speed = 0.0
13
12
  @y_speed = 0.0
14
13
  @motion_accel = 0.0
@@ -17,8 +16,8 @@ module TuioContainer
17
16
  end
18
17
 
19
18
  def update( x_pos, y_pos, x_speed, y_speed, motion_accel )
20
- @x_pos = x_pos
21
- @y_pos = y_pos
19
+ super( x_pos, y_pos )
20
+
22
21
  @x_speed = x_speed
23
22
  @y_speed = y_speed
24
23
  @motion_accel = motion_accel
@@ -27,17 +26,31 @@ module TuioContainer
27
26
  add_point_to_path( new_point ) unless new_point == @path.last
28
27
  end
29
28
 
29
+ def update_from_params( params )
30
+ @x_pos = params.x_pos
31
+ @y_pos = params.y_pos
32
+ @x_speed = params.x_speed
33
+ @y_speed = params.y_speed
34
+ @motion_accel = params.motion_accel
35
+ end
36
+
30
37
  def path
31
38
  @path
32
39
  end
33
40
 
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
+
42
+ def params_equal?( params )
43
+ @session_id == params.session_id &&
44
+ @x_pos.approx_equal?( params.x_pos ) &&
45
+ @y_pos.approx_equal?( params.y_pos ) &&
46
+ @x_speed.approx_equal?( params.x_speed ) &&
47
+ @y_speed.approx_equal?( params.y_speed ) &&
48
+ @motion_accel.approx_equal?( params.motion_accel ) &&
49
+ equal_to_local_params?( params )
50
+ end
51
+
52
+ def equal_to_local_args?(args)
53
+ true
41
54
  end
42
55
 
43
56
  private
@@ -1,53 +1,28 @@
1
- class TuioCursor
2
- include TuioContainer
1
+ require 'tuio_container'
2
+
3
+ class TuioCursor < TuioContainer
4
+
5
+ attr_accessor :finger_id
6
+ attr_reader :x_speed, :y_speed, :motion_accel
3
7
 
4
- attr_reader :finger_id, :x_speed, :y_speed, :motion_accel
8
+ def self.from_params( params )
9
+ new( params.session_id,
10
+ params.x_pos,
11
+ params.y_pos
12
+ )
13
+ end
5
14
 
6
- def initialize( session_id, x_pos, y_pos ) #, x_speed, y_speed, motion_accel )
15
+ def initialize( session_id, x_pos, y_pos )
7
16
  super( session_id, x_pos, y_pos )
8
17
 
9
18
  @x_speed = 0.0
10
19
  @y_speed = 0.0
11
20
  @motion_accel = 0.0
12
21
  end
22
+
13
23
 
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}"
24
+ def equal_to_local_params?( params )
25
+ true
30
26
  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
27
 
44
- # x_speed
45
- args[3],
46
-
47
- # y_speed
48
- args[4],
49
-
50
- # motion_accel
51
- args[5] ]
52
- end
53
28
  end
@@ -0,0 +1,7 @@
1
+ require 'tuio_parameter'
2
+
3
+ # /tuio/2Dcur set s x y X Y m
4
+
5
+ class TuioCursorParameter < TuioParameter
6
+
7
+ end
@@ -1,80 +1,53 @@
1
1
  require 'tuio_container'
2
2
 
3
- class TuioObject
4
- attr_reader :angle, :fiducial_id, :rotation_speed, :rotation_accel
3
+ class TuioObject < TuioContainer
4
+ attr_reader :angle, :fiducial_id, :rotation_vector, :rotation_accel
5
+
6
+ def self.from_params( params )
7
+ new(
8
+ params.session_id,
9
+ params.fiducial_id,
10
+ params.x_pos,
11
+ params.y_pos,
12
+ params.angle
13
+ )
14
+ end
5
15
 
6
- include TuioContainer
7
16
 
8
17
  def initialize( session_id, fiducial_id, x_pos, y_pos, angle )
9
18
  super( session_id, x_pos, y_pos )
10
-
19
+
11
20
  @fiducial_id = fiducial_id
12
21
  @angle = angle
13
22
 
14
- @rotation_speed = 0.0
23
+ @rotation_vector = 0.0
15
24
  @rotation_accel = 0.0
16
- end
25
+ end
17
26
 
18
- def update( x_pos, y_pos, angle, x_speed, y_speed, rotation_speed, motion_accel, rotation_accel )
27
+ def update_from_params( tuio_params )
28
+ update(
29
+ tuio_params.x_pos,
30
+ tuio_params.y_pos,
31
+ tuio_params.angle,
32
+ tuio_params.x_speed,
33
+ tuio_params.y_speed,
34
+ tuio_params.rotation_vector,
35
+ tuio_params.motion_accel,
36
+ tuio_params.rotation_accel
37
+ )
38
+ end
39
+
40
+ def update( x_pos, y_pos, angle, x_speed, y_speed, rotation_vector, motion_accel, rotation_accel )
19
41
  super( x_pos, y_pos, x_speed, y_speed, motion_accel )
20
42
 
21
43
  @angle = angle
22
- @rotation_speed = rotation_speed
44
+ @rotation_vector = rotation_vector
23
45
  @rotation_accel = rotation_accel
24
46
  end
25
47
 
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] ]
48
+ def equal_to_local_params?( params )
49
+ fiducial_id == params.fiducial_id &&
50
+ rotation_vector.approx_equal?( params.rotation_vector ) &&
51
+ rotation_accel.approx_equal?( params.rotation_accel )
79
52
  end
80
53
  end
@@ -0,0 +1,16 @@
1
+ require 'tuio_parameter'
2
+ # /tuio/2Dobj set s i x y a X Y A m r
3
+
4
+
5
+ class TuioObjectParameter < TuioParameter
6
+ attr_reader :angle, :fiducial_id, :rotation_vector, :rotation_accel
7
+
8
+ def initialize( session_id, fiducial_id, x_pos, y_pos, angle, x_speed, y_speed, rotation_vector, motion_accel, rotation_accel )
9
+ super( session_id, x_pos, y_pos, x_speed, y_speed, motion_accel )
10
+
11
+ @fiducial_id = fiducial_id
12
+ @angle = angle
13
+ @rotation_vector = rotation_vector
14
+ @rotation_accel = rotation_accel
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class TuioParameter
2
+ attr_accessor :session_id, :x_pos, :y_pos, :x_speed, :y_speed, :motion_accel
3
+
4
+ def self.new_from_initial_params( session_id, x_pos, y_pos )
5
+ new session_id, x_pos, y_pos, 0.0, 0.0, 00
6
+ end
7
+
8
+ def initialize( session_id, x_pos, y_pos, x_speed, y_speed, motion_accel )
9
+ @session_id = session_id
10
+ @x_pos = x_pos
11
+ @y_pos = y_pos
12
+ @x_speed = x_speed
13
+ @y_speed = y_speed
14
+ @motion_accel = motion_accel
15
+ end
16
+ end
@@ -66,7 +66,7 @@ describe "tuio object" do
66
66
 
67
67
  describe "set" do
68
68
  it 'should update tracking' do
69
- @server.tuio_objects.size.should == 1
69
+ @server.tuio_objects.size.should eql( 1 )
70
70
  @server.tuio_objects[49].fiducial_id.should == 25
71
71
  end
72
72
  end
@@ -0,0 +1,39 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+ require File.join( File.dirname(__FILE__) , 'tuio_parameter_spec' )
3
+
4
+ # /tuio/2Dcur set s x y X Y m
5
+
6
+ describe TuioObjectParameter do
7
+ describe "cursor creation" do
8
+ before :each do
9
+ args = [ @session_id = 12,
10
+ @x_pos = 0.1,
11
+ @y_pos = 0.2]
12
+
13
+ @tuio_param = TuioCursorParameter.new_from_initial_params( *args )
14
+ end
15
+ it "should have propper values set" do
16
+ @tuio_param.session_id == @session_id
17
+ @tuio_param.x_pos == @x_pos
18
+ @tuio_param.y_pos == @y_pos
19
+ end
20
+ end
21
+
22
+ describe "in general" do
23
+ before :each do
24
+ args = [
25
+ @session_id = 12,
26
+ @x_pos = 0.1,
27
+ @y_pos = 0.2,
28
+ @x_speed = 0.01,
29
+ @y_speed = 0.02,
30
+ @motion_accel = 0.03,
31
+ ]
32
+
33
+ @tuio_param = TuioCursorParameter.new( *args )
34
+ end
35
+
36
+ it_should_behave_like "TuioParameter"
37
+ end
38
+
39
+ end
@@ -6,24 +6,30 @@ describe TuioCursor do
6
6
  @session_id = 42,
7
7
  @x_pos = 0.8,
8
8
  @y_pos = 0.4,
9
+ @x_speed = 0.01,
10
+ @y_speed = 0.03,
11
+ @motion_accel = 0.02
9
12
  ]
10
- @tc = TuioCursor.new( *@args1 )
13
+ @params = TuioCursorParameter.new( *@args1 )
14
+ @tc = TuioCursor.from_params( @params )
11
15
  end
12
16
 
13
17
  describe "update" do
14
18
  before :each do
15
19
  @args2 = [
20
+ @session_id = 42,
16
21
  @x_pos2 = 0.23,
17
22
  @y_pos2 = 0.54,
18
23
  @x_speed = 0.01,
19
24
  @y_speed = 0.03,
20
25
  @motion_accel = 0.02
21
26
  ]
22
- @tc.update( *@args2 )
27
+ @update_params = TuioCursorParameter.new( *@args2 )
28
+ @tc.update_from_params( @update_params )
23
29
  end
24
30
 
25
31
  it "should it is equal to some arguments" do
26
- @tc.args_equal?( [@session_id, @x_pos, @y_pos] )
32
+ @tc.params_equal?( @update_params )
27
33
  end
28
34
  end
29
35
  end
@@ -0,0 +1,41 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+ require File.join( File.dirname(__FILE__) , 'tuio_parameter_spec' )
3
+
4
+ # /tuio/2Dobj set s i x y a X Y A m r
5
+ # /tuio/2Dcur set s x y X Y m
6
+ #def initialize( session_id, fiducial_id, x_pos, y_pos, angle,
7
+ # x_speed, y_speed, rotation_vector, motion_accel, rotation_accel )
8
+
9
+ describe TuioObjectParameter do
10
+
11
+ before :each do
12
+ args = [
13
+ @session_id = 12,
14
+ @fiducial_id = 41,
15
+ @x_pos = 0.1,
16
+ @y_pos = 0.2,
17
+ @angle = 3,
18
+ @x_speed = 0.01,
19
+ @y_speed = 0.02,
20
+ @rotation_vector = 0.4,
21
+ @motion_accel = 0.03,
22
+ @rotation_accel = 0.02
23
+ ]
24
+
25
+ @tuio_param = TuioObjectParameter.new( *args )
26
+ end
27
+
28
+ it_should_behave_like "TuioParameter"
29
+
30
+ it "should fetch angle" do
31
+ @tuio_param.angle.should == @angle
32
+ end
33
+
34
+ it "should fetch rotation vector" do
35
+ @tuio_param.rotation_vector.should == @rotation_vector
36
+ end
37
+
38
+ it "should fetch rotation acceleration" do
39
+ @tuio_param.rotation_accel.should == @rotation_accel
40
+ end
41
+ end
@@ -7,9 +7,15 @@ describe TuioObject do
7
7
  @fiducial_id = 1,
8
8
  @x_pos = 0.8,
9
9
  @y_pos = 0.4,
10
- @angle = 1
10
+ @angle = 1,
11
+ @x_speed = 0.1,
12
+ @y_speed = 0.2,
13
+ @rotation_vector = 0.11,
14
+ @motion_accel = 0.12,
15
+ @rotation_accel = 0.13
11
16
  ]
12
- @to = TuioObject.new( *@args1 )
17
+ @params = TuioObjectParameter.new( *@args1 )
18
+ @to = TuioObject.from_params( @params )
13
19
  end
14
20
 
15
21
  describe "in general" do
@@ -35,34 +41,26 @@ describe TuioObject do
35
41
  end
36
42
 
37
43
  describe "on update" do
44
+
38
45
  before :each do
39
46
  @args2 = [
47
+ @sesssion_id = 42,
48
+ @fiducial_id = 1,
40
49
  @x_pos2 = 0.7,
41
50
  @y_pos2 = 0.4,
42
51
  @angle2 = 1.1,
43
52
  @x_speed = 0.1,
44
53
  @y_speed = 0.2,
45
- @rotation_speed = 0.11,
54
+ @rotation_vector = 0.11,
46
55
  @motion_accel = 0.12,
47
56
  @rotation_accel = 0.13
48
57
  ]
49
-
50
- @to.update( *@args2 )
58
+ @update_params = TuioObjectParameter.new( *@args2 )
59
+ @to.update_from_params( @update_params )
51
60
  end
52
61
 
53
62
  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
63
+ @to.params_equal?( @update_params ).should be_true
66
64
  end
67
65
 
68
66
  it "should know it's new x position" do
@@ -85,8 +83,8 @@ describe TuioObject do
85
83
  @to.y_speed.should == @y_speed
86
84
  end
87
85
 
88
- it "should know it's rotation speed" do
89
- @to.rotation_speed.should == @rotation_speed
86
+ it "should know it's rotation vector" do
87
+ @to.rotation_vector.should == @rotation_vector
90
88
  end
91
89
 
92
90
  it "should know it's rotation accel" do
@@ -0,0 +1,32 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ # /tuio/2Dobj set s i x y a X Y A m r
4
+ # /tuio/2Dcur set s x y X Y m
5
+
6
+ # session_id, x, y, X, Y, m
7
+ shared_examples_for "TuioParameter" do
8
+
9
+ it "should fetch session id" do
10
+ @tuio_param.session_id.should == @session_id
11
+ end
12
+
13
+ it "should fetch x position" do
14
+ @tuio_param.x_pos.should == @x_pos
15
+ end
16
+
17
+ it "should fetch y position" do
18
+ @tuio_param.y_pos.should == @y_pos
19
+ end
20
+
21
+ it "should fetch x speed" do
22
+ @tuio_param.x_speed.should == @x_speed
23
+ end
24
+
25
+ it "should fetch y speed" do
26
+ @tuio_param.y_speed.should == @y_speed
27
+ end
28
+
29
+ it "should fetch motion acceleration" do
30
+ @tuio_param.motion_accel.should == @motion_accel
31
+ end
32
+ 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.1.0
4
+ version: 0.2.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-04-05 00:00:00 -07:00
12
+ date: 2009-04-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,15 +32,21 @@ files:
32
32
  - lib/tuio_client.rb
33
33
  - lib/tuio_container.rb
34
34
  - lib/tuio_cursor.rb
35
+ - lib/tuio_cursor_parameter.rb
35
36
  - lib/tuio_object.rb
37
+ - lib/tuio_object_parameter.rb
38
+ - lib/tuio_parameter.rb
36
39
  - lib/tuio_point.rb
37
40
  - spec/integration
38
41
  - spec/integration/tuio_event_spec.rb
39
42
  - spec/spec_helper.rb
40
43
  - spec/unit
41
44
  - spec/unit/tuio_container_spec.rb
45
+ - spec/unit/tuio_cursor_parameter_spec.rb
42
46
  - spec/unit/tuio_cursor_spec.rb
47
+ - spec/unit/tuio_object_parameter_spec.rb
43
48
  - spec/unit/tuio_object_spec.rb
49
+ - spec/unit/tuio_parameter_spec.rb
44
50
  - spec/unit/tuio_point_spec.rb
45
51
  - LICENSE
46
52
  has_rdoc: true