Skip to content

Commit

Permalink
update server and client links
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyH2 committed Apr 11, 2024
1 parent 7020d5a commit 585b648
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 8 additions & 2 deletions server/positionalTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ 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

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();
});
};
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions src/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
};
Expand Down

0 comments on commit 585b648

Please sign in to comment.