From 512fc9078203b880c1a872a3f04315bd31c3d41b Mon Sep 17 00:00:00 2001 From: Alexander Bazo Date: Tue, 27 Aug 2019 13:38:47 +0200 Subject: [PATCH] Connect gaze data with game client --- resources/js/game/GazePoint.js | 4 ++-- resources/js/game/StarGazer.js | 8 ++++---- resources/js/index.js | 8 ++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/js/game/GazePoint.js b/resources/js/game/GazePoint.js index 7651ad8..94cdf7d 100644 --- a/resources/js/game/GazePoint.js +++ b/resources/js/game/GazePoint.js @@ -1,9 +1,9 @@ class GazePoint { - constructor(screenX, screenY, id) { + constructor(screenX, screenY, createdAt, id) { this.screenX = screenX; this.screenY = screenY; - this.createdAt = Date.now(); + this.createdAt = createdAt; this.id = id || this.createdAt; } diff --git a/resources/js/game/StarGazer.js b/resources/js/game/StarGazer.js index b4c0a3f..d9a917b 100644 --- a/resources/js/game/StarGazer.js +++ b/resources/js/game/StarGazer.js @@ -15,10 +15,10 @@ class StarGazer { gm.start(); } - onGazeUpdate(gazeUpdate) { - gazeUpdate.target.linkTo(canvas); - if(gazeUpdate.target.hasLink) { - gm.addGazePoint(gazeUpdate.target); + onGazeUpdate(gazePoint) { + gazePoint.linkTo(canvas); + if(gazePoint.hasLink) { + gm.addGazePoint(gazePoint); } } diff --git a/resources/js/index.js b/resources/js/index.js index 211fca4..5b9c279 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -15,7 +15,7 @@ function init() { function initGazeClient() { gclient.connect("ws://localhost:8001/gaze"); gclient.addEventListener("connectionopened", onConnected); - gclient.addEventListener("dataAvailable", onGazeDataAvailable); + gclient.addEventListener("dataavailable", onGazeDataAvailable); gclient.addEventListener("connectionclosed", onDisconnected); } @@ -33,7 +33,11 @@ function onConnected(event) { } function onGazeDataAvailable(event) { - console.log(event); + let eyeX = (event.data.leftEyeX + event.data.rightEyeX) / 2, + eyeY = (event.data.leftEyeY + event.data.rightEyeY) / 2, + createdAt = event.data.trackerTimeStamp, + gazePoint = new GazePoint(eyeX, eyeY, createdAt); + StarGazer.onGazeUpdate(gazePoint); } function onDisconnected(event) { -- libgit2 0.26.0