|
21
|
1 |
/* |
|
|
2 |
TUIO C++ Library - part of the reacTIVision project |
|
|
3 |
http://reactivision.sourceforge.net/ |
|
|
4 |
|
|
|
5 |
Copyright (c) 2005-2008 Martin Kaltenbrunner <mkalten@iua.upf.edu> |
|
|
6 |
|
|
|
7 |
This program is free software; you can redistribute it and/or modify |
|
|
8 |
it under the terms of the GNU General Public License as published by |
|
|
9 |
the Free Software Foundation; either version 2 of the License, or |
|
|
10 |
(at your option) any later version. |
|
|
11 |
|
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
15 |
GNU General Public License for more details. |
|
|
16 |
|
|
|
17 |
You should have received a copy of the GNU General Public License |
|
|
18 |
along with this program; if not, write to the Free Software |
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
20 |
*/ |
|
|
21 |
|
|
|
22 |
#ifndef INCLUDED_TUIOPOINT_H |
|
|
23 |
#define INCLUDED_TUIOPOINT_H |
|
|
24 |
|
|
|
25 |
#define TUIO_UNDEFINED -1 |
|
|
26 |
|
|
|
27 |
class TuioPoint { |
|
|
28 |
|
|
|
29 |
protected: |
|
|
30 |
float xpos, ypos; |
|
|
31 |
long timestamp; |
|
|
32 |
|
|
|
33 |
public: |
|
|
34 |
TuioPoint (float xpos, float ypos) { |
|
|
35 |
this->xpos = xpos; |
|
|
36 |
this->ypos = ypos; |
|
|
37 |
timestamp = TUIO_UNDEFINED; |
|
|
38 |
}; |
|
|
39 |
|
|
|
40 |
TuioPoint (TuioPoint *tuioPoint) { |
|
|
41 |
this->xpos = tuioPoint->getX(); |
|
|
42 |
this->ypos = tuioPoint->getY(); |
|
|
43 |
timestamp = TUIO_UNDEFINED; |
|
|
44 |
}; |
|
|
45 |
|
|
|
46 |
~TuioPoint(){}; |
|
|
47 |
|
|
|
48 |
void update (TuioPoint *tuioPoint) { |
|
|
49 |
this->xpos = tuioPoint->getX(); |
|
|
50 |
this->ypos = tuioPoint->getY(); |
|
|
51 |
timestamp = TUIO_UNDEFINED; |
|
|
52 |
}; |
|
|
53 |
|
|
|
54 |
void update (float xpos, float ypos) { |
|
|
55 |
this->xpos = xpos; |
|
|
56 |
this->ypos = ypos; |
|
|
57 |
timestamp = TUIO_UNDEFINED; |
|
|
58 |
}; |
|
|
59 |
|
|
|
60 |
float getX() { return xpos; }; |
|
|
61 |
float getY() { return ypos; }; |
|
|
62 |
|
|
|
63 |
float getDistance(float x, float y) { |
|
|
64 |
float dx = xpos-x; |
|
|
65 |
float dy = ypos-y; |
|
|
66 |
return sqrtf(dx*dx+dy*dy); |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
float getDistance(TuioPoint *tuioPoint) { |
|
|
70 |
float dx = xpos-tuioPoint->getX(); |
|
|
71 |
float dy = ypos-tuioPoint->getY(); |
|
|
72 |
return sqrtf(dx*dx+dy*dy); |
|
|
73 |
} |
|
|
74 |
|
|
|
75 |
float getAngle(TuioPoint *tuioPoint) { |
|
|
76 |
|
|
|
77 |
float side = tuioPoint->getX()-xpos; |
|
|
78 |
float height = tuioPoint->getY()-ypos; |
|
|
79 |
float distance = tuioPoint->getDistance(xpos,ypos); |
|
|
80 |
|
|
|
81 |
float angle = (float)(asin(side/distance)+M_PI/2); |
|
|
82 |
if (height<0) angle = 2.0f*(float)M_PI-angle; |
|
|
83 |
|
|
|
84 |
return angle; |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
float getAngleDegrees(TuioPoint *tuioPoint) { |
|
|
88 |
return ((getAngle(tuioPoint)/(float)M_PI)*180.0f); |
|
|
89 |
} |
|
|
90 |
|
|
|
91 |
float getScreenX(int w) { return xpos*w; }; |
|
|
92 |
float getScreenY(int h) { return ypos*h; }; |
|
|
93 |
|
|
|
94 |
long getUpdateTime() { return timestamp; }; |
|
|
95 |
void setUpdateTime(long timestamp) { this->timestamp = timestamp; }; |
|
|
96 |
|
|
|
97 |
}; |
|
|
98 |
|
|
|
99 |
#endif |