2
0

misc_controls_deviceorientation.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - controls - deviceorientation</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="user-scalable=no, initial-scale=1">
  7. <style>
  8. body {
  9. margin: 0px;
  10. background-color: #000000;
  11. overflow: hidden;
  12. }
  13. #info {
  14. position: absolute;
  15. top: 0px; width: 100%;
  16. color: #ffffff;
  17. padding: 5px;
  18. font-family:Monospace;
  19. font-size:13px;
  20. font-weight: bold;
  21. text-align:center;
  22. }
  23. a {
  24. color: #ff8800;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id="info">
  30. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - equirectangular panorama demo with DeviceOrientation controls.
  31. photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank" rel="noopener">Jón Ragnarsson</a>.
  32. </div>
  33. <script src="../build/three.js"></script>
  34. <script src="js/controls/DeviceOrientationControls.js"></script>
  35. <script>
  36. var camera, scene, renderer, controls;
  37. init();
  38. animate();
  39. function init() {
  40. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  41. controls = new THREE.DeviceOrientationControls( camera );
  42. scene = new THREE.Scene();
  43. var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
  44. // invert the geometry on the x-axis so that all of the faces point inward
  45. geometry.scale( - 1, 1, 1 );
  46. var material = new THREE.MeshBasicMaterial( {
  47. map: new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
  48. } );
  49. var mesh = new THREE.Mesh( geometry, material );
  50. scene.add( mesh );
  51. var helperGeometry = new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
  52. var helperMaterial = new THREE.MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
  53. var helper = new THREE.Mesh( helperGeometry, helperMaterial );
  54. scene.add( helper );
  55. //
  56. renderer = new THREE.WebGLRenderer( { antialias: true } );
  57. renderer.setPixelRatio( window.devicePixelRatio );
  58. renderer.setSize( window.innerWidth, window.innerHeight );
  59. document.body.appendChild( renderer.domElement );
  60. //
  61. window.addEventListener( 'resize', onWindowResize, false );
  62. }
  63. function animate() {
  64. window.requestAnimationFrame( animate );
  65. controls.update();
  66. renderer.render( scene, camera );
  67. }
  68. function onWindowResize() {
  69. camera.aspect = window.innerWidth / window.innerHeight;
  70. camera.updateProjectionMatrix();
  71. renderer.setSize( window.innerWidth, window.innerHeight );
  72. }
  73. </script>
  74. </body>
  75. </html>