tuio-ruby 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,10 +5,11 @@ http://www.tuio.org/
5
5
  == INSTALL:
6
6
 
7
7
  [sudo] gem install tuio-ruby
8
-
8
+
9
9
  == EXAMPLE:
10
10
 
11
- require File.join( File.dirname( __FILE__ ), '..', 'lib', 'tuio-ruby' )
11
+ require 'rubygems'
12
+ require 'tuio-ruby'
12
13
 
13
14
 
14
15
  @tc = TuioClient.new
@@ -7,27 +7,27 @@ require 'tuio-ruby/core_ext/float'
7
7
 
8
8
  class TuioClient
9
9
  include OSC
10
-
10
+
11
11
  attr_reader :tuio_objects, :tuio_cursors
12
-
13
-
12
+
13
+
14
14
  client_events :object_creation, :object_update, :object_removal
15
15
  client_events :cursor_creation, :cursor_update, :cursor_removal
16
-
16
+
17
17
  def initialize( args = {} )
18
18
  @port = args[:port] || 3333
19
19
 
20
20
  @tuio_objects = { }
21
21
  @tuio_cursors = { }
22
-
22
+
23
23
  @osc = OSC::Server.new(@port)
24
-
24
+
25
25
  @osc.add_method '/tuio/2Dobj' do |msg|
26
26
  args = msg.to_a
27
-
27
+
28
28
  case args.shift
29
29
  when "set"
30
- track_tuio_object( args )
30
+ track_tuio_object( args )
31
31
  when "alive"
32
32
  keep_alive( :tuio_objects, args )
33
33
  when "fseq"
@@ -48,120 +48,120 @@ class TuioClient
48
48
  end
49
49
  end
50
50
  end
51
-
51
+
52
52
  def start
53
53
  Thread.new do
54
54
  @osc.run
55
55
  end
56
56
  end
57
-
57
+
58
58
  ####################################
59
59
  # getters #
60
60
  ####################################
61
-
61
+
62
62
  def tuio_object( id )
63
63
  @tuio_objects[id]
64
64
  end
65
-
65
+
66
66
  def tuio_cursor( id )
67
67
  @tuio_cursors[id]
68
68
  end
69
-
69
+
70
70
  private
71
71
 
72
72
  def track_tuio_object( args )
73
73
  params = TuioObjectParameter.new( *args )
74
-
74
+
75
75
  if tuio_object_previously_tracked?( params )
76
-
76
+
77
77
  tuio_object = grab_tuio_object_by( params.session_id )
78
-
78
+
79
79
  return if tuio_object.params_equal?( params )
80
80
 
81
- tuio_object.update_from_params( params )
81
+ tuio_object.update_from_params( params )
82
82
 
83
83
  trigger_object_update_callback( tuio_object )
84
84
  else # this is a new object
85
85
  tuio_object = track_new_tuio_object_with( params )
86
-
86
+
87
87
  trigger_object_creation_callback( tuio_object )
88
88
  end
89
89
  end
90
-
90
+
91
91
  def track_tuio_cursor( args )
92
- params = TuioCursorParameter.new( *args )
93
-
92
+ params = TuioCursorParameter.new( *args[0..5] )
93
+
94
94
  if tuio_cursor_previously_tracked?( params )
95
-
95
+
96
96
  tuio_cursor = grab_tuio_cursor_by( params.session_id )
97
-
97
+
98
98
  return if tuio_cursor.params_equal?( params )
99
99
  tuio_cursor.update_from_params( params )
100
-
100
+
101
101
  trigger_cursor_update_callback( tuio_cursor )
102
-
103
- else # this is a new cursor
102
+
103
+ else # this is a new cursor
104
104
  finger_id = @tuio_cursors.size
105
105
  tuio_cursor = track_new_tuio_cursor_with( params )
106
106
 
107
107
  trigger_cursor_creation_callback( tuio_cursor )
108
108
  end
109
109
  end
110
-
110
+
111
111
  def tuio_object_previously_tracked?( params )
112
112
  @tuio_objects.has_key?( params.session_id )
113
113
  end
114
-
114
+
115
115
  def tuio_cursor_previously_tracked?( params )
116
116
  @tuio_cursors.has_key?( params.session_id )
117
117
  end
118
-
118
+
119
119
  def grab_tuio_object_by( session_id )
120
120
  @tuio_objects[session_id]
121
121
  end
122
-
122
+
123
123
  def grab_tuio_cursor_by( session_id )
124
124
  @tuio_cursors[session_id]
125
125
  end
126
-
126
+
127
127
  def track_new_tuio_object_with( tuio_params )
128
- @tuio_objects[tuio_params.session_id] = TuioObject.from_params( tuio_params )
128
+ @tuio_objects[tuio_params.session_id] = TuioObject.from_params( tuio_params )
129
129
  end
130
130
 
131
- def track_new_tuio_cursor_with( params )
131
+ def track_new_tuio_cursor_with( params )
132
132
  new_cursor = TuioCursor.from_params( params )
133
133
  @tuio_cursors[params.session_id] = new_cursor
134
-
134
+
135
135
  new_cursor.finger_id = @tuio_cursors.size
136
136
  new_cursor
137
137
  end
138
-
138
+
139
139
  ####################################
140
140
  # "alive" msgs #
141
141
  ####################################
142
-
142
+
143
143
  def delete_tuio_objects( session_id )
144
144
  tuio_object = grab_tuio_object_by( session_id )
145
-
145
+
146
146
  trigger_object_removal_callback( tuio_object )
147
147
  end
148
-
148
+
149
149
  def delete_tuio_cursors( session_id )
150
150
  tuio_cursor = grab_tuio_cursor_by( session_id )
151
-
151
+
152
152
  trigger_cursor_removal_callback( tuio_cursor )
153
153
  end
154
-
155
-
154
+
155
+
156
156
  def keep_alive( type, session_ids )
157
157
  return if session_ids.nil?
158
158
  all_keys = send( type ).keys
159
-
159
+
160
160
  dead = all_keys.reject { |key| session_ids.include? key }
161
-
161
+
162
162
  dead.each do | session_id |
163
163
  send( "delete_#{type}", session_id )
164
-
164
+
165
165
  send( type ).delete( session_id )
166
166
  end
167
167
  end
@@ -4,7 +4,7 @@ describe "tuio object" do
4
4
  before :each do
5
5
  setup_server
6
6
  end
7
-
7
+
8
8
  describe "in general" do
9
9
  it "should call the creation hook" do
10
10
  @server.on_object_creation do | object |
@@ -90,6 +90,14 @@ describe "tuio_cursors" do
90
90
  before :each do
91
91
  setup_server
92
92
  end
93
+ describe "CCV height / width extensions" do
94
+ it "should strip the height / width parameters off" do
95
+ lambda{
96
+ # passing in extra two parameters
97
+ send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0, 0.1, 0.1 )
98
+ }.should_not raise_error
99
+ end
100
+ end
93
101
 
94
102
  it 'should update tracking' do
95
103
  send_message( '/tuio/2Dcur', "set", 22, 0.38, 0.35, 0.0, 0.0, 0.0 )
@@ -125,6 +133,7 @@ describe "tuio_cursors" do
125
133
  }.should raise_error
126
134
  end
127
135
 
136
+
128
137
  it "should call the update hooks" do
129
138
  @server.on_cursor_update do | objects |
130
139
  raise "update hook called!"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - aberant