core

package
v0.0.0-...-585686a Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2017 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package core implements some basic types used by other packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(string, interface{})

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher() *Dispatcher

NewEventDispatcher creates and returns a pointer to an Event Dispatcher

func (*Dispatcher) CancelDispatch

func (ed *Dispatcher) CancelDispatch()

CancelDispatch cancels the propagation of the current event. No more subscribers will be called for this event dispatch.

func (*Dispatcher) ClearSubscriptions

func (ed *Dispatcher) ClearSubscriptions()

ClearSubscriptions clear all subscriptions from this dispatcher

func (*Dispatcher) Dispatch

func (ed *Dispatcher) Dispatch(evname string, ev interface{}) bool

Dispatch dispatch the specified event and data to all registered subscribers. The function returns true if the propagation was cancelled by a subscriber.

func (*Dispatcher) Initialize

func (ed *Dispatcher) Initialize()

Initialize initializes this event dispatcher. It is normally used by other types which embed an event dispatcher

func (*Dispatcher) Subscribe

func (ed *Dispatcher) Subscribe(evname string, cb Callback)

Subscribe subscribes to receive events with the given name. If it is necessary to unsubscribe the event, the function SubscribeID should be used.

func (*Dispatcher) SubscribeID

func (ed *Dispatcher) SubscribeID(evname string, id interface{}, cb Callback)

Subscribe subscribes to receive events with the given name. The function accepts a unique id to be use to unsubscribe this event

func (*Dispatcher) UnsubscribeID

func (ed *Dispatcher) UnsubscribeID(evname string, id interface{}) int

Unsubscribe unsubscribes from the specified event and subscription id Returns the number of subscriptions found.

type IDispatcher

type IDispatcher interface {
	Subscribe(evname string, cb Callback)
	SubscribeID(evname string, id interface{}, cb Callback)
	UnsubscribeID(evname string, id interface{}) int
	Dispatch(evname string, ev interface{}) bool
	ClearSubscriptions()
	CancelDispatch()
}

type INode

type INode interface {
	GetNode() *Node
	UpdateMatrixWorld()
	Raycast(*Raycaster, *[]Intersect)
	Render(gs *gls.GLS)
	Dispose()
}

Interface for all node types

type Intersect

type Intersect struct {
	// Distance between the origin of the ray and the intersect
	Distance float32
	// Point of intersection in world coordinates
	Point math32.Vector3
	// Intersected node
	Object INode
	// If the geometry has indices, this field is the
	// index in the Indices buffer of the vertex intersected
	// or the first vertex of the intersected face.
	// If the geometry doesn't have indices, this field is the
	// index in the positions buffer of the vertex intersected
	// or the first vertex of the insersected face.
	Index uint32
}

Intersect describes the intersection between a ray and an object

type Intersects

type Intersects []Intersect

For sorting Intersects by distance

func (Intersects) Len

func (is Intersects) Len() int

func (Intersects) Less

func (is Intersects) Less(i, j int) bool

func (Intersects) Swap

func (is Intersects) Swap(i, j int)

type Node

type Node struct {
	Dispatcher // Embedded event dispatcher
	// contains filtered or unexported fields
}

func NewNode

func NewNode() *Node

NewNode creates and returns a pointer to a new Node

func (*Node) Add

func (n *Node) Add(ichild INode) *Node

Add adds the specified INode to this node list of children

func (*Node) AddRotationX

func (n *Node) AddRotationX(x float32)

AddRotationX adds to the current rotation x coordinate in radians The node quaternion is updated

func (*Node) AddRotationY

func (n *Node) AddRotationY(y float32)

AddRotationY adds to the current rotation y coordinate in radians The node quaternion is updated

func (*Node) AddRotationZ

func (n *Node) AddRotationZ(z float32)

AddRotationZ adds to the current rotation z coordinate in radians The node quaternion is updated

func (*Node) Children

func (n *Node) Children() []INode

Children returns the list of this node children

func (*Node) Direction

func (n *Node) Direction() math32.Vector3

Direction returns this node initial direction

func (*Node) Dispose

func (n *Node) Dispose()

Dispose satisfies the INode interface

func (*Node) DisposeChildren

func (n *Node) DisposeChildren(recurs bool)

DisposeChildren removes and disposes all children of this node and if 'recurs' is true for each of its children recursively.

func (*Node) FindLoaderID

func (n *Node) FindLoaderID(id string) INode

FindLoaderID looks in the specified node and all its children for a node with the specifid loaderID and if found returns it. Returns nil if not found

func (*Node) GetNode

func (n *Node) GetNode() *Node

GetNode satisfies the INode interface and returns a pointer to the embedded Node

func (*Node) Init

func (n *Node) Init()

Init initializes this Node It is normally use by other types which embed a Node

func (*Node) LoaderID

func (n *Node) LoaderID() string

LoaderID returns an optional ID set when this node was created by an external loader such as Collada

func (*Node) Matrix

func (n *Node) Matrix() math32.Matrix4

Matrix returns a copy of this node local transformation matrix

func (*Node) MatrixWorld

func (n *Node) MatrixWorld() math32.Matrix4

MatrixWorld returns a copy of this node matrix world

func (*Node) Name

func (n *Node) Name() string

Name returns current optional name for this node

func (*Node) Parent

func (n *Node) Parent() INode

Parent returns this node parent

func (*Node) Position

func (n *Node) Position() math32.Vector3

Position returns the current node position as a vector

func (*Node) Quaternion

func (n *Node) Quaternion() math32.Quaternion

Quaternion returns the current quaternion

func (*Node) QuaternionMult

func (n *Node) QuaternionMult(q *math32.Quaternion)

QuaternionMult multiplies the quaternion by the specified quaternion

func (*Node) Raycast

func (n *Node) Raycast(rc *Raycaster, intersects *[]Intersect)

Raycast satisfies the INode interface

func (*Node) Remove

func (n *Node) Remove(ichild INode) bool

Remove removes the specified INode from this node list of children Returns true if found or false otherwise

func (*Node) RemoveAll

func (n *Node) RemoveAll(recurs bool)

RemoveAll removes all children from this node

func (*Node) Render

func (n *Node) Render(gs *gls.GLS)

Render satisfies the INode interface

func (*Node) Rotation

func (n *Node) Rotation() math32.Vector3

Rotation returns the current rotation

func (*Node) Scale

func (n *Node) Scale() math32.Vector3

Scale returns the current scale

func (*Node) SetDirection

func (n *Node) SetDirection(x, y, z float32)

SetDirection sets this node initial direction vector

func (*Node) SetDirectionv

func (n *Node) SetDirectionv(vdir *math32.Vector3)

SetDirection sets this node initial direction vector

func (*Node) SetLoaderID

func (n *Node) SetLoaderID(id string)

SetLoaderID is normally used by external loaders, such as Collada, to assign an ID to the node with the ID value in the node description Can be used to find other loaded nodes.

func (*Node) SetMatrix

func (n *Node) SetMatrix(m *math32.Matrix4)

SetMatrix sets this node local transformation matrix

func (*Node) SetName

func (n *Node) SetName(name string)

SetName set an option name for the node. This name can be used for debugging or other purposes.

func (*Node) SetParent

func (n *Node) SetParent(iparent INode)

SetParent sets this node parent

func (*Node) SetPosition

func (n *Node) SetPosition(x, y, z float32)

SetPosition sets this node world position

func (*Node) SetPositionVec

func (n *Node) SetPositionVec(vpos *math32.Vector3)

SetPositionVec sets this node position from the specified vector pointer

func (*Node) SetPositionX

func (n *Node) SetPositionX(x float32)

SetPositionX sets the x coordinate of this node position

func (*Node) SetPositionY

func (n *Node) SetPositionY(y float32)

SetPositionY sets the y coordinate of this node position

func (*Node) SetPositionZ

func (n *Node) SetPositionZ(z float32)

SetPositionZ sets the z coordinate of this node position

func (*Node) SetQuaternion

func (n *Node) SetQuaternion(x, y, z, w float32)

SetQuaternion sets this node quaternion with the specified fields

func (*Node) SetQuaternionQuat

func (n *Node) SetQuaternionQuat(q *math32.Quaternion)

SetQuaternionQuat sets this node quaternion from the specified quaternion pointer

func (*Node) SetRotation

func (n *Node) SetRotation(x, y, z float32)

SetRotation sets the three fields of the node rotation in radians The node quaternion is updated

func (*Node) SetRotationX

func (n *Node) SetRotationX(x float32)

SetRotationX sets the x rotation angle in radians The node quaternion is updated

func (*Node) SetRotationY

func (n *Node) SetRotationY(y float32)

SetRotationY sets the y rotation angle in radians The node quaternion is updated

func (*Node) SetRotationZ

func (n *Node) SetRotationZ(z float32)

SetRotationZ sets the z rotation angle in radians The node quaternion is updated

func (*Node) SetScale

func (n *Node) SetScale(x, y, z float32)

SetScale sets this node scale fields

func (*Node) SetScaleVec

func (n *Node) SetScaleVec(scale *math32.Vector3)

SetScaleVec sets this node scale from a pointer to a Vector3

func (*Node) SetScaleX

func (n *Node) SetScaleX(sx float32)

SetScaleX sets the X scale of this node

func (*Node) SetScaleY

func (n *Node) SetScaleY(sy float32)

SetScaleY sets the Y scale of this node

func (*Node) SetScaleZ

func (n *Node) SetScaleZ(sz float32)

SetScaleZ sets the Z scale of this node

func (*Node) SetUserData

func (n *Node) SetUserData(data interface{})

SetUserData sets this node associated generic user data

func (*Node) SetVisible

func (n *Node) SetVisible(state bool)

SetVisible sets the node visibility state

func (*Node) UpdateMatrix

func (n *Node) UpdateMatrix()

UpdateMatrix updates this node local matrix transform from its current position, quaternion and scale.

func (*Node) UpdateMatrixWorld

func (n *Node) UpdateMatrixWorld()

UpdateMatrixWorld updates this node world transform matrix and of all its children

func (*Node) UserData

func (n *Node) UserData() interface{}

UserData returns this node associated generic user data

func (*Node) Visible

func (n *Node) Visible() bool

Visible returns the node visibility state

func (*Node) WorldDirection

func (n *Node) WorldDirection(result *math32.Vector3)

WorldDirection updates this object world matrix and sets the current world direction.

func (*Node) WorldPosition

func (n *Node) WorldPosition(result *math32.Vector3)

WorldPosition updates this node world matrix and gets the current world position vector.

func (*Node) WorldQuaternion

func (n *Node) WorldQuaternion(result *math32.Quaternion)

WorldQuaternion sets the specified result quaternion with this node current world quaternion

func (*Node) WorldRotation

func (n *Node) WorldRotation(result *math32.Vector3)

WorldRotation sets the specified result vector with current world rotation of this node in Euler angles.

func (*Node) WorldScale

func (n *Node) WorldScale(result *math32.Vector3)

WorldScale sets the specified result vector with the current world scale of this node

type Raycaster

type Raycaster struct {
	// The distance from the ray origin to the intersected points
	// must be greater than the value of this field to be considered.
	// The defaul value is 0.0
	Near float32
	// The distance from the ray origin to the intersected points
	// must be less than the value of this field to be considered.
	// The defaul value is +Infinity.
	Far float32
	// Minimum distance in world coordinates between the ray and
	// a line segment when checking intersects with lines.
	// The default value is 0.1
	LinePrecision float32
	// Minimum distance in world coordinates between the ray and
	// a point when checking intersects with points.
	// The default value is 0.1
	PointPrecision float32
	// This field must be set with the camera view matrix used
	// when checking for sprite intersections.
	// It is set automatically when using camera.SetRaycaster
	ViewMatrix math32.Matrix4
	// Embedded ray
	math32.Ray
}

func NewRaycaster

func NewRaycaster(origin, direction *math32.Vector3) *Raycaster

New creates and returns a pointer to a new raycaster object with the specified origin and direction.

func (*Raycaster) IntersectObject

func (rc *Raycaster) IntersectObject(inode INode, recursive bool) []Intersect

IntersectObject checks intersections between this raycaster and and the specified node. If recursive is true, it also checks the intersection with the node's children. Intersections are returned sorted by distance, closest first.

func (*Raycaster) IntersectObjects

func (rc *Raycaster) IntersectObjects(inodes []INode, recursive bool) []Intersect

IntersectObjects checks intersections between this raycaster and the specified array of scene nodes. If recursive is true, it also checks the intersection with each nodes' children. Intersections are returned sorted by distance, closest first.

type RenderInfo

type RenderInfo struct {
	ViewMatrix math32.Matrix4 // Current camera view matrix
	ProjMatrix math32.Matrix4 // Current camera projection matrix
}

type TimerCallback

type TimerCallback func(interface{})

Type for timer callback functions

type TimerManager

type TimerManager struct {
	// contains filtered or unexported fields
}

func NewTimerManager

func NewTimerManager() *TimerManager

NewTimerManager creates and returns a new timer manager

func (*TimerManager) ClearTimeout

func (tm *TimerManager) ClearTimeout(id int) bool

ClearTimeout clears the timeout specified by the id. Returns true if the timeout is found.

func (*TimerManager) Initialize

func (tm *TimerManager) Initialize()

Initialize initializes the timer manager. It is normally used when the TimerManager is embedded in another type.

func (*TimerManager) ProcessTimers

func (tm *TimerManager) ProcessTimers()

ProcessTimers should be called periodically to process the timers

func (*TimerManager) SetInterval

func (tm *TimerManager) SetInterval(td time.Duration, arg interface{}, cb TimerCallback) int

SetInterval sets a periodic timeout with the specified duration and callback The function returns the timeout id which can be used to cancel the timeout

func (*TimerManager) SetTimeout

func (tm *TimerManager) SetTimeout(td time.Duration, arg interface{}, cb TimerCallback) int

SetTimeout sets a timeout with the specified duration and callback The function returns the timeout id which can be used to cancel the timeout

Jump to

Keyboard shortcuts

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