UNPKG

gl2d

Version:

2D graphics package for WebGL

88 lines (87 loc) 3.44 kB
import { Mat4Struct } from '../struct/mat4'; import { PointLike } from '../struct/point'; import { RectStruct } from '../struct/rect'; import { Vec2, Vec2Like, Vec2Struct } from '../struct/vec2'; /** * Defines an orthographic projection from target space to clip space. */ export declare class Camera { /** * The area this camera is targeting. */ target: RectStruct; /** * The area of the target that is currently in view. */ view: RectStruct; /** * The orthographic projection matrix that puts the target in view. */ matrix: Mat4Struct; /** * The current position of the camera in relation to the center of the target. */ position: Vec2Struct; /** * The current zoom setting for this camera. */ zoom: number; /** * The minimum zoom setting for this camera. */ minZoom: number; /** * The maximum zoom setting for this camera. */ maxZoom: number; /** * Creates a camera restricted to the specified target area, and by the min/max zoom values. * @param target the area this camera is targeting. * @param minZoom the minimum zoom for the camera. * @param maxZoom the maximum zoom for the camera. */ constructor(target: RectStruct, minZoom: number, maxZoom: number); /** * Sets the size of the viewport in which the camera image will be displayed. * The resulting image will be centered inside the viewport and will match the aspect of the camera's target. * @param vw the new width of the viewport. * @param vh the new height of the viewport. */ setViewport(vw: number, vh: number): void; /** * Sends a request to offset this camera by the desired vector. * Note: the desired offset may be adjusted to keep the camera from viewing anything outside of the target area. * @param desiredOffset the desired offset. * @returns the actual offset. */ offset(desiredOffset: Vec2Like): Vec2; /** * Sends a request to zoom in this camera by the desired scale factor. * Note: the desired scale factor is automatically adjusted to keep the camera from viewing anything outside of the target area. * @param desiredScaleFactor the desired scale factor. * @returns the actual scale factor. */ zoomIn(desiredScaleFactor: number): number; /** * Sends a request to zoom out this camera by the desired scale factor. * Note: the desired scale factor is automatically adjusted to keep the camera from viewing anything outside of the target area. * @param desired the desired scale factor. * @returns the actual scale factor. */ zoomOut(desiredScaleFactor: number): number; /** * Sends a request to zoom this camera by the desired scale factor. * Note: the desired scale factor is automatically adjusted to keep the camera from viewing anything outside of the target area. * @param desired the desired scale factor. * @param focus the focus point. * @returns the actual scale factor and offset. */ zoomToPoint(desiredScaleFactor: number, focus: PointLike): { scaleFactor: number; offset: Vec2; }; /** * Recalculates the projection matrix to reflect changes in the camera settings. */ updateMatrix(): void; }