camera

package
v0.0.0-...-793ea6c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: BSD-3-Clause Imports: 5 Imported by: 18

Documentation

Overview

Package camera provides a basic 2D and 3D camera implementation.

Standard perspective (3D) cameras can be created using New, and orthographic (2D) cameras can be created using NewOrtho.

When a camera's properties (or the view area / window size changes) you should invoke Update on the camera.

Visualizing the camera's wireframe can be done by setting Debug == true and invoking Update.

The type of camera can be switched at runtime by changing mycam.Ortho = true as needed, and then calling Update.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	*gfx.Object

	// View is the viewing rectangle of the camera, e.g. the rectangle it will
	// draw to on the screen.
	View image.Rectangle

	// Near and far values of the camera's viewing frustum, e.g. Near=0.01,
	// Far=1000.
	Near, Far float64

	// FOV is the Y axis field-of-view (e.g. 75) for the camera's lens. For an
	// orthographic (2D) camera, this field is unused.
	FOV float64

	// Ortho is whether or not the camera is orthographic (2D), if false then
	// it is a projection (3D) camera.
	Ortho bool

	// P is the calculated projection matrix of the camera, as returned by the
	// Projection method.
	P gfx.Mat4

	// Debug causes the camera to attach a wireframe mesh and shader to itself
	// each time Update is called, for debugging purposes.
	Debug bool
}

Camera represents a camera object, it may be moved in 3D space using the objects transform and the viewing frustum controls how the camera views things. Since a camera is in itself also an object it may also have visible meshes attatched to it, etc.

A camera and it's methods are not safe for access from multiple goroutines concurrently.

func New

func New(view image.Rectangle) *Camera

New returns a new perspective (3D) camera updated with the given viewing rectangle. The returned camera has the following properties:

FOV = 75
Near = 0.1
Far = 1000
Ortho = false

func NewOrtho

func NewOrtho(view image.Rectangle) *Camera

NewOrtho returns a new orthographic (2D) camera updated with the given viewing rectangle. The returned camera has the following properties:

Near = 0.1
Far = 1000
FOV = 75
Ortho = true

func (*Camera) Copy

func (c *Camera) Copy() *Camera

Copy returns a new copy of this Camera.

func (*Camera) Destroy

func (c *Camera) Destroy()

Destroy destroys this camera for use by other callees to New. You must not use it after calling this method. This makes an implicit call to destroy the gfx.Object as well (if non-nil).

func (*Camera) Project

func (c *Camera) Project(p3 lmath.Vec3) (p2 lmath.Vec2, ok bool)

Project returns a 2D point in normalized device space coordinates given a 3D point in the world.

If ok=false is returned then the point is outside of the camera's view and the returned point may not be meaningful.

func (*Camera) Projection

func (c *Camera) Projection() gfx.Mat4

Projection implements the gfx.Camera interface.

func (*Camera) Transform

func (c *Camera) Transform() *gfx.Transform

Transform implements the gfx.Transformable interface.

func (*Camera) Update

func (c *Camera) Update(view image.Rectangle)

Update updates the camera's projection matrix to account for the given viewing rectangle which may have changed (e.g. upon window resize).

Jump to

Keyboard shortcuts

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