Documentation ¶
Overview ¶
Package ray holds utilities for performing iterative collision checks or raycasts
Index ¶
- Variables
- func Cast(origin, angle floatgeom.Point2) []collision.Point
- func CastTo(origin, target floatgeom.Point2) []collision.Point
- func ConeCast(origin, angle floatgeom.Point2) []collision.Point
- func ConeCastTo(origin, target floatgeom.Point2) []collision.Point
- func SetDefaultCaster(caster *Caster)
- func SetDefaultConeCaster(coneCaster *ConeCaster)
- type CastFilter
- type CastLimit
- type CastOption
- func AcceptIDs(ids ...event.CID) CastOption
- func AcceptLabels(ls ...collision.Label) CastOption
- func AddFilter(cf CastFilter) CastOption
- func AddLimit(cl CastLimit) CastOption
- func CenterPoints(on bool) CastOption
- func Distance(dist float64) CastOption
- func IgnoreIDs(ids ...event.CID) CastOption
- func IgnoreLabels(ls ...collision.Label) CastOption
- func LimitResults(limit int) CastOption
- func Pierce(n int) CastOption
- func PointSize(ps floatgeom.Point2) CastOption
- func PointSpan(span float64) CastOption
- func StopAtID(ids ...event.CID) CastOption
- func StopAtLabel(ls ...collision.Label) CastOption
- func Tree(t *collision.Tree) CastOption
- type Caster
- type ConeCastOption
- type ConeCaster
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCaster is a global caster that all // NewCaster() calls are built on before options are applied. DefaultCaster = &Caster{ PointSize: floatgeom.Point2{.1, .1}, PointSpan: 1.0, CastDistance: 200, Tree: collision.DefTree, } )
var ( // DefaultConeCaster is a global caster that all NewConeCaster() // calls are built on before options are applied. DefaultConeCaster = &ConeCaster{ Caster: DefaultCaster, CenterCone: true, ConeSpread: 1, Rays: 1, } )
Functions ¶
func ConeCastTo ¶
ConeCastTo calls DefaultConeCaster.CastTo. See (*ConeCaster).CastTo
func SetDefaultCaster ¶
func SetDefaultCaster(caster *Caster)
SetDefaultCaster sets the global caster to be the input, and sets the caster behind the global cone caster as well.
func SetDefaultConeCaster ¶
func SetDefaultConeCaster(coneCaster *ConeCaster)
SetDefaultConeCaster is analogous to SetDefaultCaster, however is equivalent to setting the global variable.
Types ¶
type CastFilter ¶
A CastFilter is a function that can be applied to a Caster for each space the Caster's rays hit, returning whether or not those spaces should be contained in the Caster's output.
type CastLimit ¶
A CastLimit is a function that can be applied to a Caster's points to return after it adds each one. If a Limit returns false, that Caster will immediately cease casting.
If a Caster's ray collides with multiple spaces at the same point, and some of them would pass a CastLimit, but others would not, a Caster will not reliably return those that would pass the limit.
type CastOption ¶
type CastOption func(*Caster)
A CastOption represents a transformation to a ray caster.
func AcceptIDs ¶
func AcceptIDs(ids ...event.CID) CastOption
AcceptIDs is equivalent to AcceptLabels, but for CIDs.
func AcceptLabels ¶
func AcceptLabels(ls ...collision.Label) CastOption
AcceptLabels signals to a Caster to only return spaces that have a space in the set of input labels. If anything in ls is also contained by an IgnoreLabels filter on the applied Caster, Ignore will dominate.
func AddFilter ¶
func AddFilter(cf CastFilter) CastOption
AddFilter is a utility to convert a CastFilter to a CastOption.
func AddLimit ¶
func AddLimit(cl CastLimit) CastOption
AddLimit is a helper for converting a CastLimit into a CastOption.
func CenterPoints ¶
func CenterPoints(on bool) CastOption
CenterPoints sets whether a Caster should center its collision points that form its ray. This is by default false, and is only significant if said points' dimensions are significantly large.
func Distance ¶
func Distance(dist float64) CastOption
Distance determines how far a caster will project rays before stopping
func IgnoreIDs ¶
func IgnoreIDs(ids ...event.CID) CastOption
IgnoreIDs is equivalent to IgnoreLabels, but for CIDs.
func IgnoreLabels ¶
func IgnoreLabels(ls ...collision.Label) CastOption
IgnoreLabels signals to a Caster to not return spaces that have spaces with labels in the set of input labels.
func LimitResults ¶
func LimitResults(limit int) CastOption
LimitResults will cause a Caster to return a limited number of collision points.
func Pierce ¶
func Pierce(n int) CastOption
Pierce signals to a Caster to ignore the first n spaces its rays collide with, regardless of their composition.
func PointSize ¶
func PointSize(ps floatgeom.Point2) CastOption
PointSize determines the size of a caster's collision checks
func PointSpan ¶
func PointSpan(span float64) CastOption
PointSpan determines the distance between collision check points
func StopAtID ¶
func StopAtID(ids ...event.CID) CastOption
StopAtID will cause a caster to cease casting as soon as it hits one of the input CIDs.
func StopAtLabel ¶
func StopAtLabel(ls ...collision.Label) CastOption
StopAtLabel will cause a caster to cease casting as soon as it hits one of the input labels.
type Caster ¶
type Caster struct { Filters []CastFilter Limits []CastLimit PointSize floatgeom.Point2 PointSpan float64 CastDistance float64 Tree *collision.Tree CenterPoints bool }
A Caster can cast rays and return the colliding collision points of rays cast from points at angles. This behavior is customizable through CastOptions.
func NewCaster ¶
func NewCaster(opts ...CastOption) *Caster
NewCaster will copy and modify the DefaultCaster by the input options and return the modified Caster. Giving no inputs is valid.
func (*Caster) Cast ¶
Cast creates a ray from origin pointing at the given angle and returns some spaces collided with at the point of collision, given the settings of this Caster. By default, all spaces hit will be returned.
type ConeCastOption ¶
type ConeCastOption func(*ConeCaster)
A ConeCastOption represents a transformation on a ConeCaster.
func CenterCone ¶
func CenterCone(on bool) ConeCastOption
CenterCone sets whether the caster should center its cones around the input angles or progress out from those input angles. True by default.
func ConeRays ¶
func ConeRays(rays int) ConeCastOption
ConeRays sets how many rays a ConeCaster should divide its spread into.
func ConeSpread ¶
func ConeSpread(degrees float64) ConeCastOption
ConeSpread sets how far a ConeCaster should progress its angles in degrees.
func ConeSpreadRadians ¶
func ConeSpreadRadians(radians float64) ConeCastOption
ConeSpreadRadians sets how far a ConeCaster should progress its angles in radians.
type ConeCaster ¶
type ConeCaster struct { *Caster CenterCone bool // ConeSpread is represented in radians ConeSpread float64 Rays float64 }
A ConeCaster will repeatedly Cast its underlying Caster in a cone shape.
func NewConeCaster ¶
func NewConeCaster(opts ...ConeCastOption) *ConeCaster
NewConeCaster copies the DefaultConeCaster and modifies it with the input options, returning the modified Caster. Zero arguments is valid input.
func (*ConeCaster) Cast ¶
func (cc *ConeCaster) Cast(origin, angle floatgeom.Point2) []collision.Point
Cast creates a ray from origin pointing at the given angle and returns some spaces collided with at the point of collision, given the settings of this ConeCaster. By default, all spaces hit will be returned. ConeCasters in addition will recast at progressive angles until they have cast up to their Rays value. Angles progress in counter-clockwise order.