misc_controls_deviceorientation.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. box-sizing: border-box;
  23. }
  24. a {
  25. color: #ff8800;
  26. }
  27. </style>
  28. </head>
  29. <body>
  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 camera, scene, renderer, controls;
  38. init();
  39. animate();
  40. function init() {
  41. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  42. controls = new THREE.DeviceOrientationControls( camera );
  43. scene = new THREE.Scene();
  44. var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
  45. // invert the geometry on the x-axis so that all of the faces point inward
  46. geometry.scale( - 1, 1, 1 );
  47. var material = new THREE.MeshBasicMaterial( {
  48. map: new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' )
  49. } );
  50. var mesh = new THREE.Mesh( geometry, material );
  51. scene.add( mesh );
  52. var helperGeometry = new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 );
  53. var helperMaterial = new THREE.MeshBasicMaterial( { color: 0xff00ff, wireframe: true } );
  54. var helper = new THREE.Mesh( helperGeometry, helperMaterial );
  55. scene.add( helper );
  56. //
  57. renderer = new THREE.WebGLRenderer( { antialias: true } );
  58. renderer.setPixelRatio( window.devicePixelRatio );
  59. renderer.setSize( window.innerWidth, window.innerHeight );
  60. document.body.appendChild( renderer.domElement );
  61. //
  62. window.addEventListener( 'resize', onWindowResize, false );
  63. }
  64. function animate() {
  65. window.requestAnimationFrame( animate );
  66. controls.update();
  67. renderer.render( scene, camera );
  68. }
  69. function onWindowResize() {
  70. camera.aspect = window.innerWidth / window.innerHeight;
  71. camera.updateProjectionMatrix();
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. }
  74. </script>
  75. </body>
  76. </html>