misc_camera_roll.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - roll camera</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. color: #000;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. font-weight: bold;
  14. background-color: #fff;
  15. margin: 0px;
  16. overflow: hidden;
  17. }
  18. #info {
  19. color:#000;
  20. position: absolute;
  21. top: 0px; width: 100%;
  22. padding: 5px;
  23. }
  24. a { color: red; }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="container"></div>
  29. <div id="info">
  30. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - roll camera example</br>
  31. WASD move, RF up/down, QE roll, mouse look around
  32. </div>
  33. <script src="../build/Three.js"></script>
  34. <script src="js/Detector.js"></script>
  35. <script src="js/Stats.js"></script>
  36. <script>
  37. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  38. var container, stats;
  39. var camera, controls, scene, renderer;
  40. var cross;
  41. var clock = new THREE.Clock();
  42. init();
  43. animate();
  44. function init() {
  45. // scene and camera
  46. scene = new THREE.Scene();
  47. scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
  48. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  49. controls = new THREE.RollControls( camera );
  50. controls.movementSpeed = 100;
  51. controls.lookSpeed = 3;
  52. controls.constrainVertical = [ -0.5, 0.5 ];
  53. //controls.autoForward = true;
  54. // world
  55. var geometry = new THREE.CylinderGeometry( 0, 10, 30, 4, 1 );
  56. var material = new THREE.MeshLambertMaterial( { color:0xffffff, shading: THREE.FlatShading } );
  57. for ( var i = 0; i < 500; i ++ ) {
  58. var mesh = new THREE.Mesh( geometry, material );
  59. mesh.position.x = ( Math.random() - 0.5 ) * 1000;
  60. mesh.position.y = ( Math.random() - 0.5 ) * 1000;
  61. mesh.position.z = ( Math.random() - 0.5 ) * 1000;
  62. mesh.updateMatrix();
  63. mesh.matrixAutoUpdate = false;
  64. scene.add( mesh );
  65. }
  66. scene.add( camera );
  67. // lights
  68. light = new THREE.DirectionalLight( 0xffffff );
  69. light.position.set( 1, 1, 1 );
  70. scene.add( light );
  71. light = new THREE.DirectionalLight( 0x002288 );
  72. light.position.set( -1, -1, -1 );
  73. scene.add( light );
  74. light = new THREE.AmbientLight( 0x555555 );
  75. scene.add( light );
  76. // renderer
  77. renderer = new THREE.WebGLRenderer( { antialias: false } );
  78. renderer.setClearColor( scene.fog.color, 1 );
  79. renderer.setSize( window.innerWidth, window.innerHeight );
  80. container = document.getElementById( 'container' );
  81. container.appendChild( renderer.domElement );
  82. stats = new Stats();
  83. stats.domElement.style.position = 'absolute';
  84. stats.domElement.style.top = '0px';
  85. stats.domElement.style.zIndex = 100;
  86. container.appendChild( stats.domElement );
  87. //
  88. window.addEventListener( 'resize', onWindowResize, false );
  89. }
  90. function onWindowResize() {
  91. camera.aspect = window.innerWidth / window.innerHeight;
  92. camera.updateProjectionMatrix();
  93. renderer.setSize( window.innerWidth, window.innerHeight );
  94. controls.handleResize();
  95. }
  96. function animate() {
  97. requestAnimationFrame( animate );
  98. render();
  99. stats.update();
  100. }
  101. function render() {
  102. controls.update( clock.getDelta() );
  103. renderer.render( scene, camera );
  104. }
  105. </script>
  106. </body>
  107. </html>