camera_orthographic.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 SCREEN_WIDTH = window.innerWidth;
  23. var SCREEN_HEIGHT = window.innerHeight;
  24. var container, stats;
  25. var camera, scene, renderer;
  26. init();
  27. setInterval( loop, 1000 / 60 );
  28. function init() {
  29. container = document.createElement('div');
  30. document.body.appendChild(container);
  31. camera = new THREE.Camera( 45, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
  32. camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -2000, 1000 );
  33. camera.position.x = 200;
  34. camera.position.y = 100;
  35. camera.position.z = 200;
  36. scene = new THREE.Scene();
  37. // Grid
  38. var geometry = new THREE.Geometry();
  39. geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( - 500, 0, 0 ) ) );
  40. geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( 500, 0, 0 ) ) );
  41. for ( var i = 0; i <= 20; i ++ ) {
  42. var line = new THREE.Line( geometry, new THREE.LineColorMaterial( 0x000000, 0.2 ) );
  43. line.position.z = ( i * 50 ) - 500;
  44. scene.addObject( line );
  45. var line = new THREE.Line( geometry, new THREE.LineColorMaterial( 0x000000, 0.2 ) );
  46. line.position.x = ( i * 50 ) - 500;
  47. line.rotation.y = 90 * Math.PI / 180;
  48. scene.addObject( line );
  49. }
  50. // Cubes
  51. var geometry = new Cube( 50, 50, 50 );
  52. for ( var i = 0; i < 100; i ++ ) {
  53. var cube = new THREE.Mesh( geometry, new THREE.MeshColorFillMaterial( 0xffffff, Math.random() * 0.5 + 0.5 ) );
  54. cube.overdraw = true;
  55. cube.scale.y = Math.floor( Math.random() * 2 + 1 );
  56. cube.position.x = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
  57. cube.position.y = ( cube.scale.y * 50 ) / 2;
  58. cube.position.z = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
  59. scene.addObject(cube);
  60. }
  61. // Lights
  62. var ambientLight = new THREE.AmbientLight( Math.random() * 0x10 );
  63. scene.addLight( ambientLight );
  64. var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
  65. directionalLight.position.x = Math.random() - 0.5;
  66. directionalLight.position.y = Math.random() - 0.5;
  67. directionalLight.position.z = Math.random() - 0.5;
  68. directionalLight.position.normalize();
  69. scene.addLight( directionalLight );
  70. var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
  71. directionalLight.position.x = Math.random() - 0.5;
  72. directionalLight.position.y = Math.random() - 0.5;
  73. directionalLight.position.z = Math.random() - 0.5;
  74. directionalLight.position.normalize();
  75. scene.addLight( directionalLight );
  76. renderer = new THREE.CanvasRenderer();
  77. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  78. container.appendChild( renderer.domElement );
  79. stats = new Stats();
  80. stats.domElement.style.position = 'absolute';
  81. stats.domElement.style.top = '0px';
  82. container.appendChild(stats.domElement);
  83. }
  84. function loop() {
  85. var timer = new Date().getTime() * 0.0001;
  86. camera.position.x = Math.cos( timer ) * 200;
  87. camera.position.z = Math.sin( timer ) * 200;
  88. renderer.render(scene, camera);
  89. stats.update();
  90. }
  91. </script>
  92. </body>
  93. </html>