misc_controls_deviceorientation.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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">three.js</a> - equirectangular panorama demo with DeviceOrientation controls.
  31. photo by <a href="http://www.flickr.com/photos/jonragnarsson/2294472375/" target="_blank">Jón Ragnarsson</a>.
  32. </div>
  33. <div id="container"></div>
  34. <script src="../build/three.min.js"></script>
  35. <script src="js/controls/DeviceOrientationControls.js"></script>
  36. <script>
  37. (function() {
  38. "use strict"
  39. var hasWebGL = (function() {
  40. try {
  41. var canvas = document.createElement( 'canvas' );
  42. return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) );
  43. } catch( e ) {
  44. return false;
  45. }
  46. })();
  47. window.addEventListener('load', function() {
  48. var container, camera, scene, renderer, controls, geometry, mesh;
  49. var animate = function(){
  50. controls.update();
  51. renderer.render(scene, camera);
  52. window.requestAnimationFrame(animate);
  53. };
  54. container = document.getElementById( 'container' );
  55. camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
  56. controls = new THREE.DeviceOrientationControls( camera );
  57. scene = new THREE.Scene();
  58. var geometry = new THREE.SphereGeometry( 500, 60, 40 );
  59. geometry.applyMatrix( new THREE.Matrix4().makeScale( -1, 1, 1 ) );
  60. var material = new THREE.MeshBasicMaterial( {
  61. map: THREE.ImageUtils.loadTexture( 'textures/2294472375_24a3b8ef46_o.jpg' )
  62. } );
  63. var mesh = new THREE.Mesh( geometry, material );
  64. mesh.rotation.x = 90 * ( Math.PI / 180 );
  65. scene.add(mesh);
  66. renderer = hasWebGL ? new THREE.WebGLRenderer() : new THREE.CanvasRenderer();
  67. renderer.setSize(window.innerWidth, window.innerHeight);
  68. renderer.domElement.style.position = 'absolute';
  69. renderer.domElement.style.top = 0;
  70. container.appendChild(renderer.domElement);
  71. var resizeWindow = function() {
  72. camera.aspect = window.innerWidth / window.innerHeight;
  73. camera.updateProjectionMatrix();
  74. renderer.setSize( window.innerWidth, window.innerHeight );
  75. };
  76. window.addEventListener('resize', resizeWindow, false);
  77. controls.connect();
  78. animate();
  79. }, false);
  80. })();
  81. </script>
  82. </body>
  83. </html>