camera

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 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 Intersect added in v0.2.8

type Intersect struct {
	// Distance between the origin of the ray and the intersection
	Distance float32
	// Point of intersection in world coordinates
	Point math32.Vector3
	// Intersected node
	Object core.INode
	// If the geometry has indices, this field is the
	// index in the Indices buffer of the vertex intersected
	// or the first vertex of the intersected face.
	// If the geometry doesn't have indices, this field is the
	// index in the positions buffer of the vertex intersected
	// or the first vertex of the intersected face.
	Index uint32
}

Intersect describes the intersection between a ray and an object

type Projection

type Projection int

Projection represents a camera projection.

type Raycaster added in v0.2.8

type Raycaster struct {
	// The distance from the ray origin to the intersected points
	// must be greater than the value of this field to be considered.
	// The default value is 0.0
	Near float32
	// The distance from the ray origin to the intersected points
	// must be less than the value of this field to be considered.
	// The default value is +Infinity.
	Far float32
	// Minimum distance in world coordinates between the ray and
	// a line segment when checking intersects with lines.
	// The default value is 0.1
	LinePrecision float32
	// Minimum distance in world coordinates between the ray and
	// a point when checking intersects with points.
	// The default value is 0.1
	PointPrecision float32
	// This field must be set with the camera view matrix used
	// when checking for sprite intersections.
	// It is set automatically when using camera.SetRaycaster
	ViewMatrix math32.Matrix4
	// Embedded ray
	math32.Ray
}

Raycaster represents an empty object that can cast rays and check for ray intersections.

func NewRaycaster added in v0.2.8

func NewRaycaster(origin, direction *math32.Vector3) *Raycaster

NewRaycaster creates and returns a pointer to a new raycaster object with the specified origin and direction.

func (*Raycaster) IntersectObject added in v0.2.8

func (rc *Raycaster) IntersectObject(inode core.INode, recursive bool) []Intersect

IntersectObject checks intersections between this raycaster and the specified node. If recursive is true, it also checks the intersection with the node's children. Intersections are returned sorted by distance, closest first.

func (*Raycaster) IntersectObjects added in v0.2.8

func (rc *Raycaster) IntersectObjects(inodes []core.INode, recursive bool) []Intersect

IntersectObjects checks intersections between this raycaster and the specified array of scene nodes. If recursive is true, it also checks the intersection with each nodes' children. Intersections are returned sorted by distance, closest first.

func (*Raycaster) RaycastLineStrip added in v0.2.8

func (rc *Raycaster) RaycastLineStrip(l *graphic.LineStrip, intersects *[]Intersect)

RaycastLineStrip checks for intersections with a graphic.LineStrip.

func (*Raycaster) RaycastLines added in v0.2.8

func (rc *Raycaster) RaycastLines(l *graphic.Lines, intersects *[]Intersect)

RaycastLines checks for intersections with a graphic.Lines.

func (*Raycaster) RaycastMesh added in v0.2.8

func (rc *Raycaster) RaycastMesh(m *graphic.Mesh, intersects *[]Intersect)

RaycastMesh checks for intersections with a graphic.Mesh.

func (*Raycaster) RaycastPoints added in v0.2.8

func (rc *Raycaster) RaycastPoints(p *graphic.Points, intersects *[]Intersect)

RaycastPoints checks for intersections with a graphic.Points.

func (*Raycaster) RaycastSprite added in v0.2.8

func (rc *Raycaster) RaycastSprite(s *graphic.Sprite, intersects *[]Intersect)

RaycastSprite checks intersections between the raycaster and the specified sprite and if any found appends it to the specified intersects array.

func (*Raycaster) SetFromCamera added in v0.2.8

func (rc *Raycaster) SetFromCamera(cam *Camera, sx, sy float32) error

SetFromCamera sets the specified raycaster with this camera position in world coordinates pointing to the direction defined by the specified coordinates unprojected using this camera.

Jump to

Keyboard shortcuts

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