front_idill/extern/fajran-npTuioClient/TuioClient/TuioPoint.h
author bastiena
Fri, 06 Apr 2012 18:32:13 +0200
changeset 25 a7b0e40bcab0
parent 24 2bdf5d51d434
child 28 9ccef81f02ab
permissions -rw-r--r--
Front IDILL : Basic JS TUIO lib loaded
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     1
/*
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     2
	TUIO C++ Library - part of the reacTIVision project
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     3
	http://reactivision.sourceforge.net/
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     4
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     5
	Copyright (c) 2005-2008 Martin Kaltenbrunner <mkalten@iua.upf.edu>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     6
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     7
    This program is free software; you can redistribute it and/or modify
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     8
    it under the terms of the GNU General Public License as published by
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     9
    the Free Software Foundation; either version 2 of the License, or
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    10
    (at your option) any later version.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    11
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    12
    This program is distributed in the hope that it will be useful,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    15
    GNU General Public License for more details.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    16
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    17
    You should have received a copy of the GNU General Public License
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    18
    along with this program; if not, write to the Free Software
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    19
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    20
*/
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    22
#ifndef INCLUDED_TUIOPOINT_H
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    23
#define INCLUDED_TUIOPOINT_H
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    24
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    25
#define TUIO_UNDEFINED -1
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    26
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    27
class TuioPoint {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    28
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    29
	protected:
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    30
		float xpos, ypos, zpos;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    31
		long timestamp;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    32
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    33
	public:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    34
	TuioPoint (float xpos, float ypos) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    35
		this->xpos = xpos;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    36
		this->ypos = ypos;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    37
		timestamp = TUIO_UNDEFINED;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    38
	};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    39
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    40
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    41
	* Surcharg� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    42
	*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    43
	TuioPoint (float xpos, float ypos, float zpos) {
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    44
		this->xpos = xpos;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    45
		this->ypos = ypos;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    46
		this->zpos = zpos;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    47
		timestamp = TUIO_UNDEFINED;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    48
	};
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    49
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    50
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    51
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    52
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    53
	TuioPoint (TuioPoint *tuioPoint) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    54
		this->xpos = tuioPoint->getX();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    55
		this->ypos = tuioPoint->getY();
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    56
		this->zpos = tuioPoint->getZ();
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    57
		timestamp = TUIO_UNDEFINED;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    58
	};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    59
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    60
	~TuioPoint(){};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    61
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    62
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    63
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    64
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    65
	void update (TuioPoint *tuioPoint) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    66
		this->xpos = tuioPoint->getX();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    67
		this->ypos = tuioPoint->getY();
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    68
		this->zpos = tuioPoint->getZ();
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    69
		timestamp = TUIO_UNDEFINED;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
	};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    71
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    72
	void update (float xpos, float ypos) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    73
		this->xpos = xpos;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    74
		this->ypos = ypos;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
		timestamp = TUIO_UNDEFINED;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    76
	};
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    77
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    78
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    79
	* Surcharg� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    80
	*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    81
	void update (float xpos, float ypos, float zpos) {
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    82
		this->xpos = xpos;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    83
		this->ypos = ypos;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    84
		this->zpos = zpos;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    85
		timestamp = TUIO_UNDEFINED;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    86
	};
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    87
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    88
	float getX() { return xpos; };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    89
	float getY() { return ypos; };
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    90
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    91
	* Ajout� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    92
	*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    93
	float getZ() { return zpos; };
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    94
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    95
	float getDistance(float x, float y) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    96
		float dx = xpos-x;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    97
		float dy = ypos-y;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    98
		return sqrtf(dx*dx+dy*dy);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    99
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   100
	
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   101
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   102
	* Surcharg� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   103
	*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   104
	float getDistance(float x, float y, float z) {
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   105
		float dx = xpos-x;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   106
		float dy = ypos-y;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   107
		float dz = zpos-z;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   108
		return sqrtf(dx*dx+dy*dy+dz*dz);
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   109
	}
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   110
25
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   111
	/*
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   112
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   113
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   114
	float getDistance(TuioPoint *tuioPoint) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   115
		float dx = xpos-tuioPoint->getX();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   116
		float dy = ypos-tuioPoint->getY();
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   117
		float dz = zpos-tuioPoint->getZ();
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   118
		return sqrtf(dx*dx+dy*dy+dz*dz);
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   119
	}
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   120
25
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   121
	/*
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   122
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   123
	*/
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   124
	/*float getDistance3D(TuioPoint *tuioPoint) {
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   125
		float dx = xpos-tuioPoint->getX();
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   126
		float dy = ypos-tuioPoint->getY();
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   127
		float dz = zpos-tuioPoint->getZ();
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   128
		return sqrtf(dx*dx+dy*dy+dz*dz);
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   129
	}*/
a7b0e40bcab0 Front IDILL :
bastiena
parents: 24
diff changeset
   130
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   131
	float getAngle(TuioPoint *tuioPoint) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   132
		
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   133
		float side = tuioPoint->getX()-xpos;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   134
		float height = tuioPoint->getY()-ypos;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   135
		float distance = tuioPoint->getDistance(xpos,ypos);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   136
		
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   137
		float angle = (float)(asin(side/distance)+M_PI/2);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   138
		if (height<0) angle = 2.0f*(float)M_PI-angle;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   139
		
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   140
		return angle;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   141
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   142
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   143
	float getAngleDegrees(TuioPoint *tuioPoint) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   144
		return ((getAngle(tuioPoint)/(float)M_PI)*180.0f);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   145
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   146
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   147
	float getScreenX(int w) { return xpos*w; };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   148
	float getScreenY(int h) { return ypos*h; };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   149
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   150
	long getUpdateTime() { return timestamp; };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   151
	void setUpdateTime(long timestamp) { this->timestamp = timestamp; };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   152
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   153
};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   154
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   155
#endif