Documentation
¶
Overview ¶
Package camera is experimental: its API and documented behavior may change in a minor release; see https://nsgo.games/docs/stability/.
Package camera arbitrates between virtual cameras for 2D (tilemap.Camera) and 3D (scene3d.Camera) scenes with priorities, soloing, curved and per-pair blends (including smooth interruption mid-blend), target-group framing, 3D convex/box confiners, and additive noise-driven impulse shake scaled by reduced-motion accessibility preferences.
Index ¶
- Variables
- func ClosestT3D(curve math3d.Curve3D, pos math3d.Vec3) float32
- type BlendDef
- type BlendOverride
- type BlendStyle
- type Confiner3D
- type Confiner3DKind
- type Dimension
- type Director
- func (d *Director) Active() *VirtualCamera
- func (d *Director) ActiveImpulses() int
- func (d *Director) Add(vcam *VirtualCamera, priority int)
- func (d *Director) BlendProgress() float64
- func (d *Director) Blending() bool
- func (d *Director) ClearBlendOverrides()
- func (d *Director) ClearImpulses()
- func (d *Director) Impulse(source *ImpulseSource, strength float32)
- func (d *Director) ImpulseOffset2D() core.Point
- func (d *Director) ImpulseOffset3D() math3d.Vec3
- func (d *Director) ImpulseRoll2D() float32
- func (d *Director) ImpulseRotation3D() math3d.Vec3
- func (d *Director) NextActive(exclude *VirtualCamera) *VirtualCamera
- func (d *Director) Pose2D() Pose2D
- func (d *Director) Pose3D() scene3d.Camera
- func (d *Director) Priority(vcam *VirtualCamera) (int, bool)
- func (d *Director) Remove(vcam *VirtualCamera)
- func (d *Director) SetBlendOverride(from, to *VirtualCamera, blend BlendDef)
- func (d *Director) SetBlendOverrideByName(fromName, toName string, blend BlendDef)
- func (d *Director) SetPriority(vcam *VirtualCamera, priority int)
- func (d *Director) Snap()
- func (d *Director) Solo(vcam *VirtualCamera)
- func (d *Director) Soloed() *VirtualCamera
- func (d *Director) Step(dt time.Duration)
- func (d *Director) UnshakenPose2D() Pose2D
- func (d *Director) UnshakenPose3D() scene3d.Camera
- func (d *Director) Update(dt time.Duration)
- type Dolly2DConfig
- type Dolly3DConfig
- type DollyOrient
- type Fixed3DConfig
- type Group2DConfig
- type Group3DConfig
- type GroupFramingMode
- type GroupTarget2D
- type GroupTarget3D
- type ImpulseProfile
- type ImpulseSource
- type Kind
- type LookAt3DConfig
- type Path3D
- func (p *Path3D) Closed() bool
- func (p *Path3D) DistanceToT(dist float32) float32
- func (p *Path3D) FrameAt(t float32, worldUp math3d.Vec3) math3d.CurveFrame
- func (p *Path3D) FrameAtDistance(dist float32) math3d.CurveFrame
- func (p *Path3D) Length() float32
- func (p *Path3D) Point(t float32) math3d.Vec3
- func (p *Path3D) PointAtDistance(dist float32) math3d.Vec3
- func (p *Path3D) Tangent(t float32) math3d.Vec3
- func (p *Path3D) TangentAtDistance(dist float32) math3d.Vec3
- type PathPoint3D
- type Pose2D
- type VirtualCamera
- func NewDolly2D(name string, path *tween.BezierPath) *VirtualCamera
- func NewDolly3D(name string, path math3d.Curve3D) *VirtualCamera
- func NewFPS3D(name string, fps *scene3d.FPSController) *VirtualCamera
- func NewFixed2D(name string, x, y, zoom float32) *VirtualCamera
- func NewFixed3D(name string, pos math3d.Vec3, rot math3d.Quat) *VirtualCamera
- func NewFunc2D(name string, fn func(dt time.Duration) Pose2D) *VirtualCamera
- func NewFunc3D(name string, fn func(dt time.Duration) scene3d.Camera) *VirtualCamera
- func NewGroup2D(name string, targets ...GroupTarget2D) *VirtualCamera
- func NewGroup3D(name string, targets ...GroupTarget3D) *VirtualCamera
- func NewLookAt3D(name string, pos, target math3d.Vec3) *VirtualCamera
- func NewOrbit3D(name string, orbit *scene3d.OrbitController) *VirtualCamera
- func NewRig2D(name string, rig *tilemap.CameraRig) *VirtualCamera
- func NewThirdPerson3D(name string, tp *scene3d.ThirdPersonController) *VirtualCamera
- func (v *VirtualCamera) DollyProgress() float32
- func (v *VirtualCamera) Enabled() bool
- func (v *VirtualCamera) Pose2D() Pose2D
- func (v *VirtualCamera) Pose3D() scene3d.Camera
- func (v *VirtualCamera) SetDollyProgress(t float32)
- func (v *VirtualCamera) SetEnabled(enabled bool)
- func (v *VirtualCamera) SetTarget2D(pos, vel core.Point, rot float32, dt time.Duration)
- func (v *VirtualCamera) SetTarget3D(pos, forward math3d.Vec3)
- func (v *VirtualCamera) Snap()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDegenerateConfiner = errors.New("camera: points do not span a convex 3D volume")
ErrDegenerateConfiner is returned by NewConvexHullConfiner3D when the points do not span a 3D volume.
Functions ¶
Types ¶
type BlendDef ¶
type BlendDef struct {
Duration time.Duration
Style BlendStyle
Interp resource.Interp
Curve *resource.Curve
}
BlendDef defines how the Director transitions from one virtual camera to another.
Evaluation precedence for a positive Duration:
- Curve, if non-nil (sampled across its key time span for progress u in [0, 1]).
- Interp, if non-empty (using resource.Interp.Eval).
- Style (BlendLinear, BlendSmooth, BlendEaseIn, BlendEaseOut, BlendEaseInOut; BlendCut cuts immediately).
When Duration <= 0 or Style == BlendCut (with nil Curve and empty Interp), the transition is an instant cut.
func DefaultBlend ¶
func DefaultBlend() BlendDef
DefaultBlend returns a smooth 300ms ease-in-out blend definition.
type BlendOverride ¶
type BlendOverride struct {
From *VirtualCamera
To *VirtualCamera
FromName string
ToName string
Blend BlendDef
}
BlendOverride overrides the blend used when transitioning between a specific pair of virtual cameras.
Both From/To pointers and FromName/ToName strings are supported; leaving one side nil/empty matches any source or destination camera.
type BlendStyle ¶
type BlendStyle uint8
BlendStyle selects the easing curve used when transitioning between virtual cameras.
const ( // BlendCut cuts immediately in zero time; it is the zero value of BlendStyle (use DefaultBlend or set Style explicitly for timed blends). BlendCut BlendStyle = iota // BlendLinear interpolates at a constant rate. BlendLinear // BlendSmooth eases in and out with a cubic Hermite smoothstep. BlendSmooth // BlendEaseIn starts slowly and accelerates into the target camera. BlendEaseIn // BlendEaseOut starts quickly and decelerates onto the target camera. BlendEaseOut // BlendEaseInOut accelerates for the first half and decelerates for the second half. BlendEaseInOut )
func (BlendStyle) String ¶
func (s BlendStyle) String() string
String returns the canonical name of s.
type Confiner3D ¶
type Confiner3D struct {
Kind Confiner3DKind
Box math3d.AABB
Center math3d.Vec3
Rot math3d.Quat
HalfExtents math3d.Vec3
// Planes holds the outward-facing half-space planes of a ConfinerConvex volume: a point p is inside when p.SignedDist(pos) <= -Padding for every plane.
Planes []math3d.Plane
// Padding shrinks every boundary inward by this distance (e.g. camera near-plane radius); negative values are treated as 0.
Padding float32
// Smoothing is the exponential damping rate (1/s) applied when clamping or entering the volume; <= 0 clamps immediately.
Smoothing float32
// contains filtered or unexported fields
}
Confiner3D keeps a 3D camera pose inside an axis-aligned box, an oriented box, or a convex polyhedron, with optional exponential smoothing.
func NewBoxConfiner3D ¶
func NewBoxConfiner3D(box math3d.AABB) *Confiner3D
NewBoxConfiner3D returns a Confiner3D clamping poses inside box.
func NewConvexConfiner3D ¶
func NewConvexConfiner3D(planes []math3d.Plane) *Confiner3D
NewConvexConfiner3D returns a Confiner3D from outward half-space planes (Normal·p + D <= 0 inside).
func NewConvexHullConfiner3D ¶
func NewConvexHullConfiner3D(points []math3d.Vec3) (*Confiner3D, error)
NewConvexHullConfiner3D builds a ConfinerConvex from the convex hull of points. Returns ErrDegenerateConfiner if points are fewer than 4 or coplanar/collinear/non-finite.
func NewOrientedBoxConfiner3D ¶
func NewOrientedBoxConfiner3D(center math3d.Vec3, rot math3d.Quat, halfExtents math3d.Vec3) *Confiner3D
NewOrientedBoxConfiner3D returns a Confiner3D clamping poses inside an oriented box centered at center with orientation rot and half-extents halfExtents.
func (*Confiner3D) Clamp ¶
func (c *Confiner3D) Clamp(p math3d.Vec3) math3d.Vec3
Clamp returns the closest point to p inside the confiner volume (without smoothing).
func (*Confiner3D) Contains ¶
func (c *Confiner3D) Contains(p math3d.Vec3) bool
Contains reports whether p lies inside (or on the padded boundary of) the confiner volume.
func (*Confiner3D) Reset ¶
func (c *Confiner3D) Reset()
Reset clears the confiner's smoothed position history so the next Step initializes cleanly.
func (*Confiner3D) Snap ¶
func (c *Confiner3D) Snap(p math3d.Vec3) math3d.Vec3
Snap immediately clamps p inside the confiner and resets smoothing history to the clamped point.
func (*Confiner3D) Step ¶
Step confines p over dt.
Inside the volume, Step introduces zero lag when the previous position was also inside; when p leaves the volume or the previous position was outside (such as after switching confiners), Step eases smoothly toward Clamp(p) at rate Smoothing (or clamps immediately when Smoothing <= 0).
type Confiner3DKind ¶
type Confiner3DKind uint8
Confiner3DKind selects the bounding volume shape of a Confiner3D.
const ( // ConfinerBox confines the camera inside an axis-aligned math3d.AABB. ConfinerBox Confiner3DKind = iota // ConfinerOrientedBox confines the camera inside an oriented box (Center, Rot, HalfExtents). ConfinerOrientedBox // ConfinerConvex confines the camera inside the intersection of outward half-space Planes (Normal · p + D <= -Padding). ConfinerConvex )
type Dimension ¶
type Dimension uint8
Dimension identifies whether a VirtualCamera or Director operates in 2D or 3D.
type Director ¶
type Director struct {
// Camera3D is the real 3D camera written by Step when driving 3D virtual cameras.
Camera3D *scene3d.Camera
// Camera2D is the real 2D camera written by Step when driving 2D virtual cameras.
Camera2D *tilemap.Camera
// DefaultBlend is used whenever no per-pair BlendOverride matches.
DefaultBlend BlendDef
// Confiner3D optionally confines the blended 3D pose before impulse shake is applied.
Confiner3D *Confiner3D
// Bounds2D optionally clamps the blended 2D pose when the active pose sets no Bounds.
Bounds2D *core.Bounds
// Assist, Scope, and ReduceMotion control accessibility impulse scaling.
// When reduced motion is active (via ReduceMotion, Assist.ReduceMotion(), or Scope.Env().ReduceMotion()),
// impulse amplitudes are multiplied by ReducedMotionImpulseScale (0 by default).
Assist *a11y.Assist
Scope *core.Scope
ReduceMotion bool
ReducedMotionImpulseScale float32
// ImpulseGain scales all impulse shake amplitudes (defaults to 1 when 0; negative disables impulses).
ImpulseGain float32
// OnActiveChanged is called whenever the active winning VirtualCamera changes.
OnActiveChanged func(prev, next *VirtualCamera)
// contains filtered or unexported fields
}
Director arbitrates between registered VirtualCameras by priority and Solo state, blends smoothly between camera changes (including mid-blend interruptions), applies Confiner3D or 2D Bounds, and adds noise-based Impulse shake scaled by reduced-motion accessibility settings.
Example (ThreeD) ¶
package main
import (
"fmt"
"time"
"github.com/nsgo-dev/game/pkg/camera"
"github.com/nsgo-dev/game/pkg/math3d"
"github.com/nsgo-dev/game/pkg/scene3d"
)
func main() {
cam := scene3d.NewPerspectiveCamera(math3d.Vec3{}, math3d.DegToRad(60), 16.0/9.0, 0.1, 200)
director := camera.NewDirector3D(cam)
director.DefaultBlend = camera.BlendDef{Duration: 200 * time.Millisecond, Style: camera.BlendLinear}
follow := camera.NewFixed3D("follow", math3d.Vec3{X: 0, Y: 2, Z: 6}, math3d.QuatIdentity())
aim := camera.NewFixed3D("aim", math3d.Vec3{X: 2, Y: 2, Z: 2}, math3d.QuatIdentity())
director.Add(follow, 10)
director.Add(aim, 5)
director.Snap()
director.SetPriority(aim, 20)
director.Step(100 * time.Millisecond)
fmt.Printf("active=%s pos=(%.1f, %.1f, %.1f)\n", director.Active().Name, cam.Pos.X, cam.Pos.Y, cam.Pos.Z)
}
Output: active=aim pos=(1.0, 2.0, 4.0)
Example (TwoD) ¶
package main
import (
"fmt"
"time"
"github.com/nsgo-dev/game/pkg/camera"
"github.com/nsgo-dev/game/pkg/tilemap"
"github.com/nsgo-dev/nsgo/core"
)
func main() {
cam := &tilemap.Camera{Width: 320, Height: 180, Zoom: 1}
director := camera.NewDirector2D(cam)
director.DefaultBlend = camera.BlendDef{Style: camera.BlendCut}
rig := &tilemap.CameraRig{PositionSpeed: 0}
follow := camera.NewRig2D("follow", rig)
follow.Rig2DPosFn = func() core.Point { return core.Point{X: 160, Y: 90} }
director.Add(follow, 10)
director.Step(16 * time.Millisecond)
fmt.Printf("pos=(%.0f, %.0f)\n", cam.X, cam.Y)
}
Output: pos=(160, 90)
func NewDirector2D ¶
NewDirector2D creates a Director driving cam with DefaultBlend (300ms ease-in-out).
func NewDirector3D ¶
NewDirector3D creates a Director driving cam with DefaultBlend (300ms ease-in-out).
func (*Director) Active ¶
func (d *Director) Active() *VirtualCamera
Active returns the currently winning virtual camera (respecting Solo, Enabled, and priority).
func (*Director) ActiveImpulses ¶
ActiveImpulses returns the number of currently active decaying impulses.
func (*Director) Add ¶
func (d *Director) Add(vcam *VirtualCamera, priority int)
Add registers vcam with priority (or updates its priority if already registered).
func (*Director) BlendProgress ¶
BlendProgress returns normalized linear progress in [0, 1] of the active blend, or 1 when idle.
func (*Director) ClearBlendOverrides ¶
func (d *Director) ClearBlendOverrides()
ClearBlendOverrides removes all per-pair blend overrides.
func (*Director) ClearImpulses ¶
func (d *Director) ClearImpulses()
ClearImpulses immediately removes all active impulses.
func (*Director) Impulse ¶
func (d *Director) Impulse(source *ImpulseSource, strength float32)
Impulse triggers an additive noise-based camera impulse from source with initial strength (typically in (0, 1+]). Pass nil for source to use the default impulse profile. Impulses stack additively, decay linearly to zero, and scale with reduced-motion accessibility settings.
func (*Director) ImpulseOffset2D ¶
ImpulseOffset2D returns the current 2D translation shake offset in world points from active impulses.
func (*Director) ImpulseOffset3D ¶
ImpulseOffset3D returns the current 3D translation shake offset from active impulses.
func (*Director) ImpulseRoll2D ¶
ImpulseRoll2D returns the current 2D roll shake offset in radians from active impulses.
func (*Director) ImpulseRotation3D ¶
ImpulseRotation3D returns the current Euler rotation shake offset (pitch, yaw, roll in radians) from active impulses.
func (*Director) NextActive ¶
func (d *Director) NextActive(exclude *VirtualCamera) *VirtualCamera
NextActive returns the highest-priority enabled virtual camera other than exclude (ignoring Solo if exclude is soloed), or nil when none qualifies.
func (*Director) Pose2D ¶
Pose2D returns the last evaluated final 2D camera pose (after blending, clamping, and impulses).
func (*Director) Pose3D ¶
Pose3D returns the last evaluated final 3D camera pose (after blending, confining, and impulses).
func (*Director) Priority ¶
func (d *Director) Priority(vcam *VirtualCamera) (int, bool)
Priority returns vcam's registered priority and whether it is registered.
func (*Director) Remove ¶
func (d *Director) Remove(vcam *VirtualCamera)
Remove unregisters vcam from d. If vcam was soloed, solo is cleared.
func (*Director) SetBlendOverride ¶
func (d *Director) SetBlendOverride(from, to *VirtualCamera, blend BlendDef)
SetBlendOverride configures a custom blend for transitions from from to to (either pointer may be nil to act as a wildcard).
func (*Director) SetBlendOverrideByName ¶
SetBlendOverrideByName configures a custom blend matched by VirtualCamera.Name (empty string acts as a wildcard).
func (*Director) SetPriority ¶
func (d *Director) SetPriority(vcam *VirtualCamera, priority int)
SetPriority updates vcam's priority. No-op if vcam is not registered.
func (*Director) Snap ¶
func (d *Director) Snap()
Snap immediately finishes any active blend to the winning VirtualCamera, confines its pose, and writes it to Camera3D / Camera2D.
func (*Director) Solo ¶
func (d *Director) Solo(vcam *VirtualCamera)
Solo forces vcam to be the active virtual camera regardless of priority or enabled state. Pass nil to clear solo and resume priority arbitration. If vcam is non-nil and not yet registered, it is added with priority 0.
func (*Director) Soloed ¶
func (d *Director) Soloed() *VirtualCamera
Soloed returns the currently soloed virtual camera, or nil.
func (*Director) Step ¶
Step advances all enabled virtual cameras, active transition blends, confiners, and impulses by fixed step dt, and writes the resulting pose to Camera3D / Camera2D.
func (*Director) UnshakenPose2D ¶
UnshakenPose2D returns the last evaluated 2D pose before impulse shake.
func (*Director) UnshakenPose3D ¶
UnshakenPose3D returns the last evaluated 3D pose before impulse shake.
type Dolly2DConfig ¶
type Dolly2DConfig struct {
Path *tween.BezierPath
Speed float32 // Arc-length speed in world points/s when FollowFunc is nil.
Loop bool
PingPong bool
Distance float32
PathOffset float32
Rotates bool
RotationOffset float32
Zoom float32
FollowFunc func() core.Point
Smoothing float32
Bounds *core.Bounds
StepWhenInactive bool
ResetOnActivate bool
// contains filtered or unexported fields
}
Dolly2DConfig configures a 2D KindDolly virtual camera moving along Path.
type Dolly3DConfig ¶
type Dolly3DConfig struct {
Path math3d.Curve3D
Speed float32 // Arc-length speed in world units/s when FollowNode/FollowFunc are nil.
Loop bool
PingPong bool
Distance float32 // Current arc-length distance along Path.
PathOffset float32 // Arc-length offset added when tracking FollowNode/FollowFunc.
Orient DollyOrient
FollowNode *scene3d.Node
FollowFunc func() math3d.Vec3
AimTarget math3d.Vec3
AimNode *scene3d.Node
AimFunc func() math3d.Vec3
FixedRot math3d.Quat
Up math3d.Vec3
Smoothing float32 // Exponential smoothing rate (1/s) when tracking a target.
StepWhenInactive bool
ResetOnActivate bool
// contains filtered or unexported fields
}
Dolly3DConfig configures a 3D KindDolly virtual camera moving along Path.
type DollyOrient ¶
type DollyOrient uint8
DollyOrient selects how a 3D Dolly virtual camera orients itself along its path.
const ( // DollyOrientTangent orients the camera along the curve's Rotation-Minimizing Frame tangent. DollyOrientTangent DollyOrient = iota // DollyOrientLookAt aims the camera at AimTarget / AimNode / AimFunc. DollyOrientLookAt // DollyOrientFixed keeps FixedRot unchanged along the path. DollyOrientFixed )
type Fixed3DConfig ¶
type Fixed3DConfig struct {
Pos math3d.Vec3
Rot math3d.Quat
Node *scene3d.Node // Optional node synced every step when non-nil.
}
Fixed3DConfig configures a 3D KindFixed virtual camera.
type Group2DConfig ¶
type Group2DConfig struct {
Targets []GroupTarget2D
Padding float32
MinZoom float32
MaxZoom float32
PositionSpeed float32
ZoomSpeed float32
Bounds *core.Bounds
// contains filtered or unexported fields
}
Group2DConfig configures a 2D KindGroup virtual camera framing weighted targets.
type Group3DConfig ¶
type Group3DConfig struct {
Targets []GroupTarget3D
Mode GroupFramingMode
Padding float32
Distance float32
MinDistance float32
MaxDistance float32 // <= 0 means unbounded.
MinFOV float32 // Radians; defaults to 25° when <= 0.
MaxFOV float32 // Radians; defaults to 100° when <= 0.
MinOrthoHeight float32
MaxOrthoHeight float32 // <= 0 means unbounded.
Yaw float32 // Radians around +Y when UseRot is false.
Pitch float32 // Radians elevation above centroid when UseRot is false.
Rot math3d.Quat
UseRot bool
LookAtCentroid bool
PositionSmoothing float32
ZoomSmoothing float32
// contains filtered or unexported fields
}
Group3DConfig configures a 3D KindGroup virtual camera framing weighted targets.
type GroupFramingMode ¶
type GroupFramingMode uint8
GroupFramingMode selects how a 3D Group virtual camera fits its targets in view.
const ( // GroupFrameDistance adjusts camera distance within [MinDistance, MaxDistance]. GroupFrameDistance GroupFramingMode = iota // GroupFrameFOV adjusts perspective FOVY within [MinFOV, MaxFOV] (or OrthoHeight for orthographic cameras). GroupFrameFOV // GroupFrameBoth adjusts distance up to MaxDistance first, then widens FOV up to MaxFOV if targets spread further. GroupFrameBoth )
type GroupTarget2D ¶
type GroupTarget2D struct {
Pos core.Point
PosFunc func() core.Point
Weight float32 // Default 1 when 0; negative or Disabled excludes the target.
Radius float32 // Bounding radius around the target in world points.
Disabled bool
}
GroupTarget2D is one weighted target framed by a 2D KindGroup virtual camera.
type GroupTarget3D ¶
type GroupTarget3D struct {
Node *scene3d.Node
Pos math3d.Vec3
PosFunc func() math3d.Vec3
Weight float32 // Default 1 when 0; negative or Disabled excludes the target.
Radius float32 // Bounding radius around the target in world units.
Disabled bool
}
GroupTarget3D is one weighted target framed by a 3D KindGroup virtual camera.
type ImpulseProfile ¶
type ImpulseProfile struct {
// PositionAmplitude is the maximum per-axis world-space displacement at strength 1.
PositionAmplitude math3d.Vec3
// RotationAmplitude is the maximum Euler rotation shake in radians (X=pitch, Y=yaw, Z=roll) at strength 1.
// In 2D mode, RotationAmplitude.Z controls clockwise camera roll.
RotationAmplitude math3d.Vec3
// Frequency is the smooth value-noise sampling frequency in cycles per second (defaults to 18 when <= 0).
Frequency float32
// Decay is the linear impulse strength decay rate per second (defaults to 2.5 when <= 0).
Decay float32
}
ImpulseProfile configures the noise shape and decay of a camera impulse hit.
func DefaultImpulseProfile ¶
func DefaultImpulseProfile() ImpulseProfile
DefaultImpulseProfile returns balanced 3D impulse shake settings.
func DefaultImpulseProfile2D ¶
func DefaultImpulseProfile2D() ImpulseProfile
DefaultImpulseProfile2D returns balanced 2D impulse shake settings in world points and radians.
type ImpulseSource ¶
type ImpulseSource struct {
Profile ImpulseProfile
// Seed seeds deterministic noise channels; 0 uses a fixed default seed.
Seed uint64
// Position is the world position of the impulse source when HasPosition is true.
Position math3d.Vec3
// HasPosition enables distance attenuation using MaxDistance against the active camera position.
HasPosition bool
// MaxDistance is the radius beyond which spatial impulses attenuate to zero (<= 0 disables attenuation).
MaxDistance float32
}
ImpulseSource describes an impulse emitter with a noise profile, deterministic seed, and optional spatial falloff.
type Kind ¶
type Kind uint8
Kind identifies the behavior of a VirtualCamera.
const ( // KindFixed holds a fixed pose (or tracks a single node/callback directly). KindFixed Kind = iota // KindOrbit wraps a scene3d.OrbitController (3D). KindOrbit // KindFPS wraps a scene3d.FPSController (3D). KindFPS // KindThirdPerson wraps a scene3d.ThirdPersonController (3D). KindThirdPerson // KindFollow2D wraps a tilemap.CameraRig (2D). KindFollow2D // KindLookAt positions the camera and aims it at a target (3D). KindLookAt // KindDolly moves the camera along a 3D math3d.Curve3D or 2D tween.BezierPath. KindDolly // KindGroup frames weighted targets by adjusting distance, FOV, or 2D zoom with padding. KindGroup // KindCustom evaluates a user-supplied callback each step. KindCustom )
type LookAt3DConfig ¶
type LookAt3DConfig struct {
Pos math3d.Vec3
FollowNode *scene3d.Node
FollowFunc func() math3d.Vec3
FollowOffset math3d.Vec3
FollowSmoothing float32
AimTarget math3d.Vec3
AimNode *scene3d.Node
AimFunc func() math3d.Vec3
AimOffset math3d.Vec3
AimSmoothing float32
Up math3d.Vec3
// contains filtered or unexported fields
}
LookAt3DConfig configures a 3D KindLookAt virtual camera.
type Path3D ¶
type Path3D struct {
// contains filtered or unexported fields
}
Path3D is a multi-segment arc-length parameterized 3D cubic Bézier curve implementing math3d.Curve3D.
func NewPath3D ¶
func NewPath3D(points []PathPoint3D, closed bool) *Path3D
NewPath3D builds a multi-segment cubic Bézier Path3D from points. At least 2 points are required for non-empty segments; fewer than 2 points produces a zero-length degenerate path at the single point or origin.
func (*Path3D) DistanceToT ¶
DistanceToT converts arc-length distance to normalized t in [0, 1].
func (*Path3D) FrameAt ¶
FrameAt evaluates a smooth Rotation-Minimizing Frame at normalized progress t in [0, 1].
func (*Path3D) FrameAtDistance ¶
func (p *Path3D) FrameAtDistance(dist float32) math3d.CurveFrame
FrameAtDistance evaluates a Rotation-Minimizing Frame at arc-length distance dist.
func (*Path3D) Point ¶
Point evaluates the 3D position at normalized arc-length progress t in [0, 1].
func (*Path3D) PointAtDistance ¶
PointAtDistance evaluates the 3D position at arc-length distance dist.
type PathPoint3D ¶
type PathPoint3D struct {
Pos math3d.Vec3
In math3d.Vec3
Out math3d.Vec3
Tilt float32 // Roll angle around the path tangent in radians.
}
PathPoint3D is one control point of a multi-segment 3D cubic Bézier path. In and Out are handle offsets relative to Pos.
type Pose2D ¶
Pose2D is one evaluated 2D camera pose written into a tilemap.Camera.
type VirtualCamera ¶
type VirtualCamera struct {
Name string
Dimension Dimension
Kind Kind
Projection scene3d.Projection
MotionBlur bool
// Confiner optionally confines this virtual camera's 3D pose before blending.
Confiner *Confiner3D
Fixed3D Fixed3DConfig
// Orbit controller state and optional live target tracking (KindOrbit).
Orbit *scene3d.OrbitController
OrbitTargetNode *scene3d.Node
OrbitTargetFunc func() math3d.Vec3
OrbitTargetOffset math3d.Vec3
ObstructionCheck func(from, to math3d.Vec3) (float32, bool)
ObstructionPadding float32
OrbitMinDistance float32
// FPS controller (KindFPS).
FPS *scene3d.FPSController
// ThirdPerson controller and live target tracking (KindThirdPerson).
ThirdPerson *scene3d.ThirdPersonController
ThirdTargetNode *scene3d.Node
ThirdTargetFunc func() (pos, forward math3d.Vec3)
LookAt3D LookAt3DConfig
Dolly3D Dolly3DConfig
Group3D Group3DConfig
// 2D settings.
Fixed2D Pose2D
Fixed2DFn func() core.Point
Rig2D *tilemap.CameraRig
Rig2DFunc func() (pos, vel core.Point, rot float32)
Rig2DPosFn func() core.Point
Bounds2D *core.Bounds
Dolly2D Dolly2DConfig
Group2D Group2DConfig
Custom3D func(dt time.Duration) scene3d.Camera
Custom2D func(dt time.Duration) Pose2D
// contains filtered or unexported fields
}
VirtualCamera represents one virtual camera configuration and live state managed by a Director.
func NewDolly2D ¶
func NewDolly2D(name string, path *tween.BezierPath) *VirtualCamera
NewDolly2D returns a 2D KindDolly virtual camera moving along path.
func NewDolly3D ¶
func NewDolly3D(name string, path math3d.Curve3D) *VirtualCamera
NewDolly3D returns a 3D KindDolly virtual camera moving along path.
func NewFPS3D ¶
func NewFPS3D(name string, fps *scene3d.FPSController) *VirtualCamera
NewFPS3D returns a 3D KindFPS virtual camera wrapping fps (creating one if nil).
func NewFixed2D ¶
func NewFixed2D(name string, x, y, zoom float32) *VirtualCamera
NewFixed2D returns a 2D KindFixed virtual camera centered at (x, y) with zoom.
func NewFixed3D ¶
NewFixed3D returns a 3D KindFixed virtual camera at pos with rotation rot.
func NewFunc2D ¶
func NewFunc2D(name string, fn func(dt time.Duration) Pose2D) *VirtualCamera
NewFunc2D returns a 2D KindCustom virtual camera driven by fn.
func NewGroup2D ¶
func NewGroup2D(name string, targets ...GroupTarget2D) *VirtualCamera
NewGroup2D returns a 2D KindGroup virtual camera framing targets.
func NewGroup3D ¶
func NewGroup3D(name string, targets ...GroupTarget3D) *VirtualCamera
NewGroup3D returns a 3D KindGroup virtual camera framing targets.
func NewLookAt3D ¶
func NewLookAt3D(name string, pos, target math3d.Vec3) *VirtualCamera
NewLookAt3D returns a 3D KindLookAt virtual camera at pos aimed at target.
func NewOrbit3D ¶
func NewOrbit3D(name string, orbit *scene3d.OrbitController) *VirtualCamera
NewOrbit3D returns a 3D KindOrbit virtual camera wrapping orbit (creating one if nil).
func NewRig2D ¶
func NewRig2D(name string, rig *tilemap.CameraRig) *VirtualCamera
NewRig2D returns a 2D KindFollow2D virtual camera wrapping a tilemap.CameraRig.
func NewThirdPerson3D ¶
func NewThirdPerson3D(name string, tp *scene3d.ThirdPersonController) *VirtualCamera
NewThirdPerson3D returns a 3D KindThirdPerson virtual camera wrapping tp (creating one if nil).
func (*VirtualCamera) DollyProgress ¶
func (v *VirtualCamera) DollyProgress() float32
DollyProgress returns the current normalized progress along a KindDolly path in [0, 1].
func (*VirtualCamera) Enabled ¶
func (v *VirtualCamera) Enabled() bool
Enabled reports whether v participates in Director priority arbitration.
func (*VirtualCamera) Pose2D ¶
func (v *VirtualCamera) Pose2D() Pose2D
Pose2D returns the last evaluated 2D camera pose of v.
func (*VirtualCamera) Pose3D ¶
func (v *VirtualCamera) Pose3D() scene3d.Camera
Pose3D returns the last evaluated 3D camera pose of v.
func (*VirtualCamera) SetDollyProgress ¶
func (v *VirtualCamera) SetDollyProgress(t float32)
SetDollyProgress seeks a KindDolly virtual camera (2D or 3D) to normalized progress t in [0, 1].
func (*VirtualCamera) SetEnabled ¶
func (v *VirtualCamera) SetEnabled(enabled bool)
SetEnabled enables or disables v for Director priority arbitration.
func (*VirtualCamera) SetTarget2D ¶
SetTarget2D forwards a manual target step to a KindFollow2D rig (or sets Fixed2D position when Rig2D is nil).
func (*VirtualCamera) SetTarget3D ¶
func (v *VirtualCamera) SetTarget3D(pos, forward math3d.Vec3)
SetTarget3D updates the manual target position and forward direction for a KindThirdPerson or KindOrbit virtual camera.
func (*VirtualCamera) Snap ¶
func (v *VirtualCamera) Snap()
Snap immediately settles smoothing on v to its current target pose.