From 585b6485a06c94bcdd97f6cfd193c0f0c3716e3f Mon Sep 17 00:00:00 2001 From: CrazyH <87752773+CrazyH2@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:08:13 +0100 Subject: [PATCH] update server and client links --- server/positionalTracking.js | 10 ++++++++-- src/peer.js | 11 +++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/positionalTracking.js b/server/positionalTracking.js index b707481..9e5c6df 100644 --- a/server/positionalTracking.js +++ b/server/positionalTracking.js @@ -3,6 +3,9 @@ class PositionalTracking { this.root = root; var scope = this; + this.cameraWidth = 0; + this.cameraHeight = 0; + this.focalLength = 10000000; // Focal length of the camera in pixels (hypothetical value) this.trackedObjectWidth = 4; // Width of the object in cm this.trackedObjectHeight = 4; // Height of the object in cm @@ -10,6 +13,9 @@ class PositionalTracking { navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: "user" }}).then(function success(stream) { document.querySelector("#cameraFeed").srcObject = stream; + this.cameraWidth = stream.getTracks()[0].getSettings().width; + this.cameraHeight = stream.getTracks()[0].getSettings().height; + scope.start(); }); }; @@ -76,8 +82,8 @@ class PositionalTracking { x: event.data[0].x, y: event.data[0].y, z: event.data[0].z, - screenWidth: window.innerWidth, - screenHeight: window.innerHeight, + cameraWidth: scope.cameraWidth, + cameraHeight: scope.cameraHeight, }; scope.root.position = output; diff --git a/src/peer.js b/src/peer.js index 1f92476..254b6ad 100644 --- a/src/peer.js +++ b/src/peer.js @@ -7,6 +7,8 @@ class PeerManager { this.root = root; var scope = this; + this.cameraScale = 10; + this.started = false; this.peerId = this.makeid(3) + "-" + this.makeid(3) + "-" + this.makeid(3); @@ -66,13 +68,10 @@ class PeerManager { var posy = (position.y + (position.height / 2)); var posz = position.z; - var conv = new THREE.Vector3(); - conv.project(this.root.render.scene.camera); - conv.x = ( posx * (position.screenWidth / 2) ) + (position.screenWidth / 2); - conv.y = - ( posy * (position.screenHeight / 2) ) + (position.screenHeight / 2); - conv.z = posz; + var worldX = (posx / position.cameraWidth) * 2 - 1; + var worldY = -(posy / position.cameraHeight) * 2 + 1; - this.root.render.scene.hand.position.copy(conv); + this.root.render.scene.hand.position.set(worldX * scope.cameraScale, worldY * scope.cameraScale, posz); } else { this.root.render.scene.hand.position.set(0, -0.3, -0.2); };