1 // |
|
2 // Copyright (C) 2009 Fajran Iman Rusadi |
|
3 // |
|
4 // This program is free software: you can redistribute it and/or modify |
|
5 // it under the terms of the GNU General Public License as published by |
|
6 // the Free Software Foundation, either version 3 of the License, or |
|
7 // (at your option) any later version. |
|
8 // |
|
9 // This program is distributed in the hope that it will be useful, |
|
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 // GNU General Public License for more details. |
|
13 // |
|
14 // You should have received a copy of the GNU General Public License |
|
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 // |
|
17 |
|
18 /* |
|
19 Modified by alexandre.bastien@iri.centrepompidou.fr to manage TUIO strings. |
|
20 */ |
|
21 |
|
22 #include "client.h" |
|
23 |
|
24 #include <TuioClient.h> |
|
25 #include <TuioListener.h> |
|
26 #include <TuioObject.h> |
|
27 #include <TuioCursor.h> |
|
28 |
|
29 static inline void call(TuioEvent type, long sid, int fid, float x, float y, float a) |
|
30 { |
|
31 TuioEventData data; |
|
32 data.type = type; |
|
33 data.sid = sid; |
|
34 data.fid = fid; |
|
35 data.x = x; |
|
36 data.y = y; |
|
37 data.a = a; |
|
38 tuio_callback(data); |
|
39 } |
|
40 |
|
41 /* |
|
42 * Surchargé par alexandre.bastien@iri.centrepompidou.fr |
|
43 */ |
|
44 static inline void call(TuioEvent type, long sid, int fid, float x, float y, float z, float a) |
|
45 { |
|
46 TuioEventData data; |
|
47 data.type = type; |
|
48 data.sid = sid; |
|
49 data.fid = fid; |
|
50 data.x = x; |
|
51 data.y = y; |
|
52 data.z = z; |
|
53 data.a = a; |
|
54 data.code = ""; |
|
55 tuio_callback(data); |
|
56 } |
|
57 |
|
58 /* |
|
59 * Ajouté par alexandre.bastien@iri.centrepompidou.fr |
|
60 */ |
|
61 static inline void call(TuioEvent type, long sid, const char* code) |
|
62 { |
|
63 TuioEventData data; |
|
64 data.type = type; |
|
65 data.sid = sid; |
|
66 data.code = code; |
|
67 tuio_callback(data); |
|
68 } |
|
69 |
|
70 class Listener : public TuioListener |
|
71 { |
|
72 public: |
|
73 Listener() { }; |
|
74 ~Listener() { }; |
|
75 |
|
76 void addTuioObject(TuioObject *object) |
|
77 { |
|
78 call(TE_OBJECT_ADD, |
|
79 object->getSessionID(), object->getFiducialID(), |
|
80 object->getX(), object->getY(), object->getAngle()); |
|
81 } |
|
82 |
|
83 void updateTuioObject(TuioObject *object) |
|
84 { |
|
85 call(TE_OBJECT_UPDATE, |
|
86 object->getSessionID(), object->getFiducialID(), |
|
87 object->getX(), object->getY(), object->getAngle()); |
|
88 } |
|
89 |
|
90 void removeTuioObject(TuioObject *object) |
|
91 { |
|
92 call(TE_OBJECT_REMOVE, |
|
93 object->getSessionID(), object->getFiducialID(), |
|
94 object->getX(), object->getY(), object->getAngle()); |
|
95 } |
|
96 |
|
97 /* |
|
98 * Modifié par alexandre.bastien@iri.centrepompidou.fr |
|
99 */ |
|
100 void addTuioCursor(TuioCursor *cursor) |
|
101 { |
|
102 call(TE_CURSOR_ADD, |
|
103 cursor->getSessionID(), cursor->getFingerID(), |
|
104 cursor->getX(), cursor->getY(), cursor->getZ(), 0); |
|
105 } |
|
106 |
|
107 /* |
|
108 * Modifié par alexandre.bastien@iri.centrepompidou.fr |
|
109 */ |
|
110 void updateTuioCursor(TuioCursor *cursor) |
|
111 { |
|
112 call(TE_CURSOR_UPDATE, |
|
113 cursor->getSessionID(), cursor->getFingerID(), |
|
114 cursor->getX(), cursor->getY(), cursor->getZ(), 0); |
|
115 } |
|
116 |
|
117 /* |
|
118 * Modifié par alexandre.bastien@iri.centrepompidou.fr |
|
119 */ |
|
120 void removeTuioCursor(TuioCursor *cursor) |
|
121 { |
|
122 call(TE_CURSOR_REMOVE, |
|
123 cursor->getSessionID(), cursor->getFingerID(), |
|
124 cursor->getX(), cursor->getY(), cursor->getZ(), 0); |
|
125 } |
|
126 |
|
127 /* |
|
128 * Ajouté par alexandre.bastien@iri.centrepompidou.fr |
|
129 */ |
|
130 void addTuioString(TuioString *string) |
|
131 { |
|
132 call(TE_STRING_ADD, string->getSessionID(), string->getCode()); |
|
133 } |
|
134 |
|
135 /* |
|
136 * Ajouté par alexandre.bastien@iri.centrepompidou.fr |
|
137 */ |
|
138 void updateTuioString(TuioString *string) |
|
139 { |
|
140 call(TE_STRING_UPDATE, string->getSessionID(), string->getCode()); |
|
141 } |
|
142 |
|
143 /* |
|
144 * Ajouté par alexandre.bastien@iri.centrepompidou.fr |
|
145 */ |
|
146 void removeTuioString(TuioString *string) |
|
147 { |
|
148 call(TE_STRING_REMOVE, string->getSessionID(), string->getCode()); |
|
149 } |
|
150 |
|
151 void refresh(long timestamp) |
|
152 { |
|
153 } |
|
154 }; |
|
155 |
|
156 static TuioClient* client = 0; |
|
157 static Listener* listener = 0; |
|
158 |
|
159 void tuio_start(int port) |
|
160 { |
|
161 if (!client) { |
|
162 listener = new Listener(); |
|
163 |
|
164 client = new TuioClient(port); |
|
165 client->addTuioListener(listener); |
|
166 client->start(); |
|
167 } |
|
168 } |
|
169 |
|
170 void tuio_stop() |
|
171 { |
|
172 client->stop(); |
|
173 delete listener; |
|
174 delete client; |
|
175 |
|
176 client = 0; |
|
177 listener = 0; |
|
178 } |
|
179 |
|
180 void t() |
|
181 { |
|
182 std::cout << "t" << std::endl; |
|
183 } |
|