| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <title>three.js - camera - orthographic</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
- <style type="text/css">
- body {
- font-family: Monospace;
- background-color: #f0f0f0;
- margin: 0px;
- overflow: hidden;
- }
- </style>
- </head>
- <body>
- <script type="text/javascript" src="../build/Three.js"></script>
- <script type="text/javascript" src="geometry/primitives/Cube.js"></script>
- <script type="text/javascript" src="geometry/primitives/Plane.js"></script>
- <script type="text/javascript" src="js/Stats.js"></script>
- <script type="text/javascript">
- var SCREEN_WIDTH = window.innerWidth;
- var SCREEN_HEIGHT = window.innerHeight;
- var container;
- var stats;
- var camera;
- var scene;
- var renderer;
- var cube, plane;
- var mouseX = 0;
- var mouseXOnMouseDown = 0;
- var windowHalfX = window.innerWidth / 2;
- var windowHalfY = window.innerHeight / 2;
- var moveForward = false,
- moveBackwards = false,
- moveUp = false,
- moveDown = false,
- moveLeft = false,
- moveRight = false,
- yawLeft = false,
- yawRight = false,
- pitchUp = false,
- pitchDown = false,
- rollLeft = false,
- rollRight = false;
- init();
- setInterval(loop, 1000/60);
- function init() {
- container = document.createElement('div');
- document.body.appendChild(container);
- camera = new THREE.Camera( 45, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
- camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -2000, 1000 );
- camera.position.x = 200;
- camera.position.y = 150;
- camera.position.z = 200;
- scene = new THREE.Scene();
- // Plane
- plane = new THREE.Mesh( new Plane( 1000, 1000, 20, 20 ), new THREE.MeshColorStrokeMaterial( 0x000000, 0.2 ) );
- plane.rotation.x = - 90 * ( Math.PI / 180 );
- scene.addObject( plane );
- geometry = new Cube( 50, 50, 50 );
- for (var i = 0; i < 100; i ++ ) {
- cube = new THREE.Mesh(geometry, new THREE.MeshColorFillMaterial( 0xffffff, Math.random() * 0.5 + 0.5 ) );
- cube.overdraw = true;
- cube.scale.y = Math.floor( Math.random() * 2 + 1 );
- cube.position.x = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
- cube.position.y = ( cube.scale.y * 50 ) / 2;
- cube.position.z = Math.floor( ( Math.random() * 1000 - 500 ) / 50 ) * 50 + 25;
- scene.addObject(cube);
- }
- // Lights
- var ambientLight = new THREE.AmbientLight( Math.random() * 0x10 );
- scene.addLight( ambientLight );
- var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
- directionalLight.position.x = Math.random() - 0.5;
- directionalLight.position.y = Math.random() - 0.5;
- directionalLight.position.z = Math.random() - 0.5;
- directionalLight.position.normalize();
- scene.addLight( directionalLight );
- var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
- directionalLight.position.x = Math.random() - 0.5;
- directionalLight.position.y = Math.random() - 0.5;
- directionalLight.position.z = Math.random() - 0.5;
- directionalLight.position.normalize();
- scene.addLight( directionalLight );
- renderer = new THREE.CanvasRenderer();
- renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
- container.appendChild( renderer.domElement );
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.top = '0px';
- container.appendChild(stats.domElement);
- }
- //
- function loop() {
- var timer = new Date().getTime() * 0.0001;
- camera.position.x = Math.cos( timer ) * 200;
- camera.position.z = Math.sin( timer ) * 200;
- renderer.render(scene, camera);
- stats.update();
- }
- </script>
- </body>
- </html>
|