4 <title>three.js webgl - controls - deviceorientation</title>
6 <meta name="viewport" content="user-scalable=no, initial-scale=1">
10 background-color: #000000;
16 top: 0px; width: 100%;
19 font-family:Monospace;
32 <div id="container"></div>
35 <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - equirectangular panorama demo with DeviceOrientation controls.
36 photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank" rel="noopener">Jón Ragnarsson</a>.
39 <script src="../build/three.js"></script>
40 <script src="js/controls/DeviceOrientationControls.js"></script>
44 var container, camera, scene, renderer, controls;
51 container = document.getElementById( 'container' );
53 camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
55 controls = new THREE.DeviceOrientationControls( camera );
57 scene = new THREE.Scene();
59 var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
60 // invert the geometry on the x-axis so that all of the faces point inward
61 geometry.scale( - 1, 1, 1 );
63 var material = new THREE.MeshBasicMaterial( {
64 map: new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
67 var mesh = new THREE.Mesh( geometry, material );
70 var helperGeometry = new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
71 var helperMaterial = new THREE.MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
72 var helper = new THREE.Mesh( helperGeometry, helperMaterial );
77 renderer = new THREE.WebGLRenderer();
78 renderer.setPixelRatio( window.devicePixelRatio );
79 renderer.setSize( window.innerWidth, window.innerHeight );
80 container.appendChild( renderer.domElement );
84 window.addEventListener( 'resize', onWindowResize, false );
91 window.requestAnimationFrame( animate );
94 renderer.render( scene, camera );
98 function onWindowResize() {
100 camera.aspect = window.innerWidth / window.innerHeight;
101 camera.updateProjectionMatrix();
103 renderer.setSize( window.innerWidth, window.innerHeight );