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.