Jump to content

setInterval


avrudoi
 Share

Recommended Posts

here's the code to insert the timer to tell to all revolved.

<!DOCTYPE html><html lang="en">	<head>		<title>three.js canvas - geometry - cube</title>		<meta charset="utf-8">		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">		<style>			body {				font-family: Monospace;				background-color: #f0f0f0;				margin: 0px;				overflow: hidden;			}		</style>	</head>	<body>		<script src="../build/three.min.js"></script>		<script src="js/libs/stats.min.js"></script>		<script>			var container, stats;			var camera, scene, renderer;			var cube1, cube2, cube3, cube4, cube5, cube6;			var objects = [];			var targetRotation = 0;			var targetRotationOnMouseDown = 0;			var mouseX = 0, mouseY = 0;			var mouseXOnMouseDown = 0;			var windowHalfX = window.innerWidth / 2;			var windowHalfY = window.innerHeight / 2;			var phi=0;			init();			animate();			window.setInterval( vrs(  ),5000);//включаеться только один раз				function init() {				container = document.createElement( 'div' );				document.body.appendChild( container );				var info = document.createElement( 'div' );				info.style.position = 'absolute';				info.style.top = '10px';				info.style.width = '100%';				info.style.textAlign = 'center';				info.innerHTML = 'Drag to spin the cube';				container.appendChild( info );				projector = new THREE.Projector();								camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );				camera.position.y = 150;				camera.position.z = 500;				scene = new THREE.Scene();				// Cube				var geometry = new THREE.CubeGeometry( 150, 200, 1 );				var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, overdraw: 0.5 } );								cube1 = new THREE.Mesh( geometry, material );				cube1.position.y = 0;				cube1.position.x = 0;				cube1.position.z = 0; 								cube2 = new THREE.Mesh( geometry, material );				cube2.position.y = 0;				cube2.position.x = -150;				cube2.position.z = 0;								cube3 = new THREE.Mesh( geometry, material );				cube3.position.y = 0;				cube3.position.x = 150;				cube3.position.z = 0;												scene.add(cube1);				scene.add(cube2);				scene.add(cube3);												renderer = new THREE.CanvasRenderer();				renderer.setSize( window.innerWidth, window.innerHeight );				container.appendChild( renderer.domElement );				stats = new Stats();				stats.domElement.style.position = 'absolute';				stats.domElement.style.top = '0px';				container.appendChild( stats.domElement );				document.addEventListener( 'mousedown', onDocumentMouseDown, 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 onDocumentMouseDown( event ) {				event.preventDefault();				document.addEventListener( 'mousemove', onDocumentMouseMove, false );				document.addEventListener( 'mouseup', onDocumentMouseUp, false );				document.addEventListener( 'mouseout', onDocumentMouseOut, false );				mouseXOnMouseDown = event.clientX - windowHalfX;				targetRotationOnMouseDown = targetRotation;			}					function onDocumentMouseMove( event ) {				mouseX = event.clientX - windowHalfX;				mouseY = event.clientY - windowHalfY				targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;																	if (mouseX>-75 && mouseX<75 && mouseY > 0 && mouseY <200){				cube1.rotation.y += ( targetRotation - cube1.rotation.y ) * 0.05;				}								if (mouseX>-225 && mouseX<-75 && mouseY > 0 && mouseY <200){				cube2.rotation.y += ( targetRotation - cube2.rotation.y ) * 0.05;				}								if (mouseX>75 && mouseX<225 && mouseY > 0 && mouseY <200){				cube3.rotation.y += ( targetRotation - cube3.rotation.y ) * 0.05;				}			}						function onDocumentMouseUp( event ) {				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );											}			function onDocumentMouseOut( event ) {				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );			}			function onDocumentTouchStart( event ) {				if ( event.touches.length === 1 ) {					event.preventDefault();					mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;					targetRotationOnMouseDown = targetRotation;				}			}			function onDocumentTouchMove( event ) {				if ( event.touches.length === 1 ) {					event.preventDefault();					mouseX = event.touches[ 0 ].pageX - windowHalfX;					targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;				}			}			//			function animate() {				requestAnimationFrame( animate );				render();				stats.update();			}			function render() {								renderer.render( scene, camera );							}			window.setInterval( vrs(),200);//включаеться только один раз			function vrs()			{			//alert(1);			cube1.rotation.y += 1;			}					</script>	</body></html>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...