Documentation ¶
Overview ¶
Package camera contains virtual cameras and associated controls.
Index ¶
- Constants
- type Axis
- type Camera
- func (c *Camera) Aspect() float32
- func (c *Camera) Axis() Axis
- func (c *Camera) Far() float32
- func (c *Camera) Fov() float32
- func (c *Camera) Near() float32
- func (c *Camera) ProjMatrix(m *math32.Matrix4)
- func (c *Camera) Project(v *math32.Vector3) *math32.Vector3
- func (c *Camera) Projection() Projection
- func (c *Camera) SetAspect(aspect float32)
- func (c *Camera) SetAxis(axis Axis)
- func (c *Camera) SetFar(far float32)
- func (c *Camera) SetFov(fov float32)
- func (c *Camera) SetNear(near float32)
- func (c *Camera) SetProjection(proj Projection)
- func (c *Camera) SetSize(size float32)
- func (c *Camera) Size() float32
- func (c *Camera) Unproject(v *math32.Vector3) *math32.Vector3
- func (c *Camera) UpdateFov(targetDist float32)
- func (c *Camera) UpdateSize(targetDist float32)
- func (c *Camera) ViewMatrix(m *math32.Matrix4)
- type FlyControl
- func (fc *FlyControl) Dispose()
- func (fc *FlyControl) Forward(delta float32)
- func (fc *FlyControl) GetDirections() (forward, up math32.Vector3)
- func (fc *FlyControl) GetMouseSensitivity() float32
- func (fc *FlyControl) GetPosition() (position math32.Vector3)
- func (fc *FlyControl) GetRotation() (rotation math32.Vector3)
- func (fc *FlyControl) IsUsingWorldUp() bool
- func (fc *FlyControl) Pitch(delta float32)
- func (fc *FlyControl) Reorient(target, worldUp *math32.Vector3)
- func (fc *FlyControl) Reposition(position *math32.Vector3)
- func (fc *FlyControl) Right(delta float32)
- func (fc *FlyControl) Roll(delta float32)
- func (fc *FlyControl) ScaleZoom(fovScale float32)
- func (fc *FlyControl) SetMouseIsCaptured(captured bool)
- func (fc *FlyControl) SetMouseSensitivity(value float32)
- func (fc *FlyControl) Subscribe(key, mouse bool)
- func (fc *FlyControl) Unsubscribe(key, mouse bool)
- func (fc *FlyControl) Up(delta float32)
- func (fc *FlyControl) UseWorldUp(use bool)
- func (fc *FlyControl) Yaw(delta float32)
- func (fc *FlyControl) Zoom(delta float32)
- type FlyControlOption
- func FPSStyle() FlyControlOption
- func FlightSimStyle() FlyControlOption
- func WithConstraints(constraints map[FlyMovement]float32) FlyControlOption
- func WithKeys(keys map[FlyMovement]window.Key) FlyControlOption
- func WithMouse(mouse map[FlyMovement]MouseGuesture) FlyControlOption
- func WithSpeeds(speeds map[FlyMovement]float32) FlyControlOption
- type FlyMovement
- type ICamera
- type MouseGuesture
- type MouseMotion
- type OrbitControl
- func (oc *OrbitControl) Dispose()
- func (oc *OrbitControl) Enabled() OrbitEnabled
- func (oc *OrbitControl) Pan(deltaX, deltaY float32)
- func (oc *OrbitControl) Reset()
- func (oc *OrbitControl) Rotate(thetaDelta, phiDelta float32)
- func (oc *OrbitControl) SetEnabled(bitmask OrbitEnabled)
- func (oc *OrbitControl) SetTarget(v math32.Vector3)
- func (oc *OrbitControl) Target() math32.Vector3
- func (oc *OrbitControl) Zoom(delta float32)
- type OrbitEnabled
- type Projection
Constants ¶
const ( Vertical = Axis(iota) Horizontal )
The two possible camera axes.
const ( Perspective = Projection(iota) Orthographic )
The possible camera projections.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Camera ¶
Camera represents a virtual camera, which specifies how to project a 3D scene onto an image.
func New ¶ added in v0.3.2
New creates and returns a new perspective camera with the specified aspect ratio and default parameters.
func NewOrthographic ¶
NewOrthographic creates and returns a new orthographic camera with the specified parameters.
func NewPerspective ¶
NewPerspective creates and returns a new perspective camera with the specified parameters.
func (*Camera) Axis ¶ added in v0.3.2
Axis returns the reference axis associated with the camera size/fov.
func (*Camera) Fov ¶ added in v0.3.2
Fov returns the perspective field-of-view in degrees along the reference axis.
func (*Camera) ProjMatrix ¶ added in v0.3.2
ProjMatrix returns the projection matrix of the camera.
func (*Camera) Project ¶
Project transforms the specified position from world coordinates to this camera projected coordinates.
func (*Camera) Projection ¶ added in v0.3.2
func (c *Camera) Projection() Projection
Projection returns the projection method used by the camera.
func (*Camera) SetAxis ¶ added in v0.3.2
SetAxis sets the reference axis associated with the camera size/fov.
func (*Camera) SetFov ¶ added in v0.3.2
SetFov sets the perspective field-of-view in degrees along the reference axis.
func (*Camera) SetProjection ¶ added in v0.3.2
func (c *Camera) SetProjection(proj Projection)
SetProjection sets the projection method used by the camera.
func (*Camera) SetSize ¶ added in v0.3.2
SetSize sets the orthographic view size along the camera's reference axis.
func (*Camera) Size ¶ added in v0.3.2
Size returns the orthographic view size along the camera's reference axis.
func (*Camera) Unproject ¶
Unproject transforms the specified position from camera projected coordinates to world coordinates.
func (*Camera) UpdateFov ¶ added in v0.3.2
UpdateFov updates the field-of-view such that the frustum matches the orthographic size at the depth specified by targetDist.
func (*Camera) UpdateSize ¶ added in v0.3.2
UpdateSize updates the orthographic size to match the current field-of-view frustum at the depth specified by targetDist.
func (*Camera) ViewMatrix ¶
ViewMatrix returns the view matrix of the camera.
type FlyControl ¶ added in v0.3.4
type FlyControl struct { core.Dispatcher // Embedded event dispatcher // Constraints map. // Specifies the maxium cumulative value in a particular movement. // Translation movements aren't used. // Angular rotation contraints are in radians. Constraints map[FlyMovement]float32 // Speeds map. // Translation movements in units/event. // Angular rotation and zoom in radians/event. Speeds map[FlyMovement]float32 // Keys map. // Maps a movment to a key press. Keys map[FlyMovement]window.Key // Mouse map. // Maps a movement to a mouse "guesture" // (a combination of mouse movement and optional mouse button). Mouse map[FlyMovement]MouseGuesture // contains filtered or unexported fields }
FlyControl provides a camera controller that allows looking at the scene from a first person style view. It allows for translation in the Forward/Backward, Right/Left, and Up/Down directions, and rotation in the Yaw/Pitch/Roll directions from the camera's point of view. The camera's field of view can also be modified to allow ZoomOut/ZoomIn.
For maximum flexibility, the FlyControl is very configurable, but two main modes of operation exist: "manual" and "automatic".
"Manual" mode requires the user to directly make adjustments to the FlyControl's position and orientation by using the Forward(), Right(), Yaw(), Pitch() and other similar methods. Manual mode does not subscribe to key or mouse events, nor does it use the FlyControl's member maps "Speeds", "Keys", or "Mouse" ("Constraints" is used). A FlyControl created (eg with NewFlyControl()) with no options defaults to "manual" mode.
"Automatic" mode subscribes to key and mouse events, and handles position and orientation adjustments according to parameters specified in the "Keys", "Mouse", "Speed", and "Constraint" maps. Generally, methods such as Forward() will not be used. Some preconfigured options are available with FPSStyle() and FlightSimStyle(), and can be further configured by the With*() options, and by modifying the FlyControl's Keys (etc) maps directly.
func NewFlyControl ¶ added in v0.3.4
func NewFlyControl(cam *Camera, target, worldUp *math32.Vector3, options ...FlyControlOption) *FlyControl
NewFlyControl initalizes a FlyControl to manipulate cam. It starts positioned at the cam's position, and oriented looking at target with camera's up aligned in the direction of worldUp. Configuration options can be provided. The FlyControl will default to "manual" mode if no options are given. See documentation for FlyControl for more information about common usage patterns.
func (*FlyControl) Dispose ¶ added in v0.3.4
func (fc *FlyControl) Dispose()
Dispose unsubscribes from all events.
func (*FlyControl) Forward ¶ added in v0.3.4
func (fc *FlyControl) Forward(delta float32)
Forward and backward translation along the camera's forward axis.
func (*FlyControl) GetDirections ¶ added in v0.3.4
func (fc *FlyControl) GetDirections() (forward, up math32.Vector3)
GetDirections returns copies of the camera's current "forward" and "up" direction. The up direction is from the camera's perspective regardless of the status of IsUsingWorldUp().
func (*FlyControl) GetMouseSensitivity ¶ added in v0.3.4
func (fc *FlyControl) GetMouseSensitivity() float32
GetMouseSensitivity gets the current mouse sensitivity in [0,1].
func (*FlyControl) GetPosition ¶ added in v0.3.4
func (fc *FlyControl) GetPosition() (position math32.Vector3)
GetPosition returns a copy of the camera's position.
func (*FlyControl) GetRotation ¶ added in v0.3.4
func (fc *FlyControl) GetRotation() (rotation math32.Vector3)
GetRotation returns a copy of the camera's cumulative rotation. Yaw, Pitch, and Roll are in the X, Y, and Z coordinates.
func (*FlyControl) IsUsingWorldUp ¶ added in v0.3.4
func (fc *FlyControl) IsUsingWorldUp() bool
IsUsingWorldUp returns true if the "up" direction used for movement and rotation is the world up, and false if it is the camera up.
func (*FlyControl) Pitch ¶ added in v0.3.4
func (fc *FlyControl) Pitch(delta float32)
Pitch adjustment in radians. Pitch rotates the camera about its right axis.
Caution: If using world up, take care not to allow the camera's forward direction to become parallel to the world up direction by setting constraints on PitchUp and PitchDown to be in the interval (-π/2, π/2). If camera forward and world up become parallel, NaNs will happen.
func (*FlyControl) Reorient ¶ added in v0.3.4
func (fc *FlyControl) Reorient(target, worldUp *math32.Vector3)
Reorient the camera to look at target and use the given world up direction.
func (*FlyControl) Reposition ¶ added in v0.3.4
func (fc *FlyControl) Reposition(position *math32.Vector3)
Reposition the camera to the new position.
func (*FlyControl) Right ¶ added in v0.3.4
func (fc *FlyControl) Right(delta float32)
Right and left translation along the camera's right axis.
func (*FlyControl) Roll ¶ added in v0.3.4
func (fc *FlyControl) Roll(delta float32)
Roll adjustment in radians. Roll rotates the camera about its forward axis.
func (*FlyControl) ScaleZoom ¶ added in v0.3.4
func (fc *FlyControl) ScaleZoom(fovScale float32)
ScaleZoom modifies the fov based on scaling the current fov.
func (*FlyControl) SetMouseIsCaptured ¶ added in v0.3.4
func (fc *FlyControl) SetMouseIsCaptured(captured bool)
SetMouseIsCaptured is used to inform the FlyControl about the cursor being captured by the GL window so the FlyControl can respond to mouse events appropriately. Mouse/cursor capture is not modifed by the FlyControl.
func (*FlyControl) SetMouseSensitivity ¶ added in v0.3.4
func (fc *FlyControl) SetMouseSensitivity(value float32)
SetMouseSensitivity to value in [0,1]. Values outside of [0,1] are clamped to that range.
func (*FlyControl) Subscribe ¶ added in v0.3.4
func (fc *FlyControl) Subscribe(key, mouse bool)
Subscribe to input events. A value of false for either key or mouse does not unsubscribe from that type of event. Multiple calls will subscribe only once.
func (*FlyControl) Unsubscribe ¶ added in v0.3.4
func (fc *FlyControl) Unsubscribe(key, mouse bool)
Unsubscribe from input events.
func (*FlyControl) Up ¶ added in v0.3.4
func (fc *FlyControl) Up(delta float32)
Up and down translation along the current "up" axis.
func (*FlyControl) UseWorldUp ¶ added in v0.3.4
func (fc *FlyControl) UseWorldUp(use bool)
UseWorldUp sets the FlyControl to use world up instead of camera up when calculating movements Up/Down, Yaw, Pitch, and Roll. Setting this to false will use the "up" direction relative to the camera's point of view.
Caution: If using world up, take care not to allow the camera's forward direction to become parallel to the world up direction by setting constraints on PitchUp and PitchDown to be in the interval (-π/2, π/2). If camera forward and world up become parallel, NaNs will happen.
func (*FlyControl) Yaw ¶ added in v0.3.4
func (fc *FlyControl) Yaw(delta float32)
Yaw adjustment in radians. Yaw rotates the camera about the current "up" axis. Positive yaw is "right" from the camera's point of view.
func (*FlyControl) Zoom ¶ added in v0.3.4
func (fc *FlyControl) Zoom(delta float32)
Zoom modifies the fov based on the delta change in radians.
type FlyControlOption ¶ added in v0.3.4
type FlyControlOption func(fc *FlyControl)
FlyControlOption is a functional option when creating a new FlyControl.
func FPSStyle ¶ added in v0.3.4
func FPSStyle() FlyControlOption
FPSStyle configures the FlyControl with some default settings to make it act similarly to most FPS style games.
Yaw causes the camera to rotate around world up instead of camera up (IsUsingWorldUp()==true). Forward/Backward/Right/Left is mapped to the WADS keys while Yaw and Pitch are mapped to the arrow keys and also the mouse. Mouse look requires the user to left-click and hold. Pitch is constrained between ±85 degrees, and FoV is constrained between 0 and 100 degrees. The control subscribes to keyboard and mouse events.
These settings can be altered by providing maps with WithKeys() etc functional options in NewFlyControl(), or by altering the maps directly in the FlyControl struct. This option should be listed before any of the With*() options.
func FlightSimStyle ¶ added in v0.3.4
func FlightSimStyle() FlyControlOption
FlightSimStyle configures the FlyControl with some default settings to make it act similarly to a airplane or spacecraft.
Yaw causes the camera to rotate around camera up instead of world up (IsUsingWorldUp()==false). Forward/Backward/Right/Left is mapped to the arrow keys while Yaw/Pitch/Roll are mapped to the WADS and also the mouse. Mouse look requires the user to left-click and hold. There are no rotational constraints, allowing the camera to perform manuvers such as loops and aileron rolls. FoV is constrained between 0 and 100 degrees. The control subscribes to keyboard and mouse events.
These settings can be altered by providing maps with WithKeys() etc functional options in NewFlyControl(), or by altering the maps directly in the FlyControl struct. This option should be listed before any of the With*() options.
func WithConstraints ¶ added in v0.3.4
func WithConstraints(constraints map[FlyMovement]float32) FlyControlOption
WithConstraints provides a map of rotation (and FoV) constraints for the FlyControl.
func WithKeys ¶ added in v0.3.4
func WithKeys(keys map[FlyMovement]window.Key) FlyControlOption
WithKeys provides a map of movements to keys for the FlyControl.
func WithMouse ¶ added in v0.3.4
func WithMouse(mouse map[FlyMovement]MouseGuesture) FlyControlOption
WithMouse provides a map of movements to mouse guestures for the FlyControl.
func WithSpeeds ¶ added in v0.3.4
func WithSpeeds(speeds map[FlyMovement]float32) FlyControlOption
WithSpeeds provides a map of movement speeds for the FlyControl.
type FlyMovement ¶ added in v0.3.4
type FlyMovement int
FlyMovement are the ways the camera can move.
const ( Forward FlyMovement = iota // positive translation in the direction the camera is looking. Backward // negative translation in the direction the camera is looking. Right // right ("positive") translation from the camera's point of view. Left // left ("negative") translation from the camera's point of view. Up // upward ("positive") translation from the camera's point of view. Down // downward ("negative") translation from the camera's point of view. YawRight // "right" rotation from the camera's point of view. YawLeft // "left" rotation from the camera's point of view. PitchUp // "up" rotation from the camera's point of view. PitchDown // "down" rotation from the camera's point of view. RollRight // rotation "right" (CW) along the direction the camera is looking. RollLeft // rotation "left" (CCW) along the direction the camera is looking. ZoomOut // increase in the field of view. ZoomIn // decrease in the field of view. )
type MouseGuesture ¶ added in v0.3.4
type MouseGuesture struct { Motion MouseMotion // motion of the guesture Buttons []window.MouseButton // list of mouse buttons that must be pressed Captured bool // guesture happens when mouse is captured by window }
MouseGuesture is an action performed with the mouse in a particular direction (eg up) and with optional mouse buttons pressed. Captured indicates if the MouseGuesture is active/valid only when the mouse is captured by the window (indicated by calling SetMouseIsCaptured(true)).
type MouseMotion ¶ added in v0.3.4
type MouseMotion int
MouseMotion are the ways a mouse can move.
const ( MouseNone MouseMotion = iota MouseRight // +X MouseLeft // -X MouseDown // +Y MouseUp // -Y MouseScrollRight // +X MouseScrollLeft // -X MouseScrollDown // +Y MouseScrollUp // -Y )
type OrbitControl ¶ added in v0.3.2
type OrbitControl struct { core.Dispatcher // Embedded event dispatcher // Public properties MinDistance float32 // Minimum distance from target (default is 1) MaxDistance float32 // Maximum distance from target (default is infinity) MinPolarAngle float32 // Minimum polar angle in radians (default is 0) MaxPolarAngle float32 // Maximum polar angle in radians (default is Pi) MinAzimuthAngle float32 // Minimum azimuthal angle in radians (default is negative infinity) MaxAzimuthAngle float32 // Maximum azimuthal angle in radians (default is infinity) RotSpeed float32 // Rotation speed factor (default is 1) ZoomSpeed float32 // Zoom speed factor (default is 0.1) KeyRotSpeed float32 // Rotation delta in radians used on each rotation key event (default is the equivalent of 15 degrees) KeyZoomSpeed float32 // Zoom delta used on each zoom key event (default is 2) KeyPanSpeed float32 // Pan delta used on each pan key event (default is 35) // contains filtered or unexported fields }
OrbitControl is a camera controller that allows orbiting a target point while looking at it. It allows the user to rotate, zoom, and pan a 3D scene using the mouse or keyboard.
func NewOrbitControl ¶ added in v0.3.2
func NewOrbitControl(cam *Camera) *OrbitControl
NewOrbitControl creates and returns a pointer to a new orbit control for the specified camera.
func (*OrbitControl) Dispose ¶ added in v0.3.2
func (oc *OrbitControl) Dispose()
Dispose unsubscribes from all events.
func (*OrbitControl) Enabled ¶ added in v0.3.2
func (oc *OrbitControl) Enabled() OrbitEnabled
Enabled returns the current OrbitEnabled bitmask.
func (*OrbitControl) Pan ¶ added in v0.3.2
func (oc *OrbitControl) Pan(deltaX, deltaY float32)
Pan pans the camera and target the specified amount on the plane perpendicular to the viewing direction.
func (*OrbitControl) Reset ¶ added in v0.3.2
func (oc *OrbitControl) Reset()
Reset resets the orbit control.
func (*OrbitControl) Rotate ¶ added in v0.3.2
func (oc *OrbitControl) Rotate(thetaDelta, phiDelta float32)
Rotate rotates the camera around the target by the specified angles.
func (*OrbitControl) SetEnabled ¶ added in v0.3.2
func (oc *OrbitControl) SetEnabled(bitmask OrbitEnabled)
SetEnabled sets the current OrbitEnabled bitmask.
func (*OrbitControl) SetTarget ¶ added in v0.3.2
func (oc *OrbitControl) SetTarget(v math32.Vector3)
Set camera orbit target Vector3
func (*OrbitControl) Target ¶ added in v0.3.2
func (oc *OrbitControl) Target() math32.Vector3
Target returns the current orbit target.
func (*OrbitControl) Zoom ¶ added in v0.3.2
func (oc *OrbitControl) Zoom(delta float32)
Zoom moves the camera closer or farther from the target the specified amount and also updates the camera's orthographic size to match.
type OrbitEnabled ¶ added in v0.3.2
type OrbitEnabled int
OrbitEnabled specifies which control types are enabled.
const ( OrbitNone OrbitEnabled = 0x00 OrbitRot OrbitEnabled = 0x01 OrbitZoom OrbitEnabled = 0x02 OrbitPan OrbitEnabled = 0x04 OrbitKeys OrbitEnabled = 0x08 OrbitAll OrbitEnabled = 0xFF )
The possible control types.