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.
- Distance: the initial distance between the camera and the target point (the center of the world). Setting a larger distance will allow the camera to capture 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 (into the computer screen).
- Panning 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.
When running this block, the existing camera in the 3D scene will be removed, and a new orbit camera will be added at the given distance and angles.
When you change the size of the 3D scene window, the camera’s resolution will be adjusted accordingly.
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.
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.
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.
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.