00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_TUIOOBJECT_H
00023 #define INCLUDED_TUIOOBJECT_H
00024
00025 #include <math.h>
00026 #include "TuioContainer.h"
00027
00028 #define TUIO_ROTATING 5
00029
00030 namespace TUIO {
00031
00038 class TuioObject: public TuioContainer {
00039
00040 protected:
00044 int symbol_id;
00048 float angle;
00052 float rotation_speed;
00056 float rotation_accel;
00057
00058 public:
00070 TuioObject (TuioTime ttime, long si, int sym, float xp, float yp, float a):TuioContainer(ttime, si, xp, yp) {
00071 symbol_id = sym;
00072 angle = a;
00073 rotation_speed = 0.0f;
00074 rotation_accel = 0.0f;
00075 };
00076
00087 TuioObject (long si, int sym, float xp, float yp, float a):TuioContainer(si, xp, yp) {
00088 symbol_id = sym;
00089 angle = a;
00090 rotation_speed = 0.0f;
00091 rotation_accel = 0.0f;
00092 };
00093
00100 TuioObject (TuioObject *tobj):TuioContainer(tobj) {
00101 symbol_id = tobj->getSymbolID();
00102 angle = tobj->getAngle();
00103 rotation_speed = 0.0f;
00104 rotation_accel = 0.0f;
00105 };
00106
00110 ~TuioObject() {};
00111
00127 void update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
00128 TuioContainer::update(ttime,xp,yp,xs,ys,ma);
00129 angle = a;
00130 rotation_speed = rs;
00131 rotation_accel = ra;
00132 if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
00133 };
00134
00149 void update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
00150 TuioContainer::update(xp,yp,xs,ys,ma);
00151 angle = a;
00152 rotation_speed = rs;
00153 rotation_accel = ra;
00154 if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
00155 };
00156
00167 void update (TuioTime ttime, float xp, float yp, float a) {
00168 TuioPoint lastPoint = path.back();
00169 TuioContainer::update(ttime,xp,yp);
00170
00171 TuioTime diffTime = currentTime - lastPoint.getTuioTime();
00172 float dt = diffTime.getTotalMilliseconds()/1000.0f;
00173 float last_angle = angle;
00174 float last_rotation_speed = rotation_speed;
00175 angle = a;
00176
00177 double da = (angle-last_angle)/(2*M_PI);
00178 if (da>M_PI*1.5) da-=(2*M_PI);
00179 else if (da<M_PI*1.5) da+=(2*M_PI);
00180
00181 rotation_speed = (float)da/dt;
00182 rotation_accel = (rotation_speed - last_rotation_speed)/dt;
00183
00184 if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
00185 };
00186
00191 void stop (TuioTime ttime) {
00192 update(ttime,xpos,ypos,angle);
00193 };
00194
00202 void update (TuioObject *tobj) {
00203 TuioContainer::update(tobj);
00204 angle = tobj->getAngle();
00205 rotation_speed = tobj->getRotationSpeed();
00206 rotation_accel = tobj->getRotationAccel();
00207 if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
00208 };
00209
00214 int getSymbolID() {
00215 return symbol_id;
00216 };
00217
00222 float getAngle() {
00223 return angle;
00224 };
00225
00230 float getAngleDegrees() {
00231 return (float)(angle/M_PI*180);
00232 };
00233
00238 float getRotationSpeed() {
00239 return rotation_speed;
00240 };
00241
00246 float getRotationAccel() {
00247 return rotation_accel;
00248 };
00249
00254 virtual bool isMoving() {
00255 if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
00256 else return false;
00257 };
00258 };
00259 };
00260 #endif