camera

package
v0.0.0-...-63f7c67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2023 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package camera contains virtual cameras and associated controls.

Index

Constants

View Source
const (
	Vertical = Axis(iota)
	Horizontal
)

The two possible camera axes.

View Source
const (
	Perspective = Projection(iota)
	Orthographic
)

The possible camera projections.

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis

type Axis int

Axis represents a camera axis.

type Camera

type Camera struct {
	core.Node // Embedded Node
	// contains filtered or unexported fields
}

Camera represents a virtual camera, which specifies how to project a 3D scene onto an image.

func New

func New(aspect float32) *Camera

New creates and returns a new perspective camera with the specified aspect ratio and default parameters.

func NewOrthographic

func NewOrthographic(aspect, near, far, size float32, axis Axis) *Camera

NewOrthographic creates and returns a new orthographic camera with the specified parameters.

func NewPerspective

func NewPerspective(aspect, near, far, fov float32, axis Axis) *Camera

NewPerspective creates and returns a new perspective camera with the specified parameters.

func (*Camera) Aspect

func (c *Camera) Aspect() float32

Aspect returns the camera aspect ratio.

func (*Camera) Axis

func (c *Camera) Axis() Axis

Axis returns the reference axis associated with the camera size/fov.

func (*Camera) Far

func (c *Camera) Far() float32

Far returns the camera far plane Z coordinate.

func (*Camera) Fov

func (c *Camera) Fov() float32

Fov returns the perspective field-of-view in degrees along the reference axis.

func (*Camera) Near

func (c *Camera) Near() float32

Near returns the camera near plane Z coordinate.

func (*Camera) ProjMatrix

func (c *Camera) ProjMatrix(m *math32.Matrix4)

ProjMatrix returns the projection matrix of the camera.

func (*Camera) Project

func (c *Camera) Project(v *math32.Vector3) *math32.Vector3

Project transforms the specified position from world coordinates to this camera projected coordinates.

func (*Camera) Projection

func (c *Camera) Projection() Projection

Projection returns the projection method used by the camera.

func (*Camera) SetAspect

func (c *Camera) SetAspect(aspect float32)

SetAspect sets the camera aspect ratio.

func (*Camera) SetAxis

func (c *Camera) SetAxis(axis Axis)

SetAxis sets the reference axis associated with the camera size/fov.

func (*Camera) SetFar

func (c *Camera) SetFar(far float32)

SetFar sets the camera far plane Z coordinate.

func (*Camera) SetFov

func (c *Camera) SetFov(fov float32)

SetFov sets the perspective field-of-view in degrees along the reference axis.

func (*Camera) SetNear

func (c *Camera) SetNear(near float32)

SetNear sets the camera near plane Z coordinate.

func (*Camera) SetProjection

func (c *Camera) SetProjection(proj Projection)

SetProjection sets the projection method used by the camera.

func (*Camera) SetSize

func (c *Camera) SetSize(size float32)

SetSize sets the orthographic view size along the camera's reference axis.

func (*Camera) Size

func (c *Camera) Size() float32

Size returns the orthographic view size along the camera's reference axis.

func (*Camera) Unproject

func (c *Camera) Unproject(v *math32.Vector3) *math32.Vector3

Unproject transforms the specified position from camera projected coordinates to world coordinates.

func (*Camera) UpdateFov

func (c *Camera) UpdateFov(targetDist float32)

UpdateFov updates the field-of-view such that the frustum matches the orthographic size at the depth specified by targetDist.

func (*Camera) UpdateSize

func (c *Camera) UpdateSize(targetDist float32)

UpdateSize updates the orthographic size to match the current field-of-view frustum at the depth specified by targetDist.

func (*Camera) ViewMatrix

func (c *Camera) ViewMatrix(m *math32.Matrix4)

ViewMatrix returns the view matrix of the camera.

type ICamera

type ICamera interface {
	ViewMatrix(m *math32.Matrix4)
	ProjMatrix(m *math32.Matrix4)
}

ICamera is the interface for all cameras.

type OrbitControl

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

func NewOrbitControl(cam *Camera) *OrbitControl

NewOrbitControl creates and returns a pointer to a new orbit control for the specified camera.

func (*OrbitControl) Dispose

func (oc *OrbitControl) Dispose()

Dispose unsubscribes from all events.

func (*OrbitControl) Enabled

func (oc *OrbitControl) Enabled() OrbitEnabled

Enabled returns the current OrbitEnabled bitmask.

func (*OrbitControl) Pan

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

func (oc *OrbitControl) Reset()

Reset resets the orbit control.

func (*OrbitControl) Rotate

func (oc *OrbitControl) Rotate(thetaDelta, phiDelta float32)

Rotate rotates the camera around the target by the specified angles.

func (*OrbitControl) SetEnabled

func (oc *OrbitControl) SetEnabled(bitmask OrbitEnabled)

SetEnabled sets the current OrbitEnabled bitmask.

func (*OrbitControl) SetTarget

func (oc *OrbitControl) SetTarget(v math32.Vector3)

Set camera orbit target Vector3

func (*OrbitControl) Target

func (oc *OrbitControl) Target() math32.Vector3

Target returns the current orbit target.

func (*OrbitControl) Zoom

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

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.

type Projection

type Projection int

Projection represents a camera projection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL