Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyH2 committed Apr 14, 2024
1 parent 5574d83 commit 54ce7de
Show file tree
Hide file tree
Showing 12 changed files with 697 additions and 798,942 deletions.
Binary file added assets/objects/.enviroment.obj.icloud
Binary file not shown.
Binary file added assets/objects/.gear_vr_controller.obj.icloud
Binary file not shown.
752,057 changes: 0 additions & 752,057 deletions assets/objects/enviroment.obj

This file was deleted.

46,882 changes: 0 additions & 46,882 deletions assets/objects/gear_vr_controller.obj

This file was deleted.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ <h2 class="socketCode">Code...</h2>
</div>

<script src="/socket.io/socket.io.js"></script>

<script src="./utils/www-ahrs.js"></script>

<script src="./libraries/three.js"></script>
<script src="./libraries/cardboard-vr-display.js"></script>

Expand Down
9 changes: 9 additions & 0 deletions node_modules/http/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions node_modules/http/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"start": "node server.js"
},
"author": "CrazyH",
"license": "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International"
"license": "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International",
"dependencies": {
"http": "0.0.1-security"
}
}
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require("express");
const { Server } = require("socket.io");
const { createServer } = require('node:http');
const { createServer } = require('http');

const app = express();
const server = createServer(app);
Expand Down
50 changes: 50 additions & 0 deletions src/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ class PeerManager {

this.socket = io();

var AHRS = require("ahrs");

this.ahrs = new AHRS({

sampleInterval: 68.84681583453657, // Madgwick is sensitive to this
algorithm: 'Madgwick',
beta: 0.8,

});

this.lastZeroQuaternion = null;

this.driftCompensation = [0, 0, 0];
this.lastTimestamp = 0;

this.socket.on('connect', function() {
scope.peerId = scope.socket.id;

Expand Down Expand Up @@ -63,6 +78,7 @@ class PeerManager {
};

update(scope, position, rotation, posNotFound) {
// Position
if(posNotFound == false) {
var posx = (position.x + (position.width / 2));
var posy = (position.y + (position.height / 2));
Expand All @@ -75,6 +91,40 @@ class PeerManager {
} else {
this.root.render.scene.hand.position.set(0, -0.3, -0.2);
};

// Rotation
var data = rotation;

let deltaTimeSeconds = 0;

if (scope.lastTimestamp) {
deltaTimeSeconds = (data.timestamp - scope.lastTimestamp);

scope.ahrs.update(
data.gyro[0],
data.gyro[1],
data.gyro[2],
data.accel[0],
data.accel[1],
data.accel[2],
data.magX, data.magY, data.magZ,
deltaTimeSeconds
);
};

scope.lastTimestamp = data.timestamp;

const {x, y, z, w} = scope.ahrs.getQuaternion();
scope.root.render.scene.hand.quaternion.set(x, z, -y, w);

if (data.homeButton) {
scope.lastZeroQuaternion = scope.root.render.scene.hand.quaternion.clone().inverse();
console.log(`Re-zeroed orientation! ${(new Date()).valueOf()}`);
}

if (scope.lastZeroQuaternion) {
scope.root.render.scene.hand.quaternion.premultiply(scope.lastZeroQuaternion);
}
};

launch(evt) {
Expand Down
Loading

0 comments on commit 54ce7de

Please sign in to comment.