- Main Page
- Classes
- Files

# TuioPoint.h

    00001 /*
    00002  TUIO C++ Library - part of the reacTIVision project
    00003  http://reactivision.sourceforge.net/
    00004
    00005  Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
    00006
    00007  This program is free software; you can redistribute it and/or modify
    00008  it under the terms of the GNU General Public License as published by
    00009  the Free Software Foundation; either version 2 of the License, or
    00010  (at your option) any later version.
    00011
    00012  This program is distributed in the hope that it will be useful,
    00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015  GNU General Public License for more details.
    00016
    00017  You should have received a copy of the GNU General Public License
    00018  along with this program; if not, write to the Free Software
    00019  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00020  */
    00021
    00022 #ifndef INCLUDED_TUIOPOINT_H
    00023 #define INCLUDED_TUIOPOINT_H
    00024 #include "TuioTime.h"
    00025 #include <iostream>
    00026
    00027 #ifndef M_PI
    00028 #define M_PI    3.14159265358979323846
    00029
    00030 #endif
    00031
    00032 namespace TUIO {
    00033
    00041         class TuioPoint {
    00042
    00043         protected:
    00047                 float xpos;
    00051                 float ypos;
    00055                 TuioTime currentTime;
    00059                 TuioTime startTime;
    00060
    00061         public:
    00066                 TuioPoint (float xp, float yp) {
    00067                         xpos = xp;
    00068                         ypos = yp;
    00069                         currentTime = TuioTime::getSessionTime();
    00070                         startTime = currentTime;
    00071                 };
    00072
    00081                 TuioPoint (TuioTime ttime, float xp, float yp) {
    00082                         xpos = xp;
    00083                         ypos = yp;
    00084                         currentTime = ttime;
    00085                         startTime = currentTime;
    00086                 };
    00087
    00094                 TuioPoint (TuioPoint *tpoint) {
    00095                         xpos = tpoint->getX();
    00096                         ypos = tpoint->getY();
    00097                         currentTime = TuioTime::getSessionTime();
    00098                         startTime = currentTime;
    00099                 };
    00100
    00104                 ~TuioPoint(){};
    00105
    00112                 void update (TuioPoint *tpoint) {
    00113                         xpos = tpoint->getX();
    00114                         ypos = tpoint->getY();
    00115                 };
    00116
    00124                 void update (float xp, float yp) {
    00125                         xpos = xp;
    00126                         ypos = yp;
    00127                 };
    00128
    00137                 void update (TuioTime ttime, float xp, float yp) {
    00138                         xpos = xp;
    00139                         ypos = yp;
    00140                         currentTime = ttime;
    00141                 };
    00142
    00143
    00148                 float getX() {
    00149                         return xpos;
    00150                 };
    00151
    00156                 float getY() {
    00157                         return ypos;
    00158                 };
    00159
    00167                 float getDistance(float xp, float yp) {
    00168                         float dx = xpos-xp;
    00169                         float dy = ypos-yp;
    00170                         return sqrtf(dx*dx+dy*dy);
    00171                 }
    00172
    00179                 float getDistance(TuioPoint *tpoint) {
    00180                         return getDistance(tpoint->getX(),tpoint->getY());
    00181                 }
    00182
    00190                  float getAngle(float xp, float yp) {
    00191                         float side = xpos-xp;
    00192                         float height = ypos-yp;
    00193                         float distance = getDistance(xp,yp);
    00194
    00195                         float angle = (float)(asin(side/distance)+M_PI/2);
    00196                         if (height<0) angle = 2.0f*(float)M_PI-angle;
    00197
    00198                         return angle;
    00199                 }
    00200
    00207                 float getAngle(TuioPoint *tpoint) {
    00208                         return getAngle(tpoint->getX(),tpoint->getY());
    00209                 }
    00210
    00218                 float getAngleDegrees(float xp, float yp) {
    00219                         return ((getAngle(xp,yp)/(float)M_PI)*180.0f);
    00220                 }
    00221
    00228                 float getAngleDegrees(TuioPoint *tpoint) {
    00229                         return ((getAngle(tpoint)/(float)M_PI)*180.0f);
    00230                 }
    00231
    00238                 int getScreenX(int width) {
    00239                         return (int)floor(xpos*width+0.5f);
    00240                 };
    00241
    00248                 int getScreenY(int height) {
    00249                         return (int)floor(ypos*height+0.5f);
    00250                 };
    00251
    00257                 TuioTime getTuioTime() {
    00258                         return currentTime;
    00259                 };
    00260
    00266                 TuioTime getStartTime() {
    00267                         return startTime;
    00268                 };
    00269         };
    00270 };
    00271 #endif