Viewport and Camera
The viewport or viewport-webgl modules supply an easy way of creating a viewport area and managing the camera controls.
The Viewport
The viewport is the visual area that shows the configurable 3d model. In general a viewport is a box on the web page that has a pixel width and height and that displays the image that is seen by the virtual camera. Setting up the viewport is described in the minimal example section.
The Camera
The camera is the virtual device that is used to see the object. The image of the camera is displayed inside the viewport. The position and orientation of the camera is defined by a set of geometric parameters:
Element | Type | Description |
focus | 3-vector | This marks the central position of the virtual lens of the camera. It is the point where all geometric light rays of the final image are bundled and it is therefore the "real" position of the camera. |
view | 3-vector | Describes the direction the camera looks into. |
top | 3-vector | Describes the direction to the top of the camera. |
right | 3-vector | Describes the direction to the right of the camera. |
aperture | float | This is the angle of view of the camera in either horizontal or vertical direction, measured in degrees. It's in horizontal direction if the viewport's pixel width is smaller than its height and in vertical direction otherwise. |
origin | 3-vector | Defines the center of rotation the camera moves around when orbiting. This point typically lies within or close to the object examined by the camera. |
The view, top and right vectors are orthogonal on each other.
Camera Movement Modes
The camera can perform a number of movements that are explained in the following sections.
Movement Controls Table
Movement mode | Mouse Mode Controls | Touch Mode Controls |
Orbiting | left mouse button | one finger | |
Dollying | mouse wheel | two fingers (pinch and spread) | |
Rolling | - | two fingers (rolling) |
Shifting | right mouse button | - | |
Panning | [control] + left mouse button | - | |
Zooming | [control] + mouse wheel | - |
Orbiting
This camera movement typically appears in a configurator setup where the user examines a model by turning it into various directions (left/right, up/down). This turning corresponds to an orbiting of the camera around the object, if this is imagined to be fixed in space. In fact the camera orbits around the point defined as vector origin in the camera parameters. In paramate, the orbit mode is applied by clicking with the left mouse button and moving the mouse cursor (mouse mode) or by touching with one finger and moving it along the touch surface (touch mode).
The orbit mode itself can come in different versions that define how the camera moves around the object:
- turn-and-flip mode
- turntable mode
- turntable mode (with overturning)
Dollying
Shifting
Panning
Zooming
Automatic Camera Positioning
The automatic camera positioning mechanism is an easy way to ensure that the configured object is properly placed within the camera's view. If this mode is active, the 3d object will always be visible in the center of the viewport and will fit well into it, even if an arbitrary rotation is applied.