7 Achegas 4b0dcd6af3 ... d2f8fc455a

Autor SHA1 Mensaxe Data
  bdestombes d2f8fc455a chore: add favicons %!s(int64=2) %!d(string=hai) anos
  bdestombes e53b70117e chore: add favicons %!s(int64=2) %!d(string=hai) anos
  bdestombes 677cfb677c chore: code style + remove HTTP JSON responses %!s(int64=2) %!d(string=hai) anos
  bdestombes 6e672bda84 chore: code style + remove HTTP JSON responses %!s(int64=2) %!d(string=hai) anos
  bdestombes b52afc858a chore: various code style %!s(int64=2) %!d(string=hai) anos
  eLandon_Miix 9af9bb2515 added actions in receiver html on tuio objects update %!s(int64=2) %!d(string=hai) anos
  eLandon_Miix e2e2b252be titi fait du js %!s(int64=2) %!d(string=hai) anos

+ 208 - 50
emitter/backend/server.js

@@ -9,12 +9,85 @@ const oscClient = new Client('127.0.0.1', 3333);
 let alive = [];
 let fseq;
 
+let objTriangle = [] ;
+
 function getHypotenuse(touch1, touch2) {
-	var x = Math.abs(touch1.x - touch2.x);
-	var y = Math.abs(touch1.y - touch2.y);
+	const x = Math.abs(touch1.x - touch2.x);
+	const y = Math.abs(touch1.y - touch2.y);
 	return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
 }
 
+function getTop(dotTrio) {
+	const dist01 = getHypotenuse(dotTrio[0], dotTrio[1]);
+	const dist02 = getHypotenuse(dotTrio[0], dotTrio[2]);
+	const dist12 = getHypotenuse(dotTrio[1], dotTrio[2]);
+
+	const diff01m02 = Math.abs(dist01 - dist02);
+	const diff01m12 = Math.abs(dist01 - dist12);
+	const diff02m12 = Math.abs(dist02 - dist12);
+
+	if (diff01m02 < diff02m12 && diff01m02 < diff01m12) {return 0;}
+	else if (diff01m12<diff01m02 && diff01m12<diff02m12) {return 1;}
+	else if (diff02m12<diff01m02 && diff02m12<diff01m12) {return 2;}
+}
+
+function getAngleApex(dotTrio, topIndex) {
+	let dotA;
+	let dotB;
+	let dotC;
+	dotB = dotTrio[topIndex];
+	if (topIndex == 0) {
+		dotA = dotTrio[1];
+		dotC = dotTrio[2];
+	}
+	else if (topIndex == 1) {
+		dotA = dotTrio[0];
+		dotC = dotTrio[2];
+	}
+	else if (topIndex == 2) {
+		dotA = dotTrio[0];
+		dotC = dotTrio[1];
+	}
+
+	const AB = [dotB.x - dotA.x, dotB.y - dotA.y] ;
+	const CB = [dotB.x - dotC.x, dotB.y - dotC.y] ;
+
+	const dotProd = (AB[0] * CB[0] + AB[1] * CB[1]);
+	const crossProd = (AB[0]*CB[1] - AB[1] * CB[0]);
+
+	const alpha = Math.atan2(crossProd, dotProd);
+	//return alpha ;
+	return Math.floor(alpha * 180. / Math.PI + 0.5) ;
+}
+
+function getOrientation(dotTrio, topIndex) {
+	let dotA;
+	let dotB;
+	let dotC;
+	dotB = dotTrio[topIndex];
+	if (topIndex == 0) {
+		dotA = dotTrio[1];
+		dotC = dotTrio[2];
+	}
+	else if (topIndex == 1) {
+		dotA = dotTrio[0];
+		dotC = dotTrio[2];
+	}
+	else if (topIndex == 2) {
+		dotA = dotTrio[0];
+		dotC = dotTrio[1];
+	}
+
+	const middlePt = [(dotA.x+dotC.x)/2 ,(dotA.y+dotC.y)/2 ] ;
+	let diff = [dotB.x - middlePt[0], dotB.y - middlePt[1]] ;
+	const length = Math.sqrt(Math.pow(diff[0],2) + Math.pow(diff[1], 2) ) ;
+	//normalize diff
+	diff = [diff[0]/length, diff[1]/length];
+	const rad = Math.atan2(diff[0], diff[1]) ;
+ 	return Math.floor( -1 * rad * 180 / Math.PI)  ;
+	 //return length ;
+}
+
 const server = require('http').Server(app);
 
 app.use(bodyParser.json());
@@ -22,7 +95,9 @@ app.use(bodyParser.urlencoded({extended:true}));
 app.use(express.static('./frontend/assets'));
 
 app.get('/', function (req, res) {
-	res.sendFile('./frontend/index.html', { root: path.resolve(__dirname + '/..') })
+	res.sendFile('./frontend/index.html', {
+		root: path.resolve(__dirname + '/..')
+	})
 });
 
 app.post('/json', function (req, res) {
@@ -54,7 +129,7 @@ app.post('/json', function (req, res) {
 					[ '/tuio/2Dcur', 'fseq', fseq ]
 				);
 				oscClient.send(oscBundle, () => {
-					res.status(200).json(JSON.stringify(req.body));
+					res.status(200).send();
 					fseq = 0;
 				});
 			} else {
@@ -103,7 +178,7 @@ app.post('/json', function (req, res) {
 							var hyp = getHypotenuse(dots[i], dots[j]);
 							/* on garde uniquement les segments inférieurs à 550px
 							 * cette valeur devra être une variable de configuration */
-							if (!alreadyExists && hyp <= 550) {
+							if (!alreadyExists && hyp <= 750) {
 								segments.push({
 									identifiers: [i, j],
 									x1: dots[i].x,
@@ -120,7 +195,7 @@ app.post('/json', function (req, res) {
 			// console.log(segments, segments.length);
 
 			/* Listage des triangles */
-			var triangles = [];
+			const triangles = [];
 			/* on boucle sur les segments */
 			segments.forEach((segment) => {
 				const dot1 = segment.identifiers[0];
@@ -148,31 +223,51 @@ app.post('/json', function (req, res) {
 					}
 				}
 			});
-			// console.log(triangles, triangles.length);
+			 console.log(triangles, triangles.length);
+
+			//MOD TITI
+			//objet pour stocker les informations des triangles identifiés (points, centre, apexAngle, orientation, indice apex, width, height)
+
+			objTriangle = {} ;
 
 			/* Définition de l'apex */
 			triangles.forEach(triangle => {
-				/* on récupère les 3 côtés (segments) du triangle */
-				const segment1 = segments.find(segment => {
-					return segment.identifiers.includes(triangle[0]) && segment.identifiers.includes(triangle[1]);
-				});
-				const segment2 = segments.find(segment => {
-					return segment.identifiers.includes(triangle[1]) && segment.identifiers.includes(triangle[2]);
-				});
-				const segment3 = segments.find(segment => {
-					return segment.identifiers.includes(triangle[0]) && segment.identifiers.includes(triangle[2]);
-				});
-				/* on trouve quel côté est le plus court
-				 * NOTE: dans notre cas, l'apex sera toujours le point opposé au plus petit côté
-				 * cette méthode n'est pas généralisable à d'autres projets */
-				const smallestSegment = [segment1, segment2, segment3].reduce(function(prev, current) {
-					return (prev.hyp < current.hyp) ? prev : current
-				});
-				/* on déduit quel point du triangle est l'apex */
-				const apexDot = triangle.find(dot => {
-					return dot !== smallestSegment.identifiers[0] && dot !== smallestSegment.identifiers[1];
-				});
-				console.log(apexDot);
+				objTriangle.dots = [];
+				objTriangle.dots[0] = dots[triangle[0]];
+				objTriangle.dots[1] = dots[triangle[1]];
+				objTriangle.dots[2] = dots[triangle[2]];
+
+				objTriangle.apex = getTop(objTriangle.dots);
+				objTriangle.center = [
+					(objTriangle.dots[0].x+objTriangle.dots[1].x+objTriangle.dots[2].x)/3 ,
+					(objTriangle.dots[0].y+objTriangle.dots[1].y+objTriangle.dots[2].y)/3
+				];
+
+				objTriangle.angleApex = getAngleApex(objTriangle.dots, objTriangle.apex) ;
+				objTriangle.orientation = getOrientation(objTriangle.dots, objTriangle.apex) ;
+				// /* on récupère les 3 côtés (segments) du triangle */
+				// const segment1 = segments.find(segment => {
+				// 	return segment.identifiers.includes(triangle[0]) && segment.identifiers.includes(triangle[1]);
+				// });
+				// const segment2 = segments.find(segment => {
+				// 	return segment.identifiers.includes(triangle[1]) && segment.identifiers.includes(triangle[2]);
+				// });
+				// const segment3 = segments.find(segment => {
+				// 	return segment.identifiers.includes(triangle[0]) && segment.identifiers.includes(triangle[2]);
+				// });
+				// /* on trouve quel côté est le plus court
+				//  * NOTE: dans notre cas, l'apex sera toujours le point opposé au plus petit côté
+				//  * cette méthode n'est pas généralisable à d'autres projets */
+				// const smallestSegment = [segment1, segment2, segment3].reduce(function(prev, current) {
+				// 	return (prev.hyp < current.hyp) ? prev : current
+				// });
+
+				// /* on déduit quel point du triangle est l'apex */
+				// const apexDot = triangle.find(dot => {
+				// 	return dot !== smallestSegment.identifiers[0] && dot !== smallestSegment.identifiers[1];
+				// });
+				console.log(objTriangle.apex);
+				console.log('centerPos : ' + objTriangle.center + ' orientation : ' + objTriangle.orientation);
 
 				/* Reste à faire:
 				 * trouver la valeur de l'angle de l'apex (théorème des cosinus)
@@ -182,36 +277,99 @@ app.post('/json', function (req, res) {
 			});
 
 
+			//plante vite
+			// if (objTriangle.dots != undefined){
+			// 	let oscBundleObj ;
+			// 	oscBundleObj = new Bundle(
+			// 		[ '/tuio/2Dobj', 'source', `tangibles${req.body.section.toString()}@127.0.0.1` ],
+			// 		[ '/tuio/2Dobj', 'alive', 1 ],
+			// 		[
+			// 			'/tuio/2Dobj',
+			// 			'set',
+			// 			1,
+			// 			1,
+			// 			objTriangle.center[0],
+			// 			objTriangle.center[1],
+			// 			objTriangle.orientation,
+			// 			0.0,
+			// 			0.0,
+			// 			0.0,
+			// 			0.0,
+			// 			0.0
+			// 		],
+			// 		[ '/tuio/2Dobj', 'fseq', fseq ]
+			// 	);
+			// 	// 	// objTriangle.forEach(triangleIndex => {
+			// 	// 	// 	oscBundle.append(
+			// 	// 	// 		[
+			// 	// 	// 			'/tuio/2Dobj',
+			// 	// 	// 			'set',
+			// 	// 	// 			triangleIndex,
+			// 	// 	// 			triangleIndex,
+			// 	// 	// 			objTriangle[triangleIndex].center[0],
+			// 	// 	// 			objTriangle[triangleIndex].center[1],
+			// 	// 	// 			objTriangle[triangleIndex].orientation,
+			// 	// 	// 			0.0,
+			// 	// 	// 			0.0,
+			// 	// 	// 			0.0,
+			// 	// 	// 			0.0,
+			// 	// 	// 			0.0
+			// 	// 	// 		]
+			// 	// 	// 	);
+			// 	// 	// });
+			// 	console.log(oscBundleObj);
+			// 	oscClient.send(oscBundleObj, () => {
+			// 		res.status(200).send();
+			// 	});
+			// }
 
 
-			oscBundle = new Bundle(
-				[ '/tuio/2Dcur', 'source', `tangibles${req.body.section.toString()}@127.0.0.1` ],
-				aliveMessage,
-				[ '/tuio/2Dcur', 'fseq', fseq ]
-			);
-			touches.forEach(touch => {
-				oscBundle.append(
-					[
-						'/tuio/2Dcur',
+			// oscBundle = new Bundle(
+			// 	[ '/tuio/2Dcur', 'source', `tangibles${req.body.section.toString()}@127.0.0.1` ],
+			// 	aliveMessage,
+			// 	[ '/tuio/2Dcur', 'fseq', fseq ]
+			// );
+			// touches.forEach(touch => {
+			// 	oscBundle.append(
+			// 		[
+			// 			'/tuio/2Dcur',
+			// 			'set',
+			// 			req.body.changedTouches[touch].identifier,
+			// 			req.body.changedTouches[touch].clientX / req.body.screenW,
+			// 			req.body.changedTouches[touch].clientY / req.body.screenH,
+			// 			0.0,
+			// 			0.0
+			// 		]
+			// 	);
+			// });
+			oscBundle = new Bundle ;
+			oscBundle.append([ '/tuio/2Dobj', 'alive', 1 ]);
+			if (objTriangle.dots != undefined){
+				oscBundle.append([
+						'/tuio/2Dobj',
 						'set',
-						req.body.changedTouches[touch].identifier,
-						req.body.changedTouches[touch].clientX / req.body.screenW,
-						req.body.changedTouches[touch].clientY / req.body.screenH,
+						1,
+						1,
+						objTriangle.center[0],
+						objTriangle.center[1],
+						objTriangle.orientation,
+						0.0,
+						0.0,
+						0.0,
 						0.0,
 						0.0
-					]
-				);
-			});
-			oscClient.send(oscBundle, () => {
-				res.status(200).json(JSON.stringify(req.body));
-			});
-		} else {
-			res.status(400).send();
-		}
+					]);
+				}
+				oscBundle.append([ '/tuio/2Dobj', 'fseq', fseq ]);
+				oscClient.send(oscBundle, () => {
+					res.status(200).send();
+				});
+			} else {
+				res.status(400).send();
+			}
 	}
 });
 
 server.listen(5001, function () {
  console.log('Votre app est disponible sur localhost:5001 !')
 });
-

BIN=BIN
emitter/frontend/assets/favicon.ico


+ 173 - 173
emitter/frontend/index.html

@@ -1,189 +1,189 @@
 <!DOCTYPE html>
 <html style="height: 100%;">
-<head>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width">
-	<title>Touch detect and send to Node server</title>
-</head>
+	<head>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width">
+		<title>Touch detect and send to Node server</title>
+	</head>
 
-<body style="height: 100%;">
-	<div id="box" style="width: 100%; height: 100%; background-color: #EEEEEE;"></div>
-	<script src="/jquery-1.7.2.js"></script>
-	<script>
-		/* simulation de touch events */
-		/*
-		function sendTouchEvent(x, y, element, eventType) {
-			const touchObj = new Touch({
-				identifier: Date.now(),
-				target: element,
-				clientX: x,
-				clientY: y,
-				radiusX: 2.5,
-				radiusY: 2.5,
-				rotationAngle: 10,
-				force: 0.5,
-			});
+	<body style="height: 100%;">
+		<div id="box" style="width: 100%; height: 100%; background-color: #EEEEEE;"></div>
+		<script src="/jquery-1.7.2.js"></script>
+		<script>
+			/* simulation de touch events */
+			/*
+			function sendTouchEvent(x, y, element, eventType) {
+				const touchObj = new Touch({
+					identifier: Date.now(),
+					target: element,
+					clientX: x,
+					clientY: y,
+					radiusX: 2.5,
+					radiusY: 2.5,
+					rotationAngle: 10,
+					force: 0.5,
+				});
 
-			const touchEvent = new TouchEvent(eventType, {
-				cancelable: true,
-				bubbles: true,
-				touches: [touchObj],
-				targetTouches: [],
-				changedTouches: [touchObj],
-				shiftKey: true,
-			});
+				const touchEvent = new TouchEvent(eventType, {
+					cancelable: true,
+					bubbles: true,
+					touches: [touchObj],
+					targetTouches: [],
+					changedTouches: [touchObj],
+					shiftKey: true,
+				});
 
-			element.dispatchEvent(touchEvent);
-		}
+				element.dispatchEvent(touchEvent);
+			}
 
-		sendTouchEvent(150, 150, box, 'touchstart');
-		sendTouchEvent(220, 200, box, 'touchmove');
-		sendTouchEvent(220, 200, box, 'touchend');
-		*/
+			sendTouchEvent(150, 150, box, 'touchstart');
+			sendTouchEvent(220, 200, box, 'touchmove');
+			sendTouchEvent(220, 200, box, 'touchend');
+			*/
 
-		const box = document.getElementById('box');
+			const box = document.getElementById('box');
 
-		const urlParams = new URLSearchParams(window.location.search);
-		const sectionParam = urlParams.get('section');
-		const section = sectionParam ? parseInt(sectionParam, 10) : 100;
-		const debugParams = urlParams.get('debug');
-		const debug = debugParams ? true : false;
-		if (debug) {
-			console.log('--- Debug activated ---');
-			console.log(`Section: ${section.toString()}`);
-		}
+			const urlParams = new URLSearchParams(window.location.search);
+			const sectionParam = urlParams.get('section');
+			const section = sectionParam ? parseInt(sectionParam, 10) : 100;
+			const debugParams = urlParams.get('debug');
+			const debug = debugParams ? true : false;
+			if (debug) {
+				console.log('--- Debug activated ---');
+				console.log(`Section: ${section.toString()}`);
+			}
 
-		box.addEventListener('touchstart', function(evt) {
-				if (debug) {
-					console.log(evt);
-				}
-				const touches = [];
-				for (var i = 0; i < evt.changedTouches.length; i++) {
-					touches[i] = {
-						clientX: evt.changedTouches[i].clientX,
-						clientY: evt.changedTouches[i].clientY,
-						force: evt.changedTouches[i].force,
-						identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
-						pageX: evt.changedTouches[i].pageX,
-						pageY: evt.changedTouches[i].pageY,
-						radiusX: evt.changedTouches[i].radiusX,
-						radiusY: evt.changedTouches[i].radiusY,
-						rotationAngle: evt.changedTouches[i].rotationAngle,
-						screenX: evt.changedTouches[i].screenX,
-						screenY: evt.changedTouches[i].screenY
+			box.addEventListener('touchstart', function(evt) {
+					if (debug) {
+						console.log(evt);
+					}
+					const touches = [];
+					for (var i = 0; i < evt.changedTouches.length; i++) {
+						touches[i] = {
+							clientX: evt.changedTouches[i].clientX,
+							clientY: evt.changedTouches[i].clientY,
+							force: evt.changedTouches[i].force,
+							identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
+							pageX: evt.changedTouches[i].pageX,
+							pageY: evt.changedTouches[i].pageY,
+							radiusX: evt.changedTouches[i].radiusX,
+							radiusY: evt.changedTouches[i].radiusY,
+							rotationAngle: evt.changedTouches[i].rotationAngle,
+							screenX: evt.changedTouches[i].screenX,
+							screenY: evt.changedTouches[i].screenY
+						};
 					};
-				};
-				box.innerHTML = evt.touches.length;
-				fetch('http://localhost:5001/json', {
-					method: 'POST',
-					mode: 'cors',
-					cache: 'no-cache',
-					credentials: 'same-origin',
-					headers: {
-						'Content-Type': 'application/json'
-					},
-					redirect: 'follow',
-					referrerPolicy: 'no-referrer',
-					body: JSON.stringify({
-						event: 'touchstart',
-						debug,
-						section,
-						screenW: $(document).width(),
-						screenH: $(document).height(),
-						changedTouches: touches
-					})
-				});
-				evt.preventDefault();
-		});
-		box.addEventListener('touchmove', function(evt) {
-				if (debug) {
-					console.log(evt);
-				}
-				const touches = [];
-				for (var i = 0; i < evt.changedTouches.length; i++) {
-					touches[i] = {
-						clientX: evt.changedTouches[i].clientX,
-						clientY: evt.changedTouches[i].clientY,
-						force: evt.changedTouches[i].force,
-						identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
-						pageX: evt.changedTouches[i].pageX,
-						pageY: evt.changedTouches[i].pageY,
-						radiusX: evt.changedTouches[i].radiusX,
-						radiusY: evt.changedTouches[i].radiusY,
-						rotationAngle: evt.changedTouches[i].rotationAngle,
-						screenX: evt.changedTouches[i].screenX,
-						screenY: evt.changedTouches[i].screenY
+					box.innerHTML = evt.touches.length;
+					fetch('http://localhost:5001/json', {
+						method: 'POST',
+						mode: 'cors',
+						cache: 'no-cache',
+						credentials: 'same-origin',
+						headers: {
+							'Content-Type': 'application/json'
+						},
+						redirect: 'follow',
+						referrerPolicy: 'no-referrer',
+						body: JSON.stringify({
+							event: 'touchstart',
+							debug,
+							section,
+							screenW: $(document).width(),
+							screenH: $(document).height(),
+							changedTouches: touches
+						})
+					});
+					evt.preventDefault();
+			});
+			box.addEventListener('touchmove', function(evt) {
+					if (debug) {
+						console.log(evt);
+					}
+					const touches = [];
+					for (var i = 0; i < evt.changedTouches.length; i++) {
+						touches[i] = {
+							clientX: evt.changedTouches[i].clientX,
+							clientY: evt.changedTouches[i].clientY,
+							force: evt.changedTouches[i].force,
+							identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
+							pageX: evt.changedTouches[i].pageX,
+							pageY: evt.changedTouches[i].pageY,
+							radiusX: evt.changedTouches[i].radiusX,
+							radiusY: evt.changedTouches[i].radiusY,
+							rotationAngle: evt.changedTouches[i].rotationAngle,
+							screenX: evt.changedTouches[i].screenX,
+							screenY: evt.changedTouches[i].screenY
+						};
 					};
-				};
-				box.innerHTML = evt.touches.length;
-				fetch('http://localhost:5001/json', {
-					method: 'POST',
-					mode: 'cors',
-					cache: 'no-cache',
-					credentials: 'same-origin',
-					headers: {
-						'Content-Type': 'application/json'
-					},
-					redirect: 'follow',
-					referrerPolicy: 'no-referrer',
-					body: JSON.stringify({
-						event: 'touchmove',
-						debug,
-						section,
-						screenW: $(document).width(),
-						screenH: $(document).height(),
-						changedTouches: touches
-					})
-				});
-				evt.preventDefault();
-		});
+					box.innerHTML = evt.touches.length;
+					fetch('http://localhost:5001/json', {
+						method: 'POST',
+						mode: 'cors',
+						cache: 'no-cache',
+						credentials: 'same-origin',
+						headers: {
+							'Content-Type': 'application/json'
+						},
+						redirect: 'follow',
+						referrerPolicy: 'no-referrer',
+						body: JSON.stringify({
+							event: 'touchmove',
+							debug,
+							section,
+							screenW: $(document).width(),
+							screenH: $(document).height(),
+							changedTouches: touches
+						})
+					});
+					evt.preventDefault();
+			});
 
-		box.addEventListener('touchend', function(evt) {
-				if (debug) {
-					console.log(evt);
-				}
-				const touches = [];
-				for (var i = 0; i < evt.changedTouches.length; i++) {
-					touches[i] = {
-						clientX: evt.changedTouches[i].clientX,
-						clientY: evt.changedTouches[i].clientY,
-						force: evt.changedTouches[i].force,
-						identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
-						pageX: evt.changedTouches[i].pageX,
-						pageY: evt.changedTouches[i].pageY,
-						radiusX: evt.changedTouches[i].radiusX,
-						radiusY: evt.changedTouches[i].radiusY,
-						rotationAngle: evt.changedTouches[i].rotationAngle,
-						screenX: evt.changedTouches[i].screenX,
-						screenY: evt.changedTouches[i].screenY
+			box.addEventListener('touchend', function(evt) {
+					if (debug) {
+						console.log(evt);
+					}
+					const touches = [];
+					for (var i = 0; i < evt.changedTouches.length; i++) {
+						touches[i] = {
+							clientX: evt.changedTouches[i].clientX,
+							clientY: evt.changedTouches[i].clientY,
+							force: evt.changedTouches[i].force,
+							identifier: ((evt.changedTouches[i].identifier + 1) % 100) + section,
+							pageX: evt.changedTouches[i].pageX,
+							pageY: evt.changedTouches[i].pageY,
+							radiusX: evt.changedTouches[i].radiusX,
+							radiusY: evt.changedTouches[i].radiusY,
+							rotationAngle: evt.changedTouches[i].rotationAngle,
+							screenX: evt.changedTouches[i].screenX,
+							screenY: evt.changedTouches[i].screenY
+						};
 					};
-				};
-				box.innerHTML = evt.touches.length;
-				fetch('http://localhost:5001/json', {
-					method: 'POST',
-					mode: 'cors',
-					cache: 'no-cache',
-					credentials: 'same-origin',
-					headers: {
-						'Content-Type': 'application/json'
-					},
-					redirect: 'follow',
-					referrerPolicy: 'no-referrer',
-					body: JSON.stringify({
-						event: 'touchend',
-						debug,
-						section,
-						screenW: $(document).width(),
-						screenH: $(document).height(),
-						changedTouches: touches
-					})
-				});
-				evt.preventDefault();
-		});
+					box.innerHTML = evt.touches.length;
+					fetch('http://localhost:5001/json', {
+						method: 'POST',
+						mode: 'cors',
+						cache: 'no-cache',
+						credentials: 'same-origin',
+						headers: {
+							'Content-Type': 'application/json'
+						},
+						redirect: 'follow',
+						referrerPolicy: 'no-referrer',
+						body: JSON.stringify({
+							event: 'touchend',
+							debug,
+							section,
+							screenW: $(document).width(),
+							screenH: $(document).height(),
+							changedTouches: touches
+						})
+					});
+					evt.preventDefault();
+			});
 
-		if (!(typeof box.ontouchstart != 'undefined')) {
-				box.style.border = '1px solid red';
-		}
+			if (!(typeof box.ontouchstart != 'undefined')) {
+					box.style.border = '1px solid red';
+			}
 		</script>
-</body>
+	</body>
 </html>

+ 5 - 3
receiver/backend/server.js

@@ -30,17 +30,19 @@ app.use(bodyParser.urlencoded({extended:true}));
 app.use(express.static('./frontend/assets'));
 
 app.get('/', function (req, res) {
-	res.sendFile('./frontend/index.html', { root: path.resolve(__dirname + '/..') });
+	res.sendFile('./frontend/index.html', {
+		root: path.resolve(__dirname + '/..')
+	});
 });
 
 app.get('/json', function (req, res) {
-	res.status(200).json({'message': 'ok'})
+	res.status(200).send();
 });
 
 io.sockets.on('connection', (socket) =>{
 	console.log(`Connecté au client ${socket.id}`);
 	const dgramCallback = function (buf) {
-		console.log(oscParser.decode(buf));
+		// console.log(oscParser.decode(buf));
 		socket.emit('osc', oscParser.decode(buf));
 	};
 

BIN=BIN
receiver/frontend/assets/favicon.ico


+ 116 - 90
receiver/frontend/index.html

@@ -1,107 +1,133 @@
 <!DOCTYPE html>
 <html>
-<head>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width">
-	<title>Proof of concept - Objets tangibles</title>
-</head>
+	<head>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width">
+		<title>Proof of concept - Objets tangibles</title>
 
-<body>
-	<script src="/jquery-1.7.2.js"></script>
-	<script src="/lodash.js"></script>
-	<script src="/socket.io/socket.io.js"></script>
-	<script src="/tuio.js"></script>
-	<style>
-		body {
-			background: #000;
-			margin: 0;
-		}
-		.tuioCursor {
-			background: #fff;
-			height: 8px;
-			left: 0;
-			position: absolute;
-			top: 0;
-			width: 8px;
-		}
-	</style>
+		<style>
+			body {
+				background: #000;
+				margin: 0;
+			}
+			.tuioCursor {
+				background: #fff;
+				height: 8px;
+				left: 0;
+				position: absolute;
+				top: 0;
+				width: 8px;
+			}
+			.tuioObj {
+				background: #f00;
+				height: 15px;
+				left: 0;
+				position: absolute;
+				top: 0;
+				width: 8px;
+				rotate: 0deg;
+			}
+		</style>
+	</head>
 
-	<script>
-				$(function() {
-					const urlParams = new URLSearchParams(window.location.search);
-					const debugParams = urlParams.get('debug');
-					const debug = debugParams ? true : false;
-					if (debug) {
-						console.log('--- Debug activated ---');
-					}
-					var dotGroups = [];
-						var client = new Tuio.Client({
-							host: 'http://localhost:5000'
-						}),
-						screenW = $(document).width(),
-						screenH = $(document).height()
+	<body>
+		<script src="/jquery-1.7.2.js"></script>
+		<script src="/lodash.js"></script>
+		<script src="/socket.io/socket.io.js"></script>
+		<script src="/tuio.js"></script>
 
-						cursors = {},
+		<script>
+		$(function() {
+			const urlParams = new URLSearchParams(window.location.search);
+			const debugParams = urlParams.get('debug');
+			const debug = debugParams ? true : false;
+			if (debug) {
+				console.log('--- Debug activated ---');
+			}
+			var dotGroups = [];
+				var client = new Tuio.Client({
+					host: 'http://localhost:5000'
+				}),
+				screenW = $(document).width(),
+				screenH = $(document).height()
 
-						onConnect = function() {
-							if (debug) {
-								console.log('connected');
-							}
-						},
+				cursors = {},
+				objects = {},
 
-						onAddTuioCursor = function(addCursor) {
-							var $addCursor = $('<div class="tuioCursor"></div>');
-							$('body').append($addCursor);
-							cursors[addCursor.getCursorId()] = $addCursor;
-							onUpdateTuioCursor(addCursor);
-						},
+				onConnect = function() {
+					if (debug) {
+						console.log('connected');
+					}
+				},
 
-						onUpdateTuioCursor = function(updateCursor) {
-							var $updateCursor = cursors[updateCursor.getCursorId()];
-							$updateCursor.css({
-								left: updateCursor.getScreenX(screenW),
-								top: updateCursor.getScreenY(screenH)
-							});
-						},
+				onAddTuioCursor = function(addCursor) {
+					var $addCursor = $('<div class="tuioCursor"></div>');
+					$('body').append($addCursor);
+					cursors[addCursor.getCursorId()] = $addCursor;
+					onUpdateTuioCursor(addCursor);
+				},
 
-						onRemoveTuioCursor = function(removeCursor) {
-							var $removeCursor = cursors[removeCursor.getCursorId()];
-							$removeCursor.remove();
-							delete[removeCursor.getCursorId()];
-						},
+				onUpdateTuioCursor = function(updateCursor) {
+					var $updateCursor = cursors[updateCursor.getCursorId()];
+					$updateCursor.css({
+						left: updateCursor.getScreenX(screenW),
+						top: updateCursor.getScreenY(screenH)
+					});
+				},
 
-						onAddTuioObject = function(addObject) {
-							if (debug) {
-								console.log('addTuioObject', addObject);
-							}
-						},
+				onRemoveTuioCursor = function(removeCursor) {
+					var $removeCursor = cursors[removeCursor.getCursorId()];
+					$removeCursor.remove();
+					delete[removeCursor.getCursorId()];
+				},
 
-						onUpdateTuioObject = function(updateObject) {
-							if (debug) {
-								console.log('updateTuioObject', updateObject);
-							}
-						},
+				onAddTuioObject = function(addObject) {
+					var $addObject = $('<div class="tuioObj"></div>');
+					$('body').append($addObject);
+					objects[addObject.symbolID] = $addObject;
+					onUpdateTuioObject(addObject);
+					if (debug) {
+						console.log('addTuioObject', addObject);
+					}
+				},
 
-						onRemoveTuioObject = function(removeObject) {
-							if (debug) {
-								console.log('removeTuioObject', removeObject);
-							}
-						},
+				onUpdateTuioObject = function(updateObject) {
+					var $updateObject = objects[updateObject.symbolID];
+					$updateObject.css({
+						left: updateObject.getScreenX(screenW),
+						top: updateObject.getScreenY(screenH),
+						rotate : updateObject.getAngleDegrees()
+					});
+					if (debug) {
+						console.log('updateTuioObject', updateObject);
+					}
+				},
 
-						onRefresh = function(time) {
+				onRemoveTuioObject = function(removeObject) {
+					var $removeObject = objects[removeObject.symbolID];
+					$removeObject.remove();
+					delete[removeObject.symbolID];
+					if (debug) {
+						console.log('removeTuioObject', removeObject);
+					}
+				},
 
-						};
+				onRefresh = function(time) {
+					if (debug) {
+						console.log('refresh', time);
+					}
+				};
 
-						client.on("connect", onConnect);
-						client.on("addTuioCursor", onAddTuioCursor);
-						client.on("updateTuioCursor", onUpdateTuioCursor);
-						client.on("removeTuioCursor", onRemoveTuioCursor);
-						client.on("addTuioObject", onAddTuioObject);
-						client.on("updateTuioObject", onUpdateTuioObject);
-						client.on("removeTuioObject", onRemoveTuioObject);
-						client.on("refresh", onRefresh);
-						client.connect();
-					});
+				client.on('connect', onConnect);
+				client.on('addTuioCursor', onAddTuioCursor);
+				client.on('updateTuioCursor', onUpdateTuioCursor);
+				client.on('removeTuioCursor', onRemoveTuioCursor);
+				client.on('addTuioObject', onAddTuioObject);
+				client.on('updateTuioObject', onUpdateTuioObject);
+				client.on('removeTuioObject', onRemoveTuioObject);
+				client.on('refresh', onRefresh);
+				client.connect();
+			});
 		</script>
-</body>
+	</body>
 </html>