camera_orthographic.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - camera - orthographic</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
  7. <style type="text/css">
  8. body {
  9. font-family: Monospace;
  10. background-color: #f0f0f0;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script type="text/javascript" src="../build/Three.js"></script>
  18. <script type="text/javascript" src="geometry/primitives/Cube.js"></script>
  19. <script type="text/javascript" src="geometry/primitives/Plane.js"></script>
  20. <script type="text/javascript" src="js/Stats.js"></script>
  21. <script type="text/javascript">
  22. var container, stats;
  23. var camera, scene, renderer;
  24. init();
  25. setInterval( loop, 1000 / 60 );
  26. function init() {
  27. container = document.createElement('div');
  28. document.body.appendChild(container);
  29. camera = new THREE.Camera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
  30. camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -2000, 1000 );
  31. camera.position.x = 200;
  32. camera.position.y = 100;
  33. camera.position.z = 200;
  34. scene = new THREE.Scene();
  35. // Grid
  36. var geometry = new THREE.Geometry();
  37. geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( - 500, 0, 0 ) ) );
  38. geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( 500, 0, 0 ) ) );
  39. for ( var i = 0; i <= 20; i ++ ) {
  40. var line = new THREE.Line( geometry, new THREE.LineColorMaterial( 0x000000, 0.2 ) );
  41. line.position.z = ( i * 50 ) - 500;
  42. scene.addObject( line );
  43. var line = new THREE.Line( geometry, new THREE.LineColorMaterial( 0x000000, 0.2 ) );
  44. line.position.x = ( i * 50 ) - 500;
  45. line.rotation.y = 90 * Math.PI / 180;
  46. scene.addObject( line );
  47. }
  48. // Cubes
  49. var geometry = new Cube( 50, 50, 50 );
  50. for ( var i = 0; i < 100; i ++ ) {
  51. var cube = new THREE.Mesh( geometry, new THREE.MeshColorFillMaterial( 0xffffff, Math.random() * 0.5 + 0.5 ) );
  52. cube.overdraw = true;
  53. cube.scale.y = Math.floor( Math.random() * 2 + 1 );
  54. cube.position.x = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
  55. cube.position.y = ( cube.scale.y * 50 ) / 2;
  56. cube.position.z = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
  57. scene.addObject(cube);
  58. }
  59. // Lights
  60. var ambientLight = new THREE.AmbientLight( Math.random() * 0x10 );
  61. scene.addLight( ambientLight );
  62. var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
  63. directionalLight.position.x = Math.random() - 0.5;
  64. directionalLight.position.y = Math.random() - 0.5;
  65. directionalLight.position.z = Math.random() - 0.5;
  66. directionalLight.position.normalize();
  67. scene.addLight( directionalLight );
  68. var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
  69. directionalLight.position.x = Math.random() - 0.5;
  70. directionalLight.position.y = Math.random() - 0.5;
  71. directionalLight.position.z = Math.random() - 0.5;
  72. directionalLight.position.normalize();
  73. scene.addLight( directionalLight );
  74. renderer = new THREE.CanvasRenderer();
  75. renderer.setSize( window.innerWidth, window.innerHeight );
  76. container.appendChild( renderer.domElement );
  77. stats = new Stats();
  78. stats.domElement.style.position = 'absolute';
  79. stats.domElement.style.top = '0px';
  80. container.appendChild(stats.domElement);
  81. }
  82. function loop() {
  83. var timer = new Date().getTime() * 0.0001;
  84. camera.position.x = Math.cos( timer ) * 200;
  85. camera.position.z = Math.sin( timer ) * 200;
  86. renderer.render(scene, camera);
  87. stats.update();
  88. }
  89. </script>
  90. </body>
  91. </html>