Browse Source

change logic of triangle searching

unknown 2 years ago
parent
commit
4cca31efa2
3 changed files with 38 additions and 42 deletions
  1. 11 11
      backend/server.js
  2. 12 16
      frontend/assets/config.json
  3. 15 15
      frontend/index.html

+ 11 - 11
backend/server.js

@@ -130,7 +130,7 @@ function getAngleApex(dotTrio, topIndex) {
 
 	const alpha = Math.atan2(crossProd, dotProd);
 	//return alpha ;
-	return Math.floor(alpha * 180. / Math.PI + 0.5) ;
+	return Math.abs(Math.floor(alpha * 180. / Math.PI + 0.5)) ;
 }
 
 function getOrientation(dotTrio, topIndex) {
@@ -228,13 +228,13 @@ app.post('/emitter/json', function (req, res) {
 
 			/* Listage de tous les points */
 			const dots = [];
-			touches.forEach(function(touch) {
+			for(const touch of req.body.touches){
 				dots.push({
-					id: req.body.touches[touch].identifier,
-					x: req.body.touches[touch].clientX,
-					y: req.body.touches[touch].clientY
+					id: touch.identifier,
+					x: touch.clientX,
+					y: touch.clientY
 				});
-			});
+			};
 			if (config.app.debug && config.app.debugLog.backend.emitter.dots) {
 				console.log('-- dots --', dots);
 			}
@@ -274,7 +274,7 @@ app.post('/emitter/json', function (req, res) {
 			/* Listage des triangles */
 			const triangles = [];
 			/* on boucle sur les segments */
-			segments.forEach((segment) => {
+			for(const segment of segments) {
 				const dot1 = segment.identifiers[0];
 				const dot2 = segment.identifiers[1];
 				/* on vérifie que le triangle n'est pas déjà listé */
@@ -299,7 +299,7 @@ app.post('/emitter/json', function (req, res) {
 						triangles.push([dot1, dot2, dot3]);
 					}
 				}
-			});
+			};
 			if (config.app.debug && config.app.debugLog.backend.emitter.triangles) {
 				console.log('-- triangles --', triangles);
 			}
@@ -309,7 +309,7 @@ app.post('/emitter/json', function (req, res) {
 			objTriangle = {} ;
 
 			/* Définition de l'apex, de la position du centre et de l'orientation */
-			triangles.forEach(triangle => {
+			for(const triangle of triangles){
 				objTriangle.dots = [];
 				objTriangle.dots[0] = dots[triangle[0]];
 				objTriangle.dots[1] = dots[triangle[1]];
@@ -330,7 +330,7 @@ app.post('/emitter/json', function (req, res) {
 					console.log('centerPos: ' + objTriangle.center);
 					console.log('orientation: ' + objTriangle.orientation);
 				}
-			});
+			};
 
 
 			//plante vite
@@ -404,7 +404,7 @@ app.post('/emitter/json', function (req, res) {
 				const matchingObject = config.objects.find(item => {
 					return objTriangle.angleApex > item.apexAngle - config.app.matchingTolerance && objTriangle.angleApex < item.apexAngle + config.app.matchingTolerance;
 				});
-				console.log(matchingObject);
+				console.log('matching object ', matchingObject);
 				currentOscBundle.append([
 					'/tuio/2Dobj',
 					'set',

+ 12 - 16
frontend/assets/config.json

@@ -3,8 +3,8 @@
 		"oscUdpPort": 3333,
 		"httpPort": 5000,
 		"timerRefresh": 100,
-		"maxDistanceBetweenPoints": 750,
-		"matchingTolerance": 2.5,
+		"maxDistanceBetweenPoints": 100,
+		"matchingTolerance": 2,
 		"debug": true,
 		"debugLog": {
 			"backend": {
@@ -25,22 +25,22 @@
 					"events": false
 				},
 				"receiver": {
-					"onAddTuioCursor": false,
-					"onUpdateTuioCursor": false,
+					"onAddTuioCursor": true,
+					"onUpdateTuioCursor": true,
 					"onRemoveTuioCursor": false,
-					"onAddTuioObject": false,
-					"onUpdateTuioObject": false,
+					"onAddTuioObject": true,
+					"onUpdateTuioObject": true,
 					"onRemoveTuioObject": false,
 					"onRefresh": false
 				}
 			}
 		},
-		"debugDisplay": false
+		"debugDisplay": true
 	},
 	"objects": [
 		{
 			"name": "object1",
-			"apexAngle": 35
+			"apexAngle": 30
 		},
 		{
 			"name": "object2",
@@ -48,23 +48,19 @@
 		},
 		{
 			"name": "object2",
-			"apexAngle": 45
+			"apexAngle": 50
 		},
 		{
 			"name": "object4",
-			"apexAngle": 50
+			"apexAngle": 70
 		},
 		{
 			"name": "object5",
-			"apexAngle": 55
+			"apexAngle": 80
 		},
 		{
 			"name": "object6",
-			"apexAngle": 60
-		},
-		{
-			"name": "object7",
-			"apexAngle": 65
+			"apexAngle": 90
 		}
 	]
 }

+ 15 - 15
frontend/index.html

@@ -80,19 +80,19 @@
 
 				const eventHandler = (evt, type) => {
 					const touches = [];
-					for (var i = 0; i < evt.changedTouches.length; i++) {
+					for (var i = 0; i < evt.touches.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
+							clientX: evt.touches[i].clientX,
+							clientY: evt.touches[i].clientY,
+							force: evt.touches[i].force,
+							identifier: ((evt.touches[i].identifier + 1) % 100) + section,
+							pageX: evt.touches[i].pageX,
+							pageY: evt.touches[i].pageY,
+							radiusX: evt.touches[i].radiusX,
+							radiusY: evt.touches[i].radiusY,
+							rotationAngle: evt.touches[i].rotationAngle,
+							screenX: evt.touches[i].screenX,
+							screenY: evt.touches[i].screenY
 						};
 					};
 
@@ -133,9 +133,9 @@
 					return eventHandler(evt, 'touchmove');
 				});
 
-				box.addEventListener('touchend', (evt) => {
-					return eventHandler(evt, 'touchend');
-				});
+				// box.addEventListener('touchend', (evt) => {
+				// 	return eventHandler(evt, 'touchend');
+				// });
 
 				/* --------
 				 * RECEIVER