Created
June 7, 2023 10:00
-
-
Save addy1997/20af696fb65799f22d75b6ff5fa7111c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AFRAME.registerComponent('camera-logger', { | |
schema: { | |
timestamp: { | |
type: 'int' | |
}, | |
seconds: { | |
type: 'int' | |
} | |
}, | |
init: function() { | |
var cameraEl = this.el.sceneEl.camera.el; | |
var rotation = cameraEl.getAttribute('rotation'); | |
var worldPos = new THREE.Vector3(); | |
worldPos.setFromMatrixPosition(cameraEl.object3D.matrixWorld); | |
console.log("Time: " + this.data.seconds + | |
"; Camera Position: (" + worldPos.x.toFixed(2) + ", " + worldPos.y.toFixed(2) + ", " + worldPos.z.toFixed(2) + | |
"); Camera Rotation: (" + rotation.x.toFixed(2) + ", " + rotation.y.toFixed(2) + ", " + rotation.z.toFixed(2) + ")"); | |
}, | |
play: function() { | |
this.data.timestamp = Date.now(); | |
this.init(); | |
}, | |
tick: function() { | |
if (Date.now() - this.data.timestamp > 1000) { | |
this.data.timestamp += 1000; | |
this.data.seconds += 1; | |
this.init(); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment