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