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 ¶
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 ¶
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) 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 ¶
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 ¶
Projection implements the gfx.Camera interface.