-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GPS and sensor example, and examples readme
- Loading branch information
Showing
8 changed files
with
125 additions
and
827 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>three.js</title> | ||
<script type='module' src='src/main.js'></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as THREE from 'three'; | ||
import * as LocAR from 'locar'; | ||
|
||
const camera = new THREE.PerspectiveCamera(80, window.innerWidth / window.innerHeight, 0.001, 1000); | ||
|
||
const renderer = new THREE.WebGLRenderer(); | ||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
document.body.appendChild(renderer.domElement); | ||
|
||
const scene = new THREE.Scene(); | ||
|
||
const locar = new LocAR.LocationBased(scene, camera); | ||
|
||
window.addEventListener("resize", e => { | ||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
camera.aspect = window.innerWidth / window.innerHeight; | ||
camera.updateProjectionMatrix(); | ||
}); | ||
|
||
const cam = new LocAR.WebcamRenderer(renderer); | ||
|
||
let firstLocation = true; | ||
|
||
const deviceOrientationControls = new LocAR.DeviceOrientationControls(camera); | ||
|
||
locar.on("gpsupdate", (pos, distMoved) => { | ||
if(firstLocation) { | ||
alert(`Got the initial location: longitude ${pos.coords.longitude}, latitude ${pos.coords.latitude}`); | ||
|
||
const boxProps = [{ | ||
latDis: 0.001, | ||
lonDis: 0, | ||
colour: 0xff0000 | ||
}, { | ||
latDis: -0.001, | ||
lonDis: 0, | ||
colour: 0xffff00 | ||
}, { | ||
latDis: 0, | ||
lonDis: -0.001, | ||
colour: 0x00ffff | ||
}, { | ||
latDis: 0, | ||
lonDis: 0.001, | ||
colour: 0x00ff00 | ||
}]; | ||
|
||
const geom = new THREE.BoxGeometry(20,20,20); | ||
|
||
for(const boxProp of boxProps) { | ||
const mesh = new THREE.Mesh( | ||
geom, | ||
new THREE.MeshBasicMaterial({color: boxProp.colour}) | ||
); | ||
|
||
console.log(`adding at ${pos.coords.longitude + boxProp.lonDis},${pos.coords.latitude + boxProp.latDis}`); | ||
locar.add( | ||
mesh, | ||
pos.coords.longitude + boxProp.lonDis, | ||
pos.coords.latitude + boxProp.latDis | ||
); | ||
} | ||
|
||
firstLocation = false; | ||
} | ||
}); | ||
|
||
locar.startGps(); | ||
|
||
renderer.setAnimationLoop(animate); | ||
|
||
function animate() { | ||
cam.update(); | ||
deviceOrientationControls.update(); | ||
renderer.render(scene, camera); | ||
} | ||
|
Oops, something went wrong.