camera_orthographic.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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;
  25. var stats;
  26. var camera;
  27. var scene;
  28. var renderer;
  29. var cube, plane;
  30. var mouseX = 0;
  31. var mouseXOnMouseDown = 0;
  32. var windowHalfX = window.innerWidth / 2;
  33. var windowHalfY = window.innerHeight / 2;
  34. var moveForward = false,
  35. moveBackwards = false,
  36. moveUp = false,
  37. moveDown = false,
  38. moveLeft = false,
  39. moveRight = false,
  40. yawLeft = false,
  41. yawRight = false,
  42. pitchUp = false,
  43. pitchDown = false,
  44. rollLeft = false,
  45. rollRight = false;
  46. init();
  47. setInterval(loop, 1000/60);
  48. function init() {
  49. container = document.createElement('div');
  50. document.body.appendChild(container);
  51. camera = new THREE.Camera( 45, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
  52. camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -2000, 1000 );
  53. camera.position.x = 200;
  54. camera.position.y = 150;
  55. camera.position.z = 200;
  56. scene = new THREE.Scene();
  57. // Plane
  58. plane = new THREE.Mesh( new Plane( 1000, 1000, 20, 20 ), new THREE.MeshColorStrokeMaterial( 0x000000, 0.2 ) );
  59. plane.rotation.x = - 90 * ( Math.PI / 180 );
  60. scene.addObject( plane );
  61. geometry = new Cube( 50, 50, 50 );
  62. for (var i = 0; i < 100; i ++ ) {
  63. cube = new THREE.Mesh(geometry, new THREE.MeshColorFillMaterial( 0xffffff, Math.random() * 0.5 + 0.5 ) );
  64. cube.overdraw = true;
  65. cube.scale.y = Math.floor( Math.random() * 2 + 1 );
  66. cube.position.x = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
  67. cube.position.y = ( cube.scale.y * 50 ) / 2;
  68. cube.position.z = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
  69. scene.addObject(cube);
  70. }
  71. // Lights
  72. var ambientLight = new THREE.AmbientLight( Math.random() * 0x10 );
  73. scene.addLight( ambientLight );
  74. var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
  75. directionalLight.position.x = Math.random() - 0.5;
  76. directionalLight.position.y = Math.random() - 0.5;
  77. directionalLight.position.z = Math.random() - 0.5;
  78. directionalLight.position.normalize();
  79. scene.addLight( directionalLight );
  80. var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
  81. directionalLight.position.x = Math.random() - 0.5;
  82. directionalLight.position.y = Math.random() - 0.5;
  83. directionalLight.position.z = Math.random() - 0.5;
  84. directionalLight.position.normalize();
  85. scene.addLight( directionalLight );
  86. renderer = new THREE.CanvasRenderer();
  87. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  88. container.appendChild( renderer.domElement );
  89. stats = new Stats();
  90. stats.domElement.style.position = 'absolute';
  91. stats.domElement.style.top = '0px';
  92. container.appendChild(stats.domElement);
  93. }
  94. //
  95. function loop() {
  96. var timer = new Date().getTime() * 0.0001;
  97. camera.position.x = Math.cos( timer ) * 200;
  98. camera.position.z = Math.sin( timer ) * 200;
  99. renderer.render(scene, camera);
  100. stats.update();
  101. }
  102. </script>
  103. </body>
  104. </html>