front_idill/extern/fajran-npTuioClient/src/client.cpp
author bastiena
Fri, 06 Apr 2012 11:48:00 +0200
changeset 24 2bdf5d51d434
parent 21 e4e5f02787a1
child 27 6c08d4d7219e
permissions -rw-r--r--
Front IDILL : TuioPoint class header modified in order to manage 3D points TuioContainer class header modified in order to manage 3D points TuioCursor class header modified in order to manage 3D points TuioClient class header modified in order to manage 3D points TuioClient class modified in order to manage 3D points client class header modified in order to manage 3D points client class modified in order to manage 3D points
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
// Copyright (C) 2009  Fajran Iman Rusadi
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     3
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     4
// This program is free software: you can redistribute it and/or modify
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     5
// it under the terms of the GNU General Public License as published by
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     6
// the Free Software Foundation, either version 3 of the License, or
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     7
// (at your option) any later version.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     8
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    12
// GNU General Public License for more details.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    13
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    16
//
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    17
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    18
#include "client.h"
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    19
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    20
#include <TuioClient.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    21
#include <TuioListener.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    22
#include <TuioObject.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    23
#include <TuioCursor.h>
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    24
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    25
static inline void call(TuioEvent type, long sid, int fid, float x, float y, float a)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    26
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    27
	TuioEventData data;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    28
	data.type = type;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    29
	data.sid = sid;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    30
	data.fid = fid;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    31
	data.x = x;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    32
	data.y = y;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    33
	data.a = a;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    34
	tuio_callback(data);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    35
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    36
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    37
/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    38
* Surcharg� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    39
*/
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    40
static inline void call(TuioEvent type, long sid, int fid, float x, float y, float z, float a)
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    41
{
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    42
	TuioEventData data;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    43
	data.type = type;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    44
	data.sid = sid;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    45
	data.fid = fid;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    46
	data.x = x;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    47
	data.y = y;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    48
	data.z = z;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    49
	data.a = a;
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    50
	tuio_callback(data);
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    51
}
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    52
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    53
class Listener : public TuioListener
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    54
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    55
public:
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    56
	Listener() { };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    57
	~Listener() { };
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    58
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    59
	void addTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    60
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    61
		call(TE_OBJECT_ADD,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    62
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    63
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    64
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    65
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    66
	void updateTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    67
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    68
		call(TE_OBJECT_UPDATE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    69
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    71
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    72
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    73
	void removeTuioObject(TuioObject *object)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    74
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
		call(TE_OBJECT_REMOVE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    76
			object->getSessionID(), object->getFiducialID(),
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    77
			object->getX(), object->getY(), object->getAngle());
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    78
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    79
	
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    80
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    81
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    82
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    83
	void addTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    84
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    85
		call(TE_CURSOR_ADD,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    86
			cursor->getSessionID(), cursor->getFingerID(),
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    87
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    88
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    89
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    90
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    91
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    92
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    93
	void updateTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    94
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    95
		call(TE_CURSOR_UPDATE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    96
			cursor->getSessionID(), cursor->getFingerID(),
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
    97
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    98
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    99
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   100
	/*
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   101
	* Modifi� par alexandre.bastien@iri.centrepompidou.fr
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   102
	*/
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   103
	void removeTuioCursor(TuioCursor *cursor)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   104
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   105
		call(TE_CURSOR_REMOVE,
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   106
			cursor->getSessionID(), cursor->getFingerID(),
24
2bdf5d51d434 Front IDILL :
bastiena
parents: 21
diff changeset
   107
			cursor->getX(), cursor->getY(), cursor->getZ(), 0);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   108
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   109
	
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   110
	void refresh(long timestamp) 
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   111
	{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   112
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   113
};
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   114
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   115
static TuioClient* client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   116
static Listener* listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   117
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   118
void tuio_start(int port)
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   119
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   120
	if (!client) {
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   121
		listener = new Listener();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   122
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   123
		client = new TuioClient(port);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   124
		client->addTuioListener(listener);
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   125
		client->start();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   126
	}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   127
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   128
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   129
void tuio_stop()
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   130
{
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   131
	client->stop();
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   132
	delete listener;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   133
	delete client;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   134
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   135
	client = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   136
	listener = 0;
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   137
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
   138