Using an Orbit Camera for 3D Scene Navigation
CreatiCode last edited by info-creaticode
A 3D scene is an infinitely large virtual world. To view what’s happening inside this world, we need to use a virtual camera. This process is very similar to watching a soccer game on TV: since the stadium is very large, a video camera captures images of the stadium from a particular position, and those images are displayed on our TV.
By default, every scene contains a camera. You can add a new camera at any time to replace the default one. The most commonly used camera type is “orbit camera”, which behaves like a satellite that orbits the Earth. It can rotate horizontally or vertically around the target, or move closer to/away from the target.
Block for Adding a New Orbit Camera
This block accepts the following parameters:
- Distance: the initial distance between the camera and the target point (the center of the world by default). Setting a larger distance will allow the camera to show more objects but with less detail. After the camera is created, you can zoom in/out the camera to change the distance, or shift the target point to a different position.
- V-angle: the initial vertical view angle of the camera, between 0 degrees and 180 degrees. A value of 0 will place the camera directly above the target. Here are some commonly used vertical view angles:
- H-angle: the initial horizontal view angle of the camera, between 0 degrees and 360 degrees. For example, when the h-angle is 0 degrees, the camera will be looking in the forward direction along the Y-axis (into the computer screen).
- Moving Speed ratio: how fast can you manually shift the target point of the camera. 100 means 100% of the default speed. See below for how to shift the target.
- Input with Key or Pointer: whether you can control the camera using the keyboard or the pointer. By default, both options are “Yes”. For example, if you select “No” for the keyboard, then you can no longer move or turn the camera using the keyboard.
- Active: This is an advanced option that controls whether this camera will become the “active camera”. If you choose “Yes”, this new camera will replace the existing active camera, and its view will be displayed on the stage; if you choose “No”, then this camera will be added as an additional camera. Its output will not be displayed until we set a new display region for it. This will be useful when we want to display the content of 2 or more cameras on the stage.
- Name: This is the name of the new camera. It will be useful when we need to select or refer to this camera later.
Program: In this program, we load the castle scene, and after waiting 2 seconds, switch to a new orbit camera that is much further away from the world center.
Rotating the Orbit Camera
You can manually rotate the orbit camera around its target using the mouse pointer or the keyboard. Note that the objects in the scene are not being moved or rotated by you. You are simply changing the camera’s view angle.
- Pointer: You can drag the pointer in the 3D scene window to rotate the camera.
- Keyboard: You can also press the 4 arrow keys ( ) to rotate the camera horizontally or vertically. Note that you will need to click or touch on the scene window first to make sure it is actively capturing your keypress.
Zooming In and Out
You can zoom in by pushing the camera closer to the target, or zoom out by drawing the camera back.
- Pointer: You can use the scroll wheel of your mouse, or pinch 2 fingers narrower or wider to zoom the camera.
- Keyboard: You can also press the W and S keys to zoom the camera. Again, please note that you will need to click or touch on the scene window first to make sure it is actively capturing your keypress.
Panning: Shifting the Target
Lastly, you can pan your camera, which means shifting the target horizontally or vertically. Again, this will not move the objects in the scene, but change the target point and the camera position in parallel.
- Pointer: You can press down the right button of your mouse, or press down 2 fingers on a touch pad and drag them.
- Keyboard: You can also use the keyboard. The A and D keys will shift the camera left or right, and the Q and E keys will shift the camera up or down.