Animating the Shapes

Before we finish our first programming session, let’s do something cool. Let’s make all of our shapes spin around like crazy.

In 3DE, add the following code after all of the shapes:

​ ​var​ clock = ​new​ THREE.Clock();
​ 
​ ​function​ animate() {
​  requestAnimationFrame(animate);
​  ​var​ t = clock.getElapsedTime();
​ 
​  ball.rotation.​set​(t, 2*t, 0);
​  box.rotation.​set​(t, 2*t, 0);
​  tube.rotation.​set​(t, 2*t, 0);
​  ground.rotation.​set​(t, 2*t, 0);
​  donut.rotation.​set​(t, 2*t, 0);
​ 
​  renderer.render(scene, camera);
​ }
​ 
​ animate();

Don’t worry about what everything means in that code. For now, it’s enough to know that at specific ...

Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.