Lesson goal: 3d graphics and the camera

Previous: Depth with 3D graphics | Home | Next: 3D graphics and the light source

In the last lesson you saw how 3d graphics gives you depth and perspective along the z-axis. Here's another cool aspect about 3d graphics: the camera.

That's right...with such graphics, you get to set the camera position, about which your 3d-scene is rendered. Just as an actual photo taken with an actual camera will look different depending on how the camera is aimed, so too will your 3d-scene depending on where your 3d-graphics camera is aimed.

When you call scene3d(), we default the camera position to (x=0,y=0,z=100), but with the camera() function shown here, you can set the camera to any position you wish, and see how it affects your scene.

camera(x,y,z)
Move the mouse over a dotted box for more information.

Let's again use scene3d() and sphere() to draw some spheres, but let's now move the camera around and see how things look in response.

First, try moving the camera up and back:

  1. Move the camera to (0,0,500)
  2. Now to (0,0,50)

What do you notice? Now try moving it left and right

  1. Move the camera to (20,0,100)
  2. Now to (-20,0,100)

Now try moving it up and down

  1. Move the camera to (0,20,100)
  2. Now to (0,-20,100)

Now you try. Try moving the camera around and seeing how it affects your scene.

Type your code here:


See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.