Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_TUIOCONTAINER_H
00023 #define INCLUDED_TUIOCONTAINER_H
00024
00025 #include <list>
00026 #include <math.h>
00027 #include "TuioPoint.h"
00028 #include <iostream>
00029
00030 #define TUIO_ADDED 0
00031 #define TUIO_ACCELERATING 1
00032 #define TUIO_DECELERATING 2
00033 #define TUIO_STOPPED 3
00034 #define TUIO_REMOVED 4
00035
00036 namespace TUIO {
00037
00044 class TuioContainer: public TuioPoint {
00045
00046 protected:
00050 long session_id;
00054 float x_speed;
00058 float y_speed;
00062 float motion_speed;
00066 float motion_accel;
00070 std::list<TuioPoint> path;
00074 int state;
00075
00076 public:
00086 TuioContainer (TuioTime ttime, long si, float xp, float yp):TuioPoint(ttime, xp,yp) {
00087 session_id = si;
00088 x_speed = 0.0f;
00089 y_speed = 0.0f;
00090 motion_speed = 0.0f;
00091 motion_accel = 0.0f;
00092 TuioPoint p(currentTime,xpos,ypos);
00093 path.push_back(p);
00094
00095 state = TUIO_ADDED;
00096 };
00097
00106 TuioContainer (long si, float xp, float yp):TuioPoint(xp,yp) {
00107 session_id = si;
00108 x_speed = 0.0f;
00109 y_speed = 0.0f;
00110 motion_speed = 0.0f;
00111 motion_accel = 0.0f;
00112 TuioPoint p(currentTime,xpos,ypos);
00113 path.push_back(p);
00114
00115 state = TUIO_ADDED;
00116 };
00117
00124 TuioContainer (TuioContainer *tcon):TuioPoint(tcon) {
00125 session_id = tcon->getSessionID();
00126 x_speed = 0.0f;
00127 y_speed = 0.0f;
00128 motion_speed = 0.0f;
00129 motion_accel = 0.0f;
00130 TuioPoint p(currentTime,xpos,ypos);
00131 path.push_back(p);
00132
00133 state = TUIO_ADDED;
00134 };
00135
00139 virtual ~TuioContainer(){};
00140
00150 virtual void update (TuioTime ttime, float xp, float yp) {
00151 TuioPoint lastPoint = path.back();
00152 TuioPoint::update(ttime,xp, yp);
00153
00154 TuioTime diffTime = currentTime - lastPoint.getTuioTime();
00155 float dt = diffTime.getTotalMilliseconds()/1000.0f;
00156 float dx = xpos - lastPoint.getX();
00157 float dy = ypos - lastPoint.getY();
00158 float dist = sqrt(dx*dx+dy*dy);
00159 float last_motion_speed = motion_speed;
00160
00161 x_speed = dx/dt;
00162 y_speed = dy/dt;
00163 motion_speed = dist/dt;
00164 motion_accel = (motion_speed - last_motion_speed)/dt;
00165
00166 TuioPoint p(currentTime,xpos,ypos);
00167 path.push_back(p);
00168
00169 if (motion_accel>0) state = TUIO_ACCELERATING;
00170 else if (motion_accel<0) state = TUIO_DECELERATING;
00171 else state = TUIO_STOPPED;
00172 };
00173
00174
00179 virtual void stop(TuioTime ttime) {
00180 update(ttime,xpos,ypos);
00181 };
00182
00195 virtual void update (TuioTime ttime, float xp, float yp, float xs, float ys, float ma) {
00196 TuioPoint::update(ttime,xp, yp);
00197 x_speed = xs;
00198 y_speed = ys;
00199 motion_speed = (float)sqrt(x_speed*x_speed+y_speed*y_speed);
00200 motion_accel = ma;
00201
00202 TuioPoint p(currentTime,xpos,ypos);
00203 path.push_back(p);
00204
00205 if (motion_accel>0) state = TUIO_ACCELERATING;
00206 else if (motion_accel<0) state = TUIO_DECELERATING;
00207 else state = TUIO_STOPPED;
00208 };
00209
00220 virtual void update (float xp, float yp, float xs, float ys, float ma) {
00221 TuioPoint::update(xp,yp);
00222 x_speed = xs;
00223 y_speed = ys;
00224 motion_speed = (float)sqrt(x_speed*x_speed+y_speed*y_speed);
00225 motion_accel = ma;
00226
00227 path.pop_back();
00228 TuioPoint p(currentTime,xpos,ypos);
00229 path.push_back(p);
00230
00231 if (motion_accel>0) state = TUIO_ACCELERATING;
00232 else if (motion_accel<0) state = TUIO_DECELERATING;
00233 else state = TUIO_STOPPED;
00234 };
00235
00243 virtual void update (TuioContainer *tcon) {
00244 TuioPoint::update(tcon);
00245 x_speed = tcon->getXSpeed();
00246 y_speed = tcon->getYSpeed();
00247 motion_speed = tcon->getMotionSpeed();
00248 motion_accel = tcon->getMotionAccel();
00249
00250 TuioPoint p(tcon->getTuioTime(),xpos,ypos);
00251 path.push_back(p);
00252
00253 if (motion_accel>0) state = TUIO_ACCELERATING;
00254 else if (motion_accel<0) state = TUIO_DECELERATING;
00255 else state = TUIO_STOPPED;
00256 };
00257
00264 virtual void remove(TuioTime ttime) {
00265 currentTime = ttime;
00266 state = TUIO_REMOVED;
00267 }
00268
00273 virtual long getSessionID() {
00274 return session_id;
00275 };
00276
00281 virtual float getXSpeed() {
00282 return x_speed;
00283 };
00284
00289 virtual float getYSpeed() {
00290 return y_speed;
00291 };
00292
00297 virtual TuioPoint getPosition() {
00298 TuioPoint p(xpos,ypos);
00299 return p;
00300 };
00301
00306 virtual std::list<TuioPoint> getPath() {
00307 return path;
00308 };
00309
00314 virtual float getMotionSpeed() {
00315 return motion_speed;
00316 };
00317
00322 virtual float getMotionAccel() {
00323 return motion_accel;
00324 };
00325
00330 virtual int getTuioState() {
00331 return state;
00332 };
00333
00338 virtual bool isMoving() {
00339 if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING)) return true;
00340 else return false;
00341 };
00342 };
00343 };
00344 #endif