Skip to content

package cameras

import "kaiju/cameras"

Types

Camera

interface

type Camera interface {
    SetPosition(position matrix.Vec3)
    SetFOV(fov float32)
    SetNearPlane(near float32)
    SetFarPlane(far float32)
    SetWidth(width float32)
    SetHeight(height float32)
    ViewportChanged(width, height float32)
    SetProperties(fov, nearPlane, farPlane, width, height float32)
    Forward() matrix.Vec3
    Right() matrix.Vec3
    Up() matrix.Vec3
    SetLookAt(position matrix.Vec3)
    SetLookAtWithUp(point, up matrix.Vec3)
    SetPositionAndLookAt(position, lookAt matrix.Vec3)
    RayCast(screenPos matrix.Vec2) collision.Ray
    TryPlaneHit(screenPos matrix.Vec2, planePos, planeNml matrix.Vec3) (hit matrix.Vec3, success bool)
    ForwardPlaneHit(screenPos matrix.Vec2, planePos matrix.Vec3) (matrix.Vec3, bool)
    Position() matrix.Vec3
    Width() float32
    Height() float32
    View() matrix.Mat4
    Projection() matrix.Mat4
    LookAt() matrix.Vec3
    NearPlane() float32
    FarPlane() float32
}

StandardCamera

struct

type StandardCamera struct {
    // Has unexported fields.
}

NewStandardCamera

func NewStandardCamera(width, height float32, position matrix.Vec3) *StandardCamera

NewStandardCamera creates a new perspective camera using the width/height for the viewport and the position to place the camera.

NewStandardCameraOrthographic

func NewStandardCameraOrthographic(width, height float32, position matrix.Vec3) *StandardCamera

NewStandardCameraOrthographic creates a new orthographic camera using the width/height for the viewport and the position to place the camera.

StandardCamera.FarPlane

func (c *StandardCamera) FarPlane() float32

FarPlane will return the far plane of the camera.

StandardCamera.Forward

func (c *StandardCamera) Forward() matrix.Vec3

Forward returns the forward vector of the camera.

StandardCamera.ForwardPlaneHit

func (c *StandardCamera) ForwardPlaneHit(screenPos matrix.Vec2, planePos matrix.Vec3) (matrix.Vec3, bool)

ForwardPlaneHit will project a ray from the camera's position given a screen position and test if it hits a plane directly facing the cameras position.

StandardCamera.Height

func (c *StandardCamera) Height() float32

Height will return the height of the camera's viewport.

StandardCamera.LookAt

func (c *StandardCamera) LookAt() matrix.Vec3

LookAt will return the look at position of the camera.

StandardCamera.NearPlane

func (c *StandardCamera) NearPlane() float32

NearPlane will return the near plane of the camera.

StandardCamera.Position

func (c *StandardCamera) Position() matrix.Vec3

Position will return the position of the camera.

StandardCamera.Projection

func (c *StandardCamera) Projection() matrix.Mat4

Projection will return the projection matrix of the camera.

StandardCamera.RayCast

func (c *StandardCamera) RayCast(screenPos matrix.Vec2) collision.Ray

RayCast will project a ray from the camera's position given a screen position using the camera's view and projection matrices.

StandardCamera.Right

func (c *StandardCamera) Right() matrix.Vec3

Right returns the right vector of the camera.

StandardCamera.SetFOV

func (c *StandardCamera) SetFOV(fov float32)

SetFOV sets the field of view for the camera.

StandardCamera.SetFarPlane

func (c *StandardCamera) SetFarPlane(far float32)

SetFarPlane sets the far plane for the camera.

StandardCamera.SetHeight

func (c *StandardCamera) SetHeight(height float32)

SetHeight sets the height of the camera viewport.

StandardCamera.SetLookAt

func (c *StandardCamera) SetLookAt(position matrix.Vec3)

SetLookAt sets the look at position of the camera.

StandardCamera.SetLookAtWithUp

func (c *StandardCamera) SetLookAtWithUp(point, up matrix.Vec3)

SetLookAtWithUp sets the look at position of the camera and the up vector to use.

StandardCamera.SetNearPlane

func (c *StandardCamera) SetNearPlane(near float32)

SetNearPlane sets the near plane for the camera.

StandardCamera.SetPosition

func (c *StandardCamera) SetPosition(position matrix.Vec3)

SetPosition sets the position of the camera.

StandardCamera.SetPositionAndLookAt

func (c *StandardCamera) SetPositionAndLookAt(position, lookAt matrix.Vec3)

SetPositionAndLookAt sets the position and look at position of the camera. This is often useful for when the camera warps to another location in space and avoids needless view matrix updates when setting the position and look at separately.

StandardCamera.SetProperties

func (c *StandardCamera) SetProperties(fov, nearPlane, farPlane, width, height float32)

SetProperties is quick access to set many properties of the camera at once. This is typically used for initializing the camera to new values. Calling each individual setter for fields would otherwise do needless projection matrix updates.

StandardCamera.SetWidth

func (c *StandardCamera) SetWidth(width float32)

SetWidth sets the width of the camera viewport.

StandardCamera.TryPlaneHit

func (c *StandardCamera) TryPlaneHit(screenPos matrix.Vec2, planePos, planeNml matrix.Vec3) (hit matrix.Vec3, success bool)

TryPlaneHit will project a ray from the camera's position given a screen position and test if it hits a plane. If it does, it will return the hit position and true. If it does not, it will return the zero vector and false.

StandardCamera.Up

func (c *StandardCamera) Up() matrix.Vec3

Up returns the up vector of the camera.

StandardCamera.View

func (c *StandardCamera) View() matrix.Mat4

View will return the view matrix of the camera.

StandardCamera.ViewportChanged

func (c *StandardCamera) ViewportChanged(width, height float32)

ViewportChanged will update the camera's projection matrix and should only be used when there is a change in the viewport. This is typically done internally in the system and should not be called by the end-developer.

StandardCamera.Width

func (c *StandardCamera) Width() float32

Width will return the width of the camera's viewport.

TurntableCamera

struct

type TurntableCamera struct {
    StandardCamera

    // Has unexported fields.
}

ToTurntable

func ToTurntable(camera *StandardCamera) *TurntableCamera

ToTurntable converts a standard camera to a turntable camera.

TurntableCamera.Dolly

func (c *TurntableCamera) Dolly(delta float32)

Dolly moves the camera closer/further from the look at point by the given delta.

TurntableCamera.Orbit

func (c *TurntableCamera) Orbit(delta matrix.Vec3)

Orbit orbits the camera around the look at point by the given delta.

TurntableCamera.Pan

func (c *TurntableCamera) Pan(delta matrix.Vec3)

Pan pans the camera while keeping the same facing by the given delta.

TurntableCamera.Pitch

func (c *TurntableCamera) Pitch() float32

Pitch returns the pitch of the camera.

TurntableCamera.RayCast

func (c *TurntableCamera) RayCast(screenPos matrix.Vec2) collision.Ray

RayCast will project a ray from the camera's position given a screen position using the camera's view and projection matrices.

TurntableCamera.SetLookAt

func (c *TurntableCamera) SetLookAt(lookAt matrix.Vec3)

SetLookAt sets the look at position of the camera.

TurntableCamera.SetLookAtWithUp

func (c *TurntableCamera) SetLookAtWithUp(point, up matrix.Vec3)

SetLookAtWithUp sets the look at position of the camera and the up vector to use.

TurntableCamera.SetPitch

func (c *TurntableCamera) SetPitch(pitch float32)

SetPitch sets the pitch of the camera.

TurntableCamera.SetPosition

func (c *TurntableCamera) SetPosition(position matrix.Vec3)

SetPosition sets the position of the camera.

TurntableCamera.SetYaw

func (c *TurntableCamera) SetYaw(yaw float32)

SetYaw sets the yaw of the camera.

TurntableCamera.SetYawAndPitch

func (c *TurntableCamera) SetYawAndPitch(yaw, pitch float32)

SetYawAndPitch sets the yaw and pitch of the camera. This helps skip needless view matrix calculations by setting both before updating the view.

TurntableCamera.SetYawPitchZoom

func (c *TurntableCamera) SetYawPitchZoom(yaw, pitch, zoom float32)

SetYawPitchZoom sets the yaw, pitch, and zoom of the camera. This helps skip needless view matrix calculations by setting all three before updating the view.

TurntableCamera.SetZoom

func (c *TurntableCamera) SetZoom(zoom float32)

SetZoom sets the zoom of the camera.

TurntableCamera.Yaw

func (c *TurntableCamera) Yaw() float32

Yaw returns the yaw of the camera.

TurntableCamera.Zoom

func (c *TurntableCamera) Zoom() float32

Zoom returns the zoom of the camera.