Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="js/three.min.js"></script>
- <script src="js/Projector.js"></script>
- <script src="js/CanvasRenderer.js"></script>
- <script>
- var SCREEN_WIDTH = window.innerWidth,
- SCREEN_HEIGHT = window.innerHeight,
- mouseX = 0, mouseY = 0,
- windowHalfX = window.innerWidth / 2,
- windowHalfY = window.innerHeight / 2,
- camera, scene, renderer;
- init();
- animate();
- function init() {
- container = document.createElement('div');
- document.body.appendChild(container);
- camera = new THREE.PerspectiveCamera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
- camera.position.z = 1000;
- scene = new THREE.Scene();
- renderer = new THREE.CanvasRenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
- container.appendChild( renderer.domElement );
- var loader = new THREE.JSONLoader();
- loader.load( 'js/Neuron.json', );
- document.addEventListener( 'mousemove', onDocumentMouseMove, false );
- document.addEventListener( 'touchstart', onDocumentTouchStart, false );
- document.addEventListener( 'touchmove', onDocumentTouchMove, false );
- //
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- windowHalfX = window.innerWidth / 2;
- windowHalfY = window.innerHeight / 2;
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- //
- function onDocumentMouseMove(event) {
- mouseX = event.clientX - windowHalfX;
- mouseY = event.clientY - windowHalfY;
- }
- function onDocumentTouchStart( event ) {
- if ( event.touches.length > 1 ) {
- event.preventDefault();
- mouseX = event.touches[ 0 ].pageX - windowHalfX;
- mouseY = event.touches[ 0 ].pageY - windowHalfY;
- }
- }
- function onDocumentTouchMove( event ) {
- if ( event.touches.length == 1 ) {
- event.preventDefault();
- mouseX = event.touches[ 0 ].pageX - windowHalfX;
- mouseY = event.touches[ 0 ].pageY - windowHalfY;
- }
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- }
- function render() {
- camera.position.x += ( mouseX - camera.position.x ) * .05;
- camera.position.y += ( - mouseY + 200 - camera.position.y ) * .05;
- camera.lookAt( scene.position );
- renderer.render( scene, camera );
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement