misc_camera_roll.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/Stats.js"></script>
  35. <script>
  36. var statsEnabled = true;
  37. var container, stats;
  38. var camera, scene, renderer;
  39. var cross;
  40. init();
  41. function init() {
  42. // scene and camera
  43. scene = new THREE.Scene();
  44. scene.fog = new THREE.FogExp2( 0xffffff, 0.002 );
  45. camera = new THREE.RollCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  46. camera.movementSpeed = 100;
  47. camera.lookSpeed = 3;
  48. camera.constrainVertical = [ -0.5, 0.5 ];
  49. //camera.autoForward = true;
  50. // world
  51. var cube = new THREE.CubeGeometry( 20, 60, 20 );
  52. cube.vertices[ 0 ].position.multiplyScalar( 0.01 );
  53. cube.vertices[ 1 ].position.multiplyScalar( 0.01 );
  54. cube.vertices[ 4 ].position.multiplyScalar( 0.01 );
  55. cube.vertices[ 5 ].position.multiplyScalar( 0.01 );
  56. var material = new THREE.MeshLambertMaterial( { color:0xffffff } );
  57. for( var i = 0; i < 500; i++ ) {
  58. var mesh = new THREE.Mesh( cube, material );
  59. mesh.position.set(( Math.random() - 0.5 ) * 1000,
  60. ( Math.random() - 0.5 ) * 1000,
  61. ( Math.random() - 0.5 ) * 1000 );
  62. mesh.updateMatrix();
  63. mesh.matrixAutoUpdate = false;
  64. scene.add( mesh );
  65. }
  66. // create cross
  67. /*
  68. cross = new THREE.Object3D();
  69. cross.scale.set( 0.5, 0.5, 0.5 );
  70. cross.matrixAutoUpdate = false;
  71. var material = new THREE.MeshPhongMaterial( { color:0xff0000 } );
  72. var mesh = new THREE.Mesh( new THREE.Cube( 40, 5, 5 ), material );
  73. mesh.position.x = 20;
  74. cross.add( mesh );
  75. var material = new THREE.MeshPhongMaterial( { color:0x00ff00 } );
  76. var mesh = new THREE.Mesh( new THREE.Cube( 5, 40, 5 ), material );
  77. mesh.position.y = 20;
  78. cross.add( mesh );
  79. var material = new THREE.MeshPhongMaterial( { color:0x0000ff } );
  80. var mesh = new THREE.Mesh( new THREE.Cube( 5, 5, 40 ), material );
  81. mesh.position.z = 20;
  82. cross.add( mesh );
  83. camera.add( cross );
  84. */
  85. scene.add( camera );
  86. // lights
  87. light = new THREE.DirectionalLight( 0xffffff );
  88. light.position.set( 1, 1, 1 );
  89. scene.add( light );
  90. light = new THREE.DirectionalLight( 0x002288 );
  91. light.position.set( -1, -1, -1 );
  92. scene.add( light );
  93. light = new THREE.AmbientLight( 0x222222 );
  94. scene.add( light );
  95. // renderer
  96. renderer = new THREE.WebGLRenderer( { antialias: false } );
  97. renderer.setClearColorHex( 0xffffff, 1 );
  98. renderer.setSize( window.innerWidth, window.innerHeight );
  99. container = document.getElementById( 'container' );
  100. container.appendChild( renderer.domElement );
  101. if ( statsEnabled ) {
  102. stats = new Stats();
  103. stats.domElement.style.position = 'absolute';
  104. stats.domElement.style.top = '0px';
  105. stats.domElement.style.zIndex = 100;
  106. container.appendChild( stats.domElement );
  107. }
  108. setInterval( loop, 1000 / 60 );
  109. }
  110. function loop() {
  111. /*
  112. cross.matrix.copy( camera.matrix );
  113. cross.matrix.n14 = 0;
  114. cross.matrix.n24 = 0;
  115. cross.matrix.n34 = -200;
  116. cross.matrixWorldNeedsUpdate = true;
  117. */
  118. renderer.render( scene, camera );
  119. if ( statsEnabled ) stats.update();
  120. }
  121. </script>
  122. </body>
  123. </html>