misc_controls_deviceorientation.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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="container"></div>
  30. <div id="info">
  31. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - equirectangular panorama demo with DeviceOrientation controls.
  32. photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank" rel="noopener">Jón Ragnarsson</a>.
  33. </div>
  34. <script src="../build/three.js"></script>
  35. <script src="js/controls/DeviceOrientationControls.js"></script>
  36. <script>
  37. var container, camera, scene, renderer, controls;
  38. init();
  39. animate();
  40. function init() {
  41. container = document.getElementById( 'container' );
  42. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  43. controls = new THREE.DeviceOrientationControls( camera );
  44. scene = new THREE.Scene();
  45. var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
  46. // invert the geometry on the x-axis so that all of the faces point inward
  47. geometry.scale( - 1, 1, 1 );
  48. var material = new THREE.MeshBasicMaterial( {
  49. map: new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
  50. } );
  51. var mesh = new THREE.Mesh( geometry, material );
  52. scene.add( mesh );
  53. var helperGeometry = new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
  54. var helperMaterial = new THREE.MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
  55. var helper = new THREE.Mesh( helperGeometry, helperMaterial );
  56. scene.add( helper );
  57. //
  58. renderer = new THREE.WebGLRenderer();
  59. renderer.setPixelRatio( window.devicePixelRatio );
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. container.appendChild( renderer.domElement );
  62. //
  63. window.addEventListener( 'resize', onWindowResize, false );
  64. }
  65. function animate() {
  66. window.requestAnimationFrame( animate );
  67. controls.update();
  68. renderer.render( scene, camera );
  69. }
  70. function onWindowResize() {
  71. camera.aspect = window.innerWidth / window.innerHeight;
  72. camera.updateProjectionMatrix();
  73. renderer.setSize( window.innerWidth, window.innerHeight );
  74. }
  75. </script>
  76. </body>
  77. </html>