engine: github.com/g3n/engine/core Index | Files

package core

import "github.com/g3n/engine/core"

Package core implements some basic types used by other packages.

Index

Package Files

RenderInfo.go dispatcher.go doc.go logger.go node.go raycaster.go timer.go

type Callback Uses

type Callback func(string, interface{})

Callback is the type for the Dispatcher callbacks functions

type Dispatcher Uses

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

Dispatcher implements an event dispatcher

func NewDispatcher Uses

func NewDispatcher() *Dispatcher

NewDispatcher creates and returns a new Event Dispatcher

func (*Dispatcher) CancelDispatch Uses

func (d *Dispatcher) CancelDispatch()

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

func (*Dispatcher) ClearSubscriptions Uses

func (d *Dispatcher) ClearSubscriptions()

ClearSubscriptions clear all subscriptions from this dispatcher

func (*Dispatcher) Dispatch Uses

func (d *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 Uses

func (d *Dispatcher) Initialize()

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

func (*Dispatcher) Subscribe Uses

func (d *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 Uses

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

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

func (*Dispatcher) UnsubscribeAllID Uses

func (d *Dispatcher) UnsubscribeAllID(id interface{}) int

UnsubscribeAllID unsubscribes from all events with the specified subscription id. Returns the number of subscriptions found.

func (*Dispatcher) UnsubscribeID Uses

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

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

type IDispatcher Uses

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()
}

IDispatcher is the interface for dispatchers

type INode Uses

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

INode is the interface for all node types.

type Intersect Uses

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 Node Uses

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

Node represents an object in 3D space existing within a hierarchy.

func NewNode Uses

func NewNode() *Node

NewNode returns a pointer to a new Node.

func (*Node) Add Uses

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

Add adds the specified node to the list of children and sets its parent pointer. If the specified node had a parent, the specified node is removed from the original parent's list of children.

func (*Node) AddAt Uses

func (n *Node) AddAt(idx int, ichild INode)

AddAt adds the specified node to the list of children at the specified index and sets its parent pointer. If the specified node had a parent, the specified node is removed from the original parent's list of children.

func (*Node) BoundingBox Uses

func (n *Node) BoundingBox() math32.Box3

BoundingBox satisfies the INode interface.

func (*Node) Changed Uses

func (n *Node) Changed() bool

Changed returns the matNeedsUpdate flag of the node.

func (*Node) ChildAt Uses

func (n *Node) ChildAt(idx int) INode

ChildAt returns the child at the specified index.

func (*Node) ChildIndex Uses

func (n *Node) ChildIndex(ichild INode) int

ChildIndex returns the index of the specified child (-1 if not found).

func (*Node) Children Uses

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

Children returns the list of children.

func (*Node) Clone Uses

func (n *Node) Clone() INode

Clone clones the Node and satisfies the INode interface.

func (*Node) Direction Uses

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

Direction returns the direction.

func (*Node) Dispose Uses

func (n *Node) Dispose()

Dispose satisfies the INode interface.

func (*Node) DisposeChildren Uses

func (n *Node) DisposeChildren(recurs bool)

DisposeChildren removes and disposes of all children. If 'recurs' is true, call DisposeChildren on each child recursively.

func (*Node) FindLoaderID Uses

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

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

func (*Node) FindPath Uses

func (n *Node) FindPath(path string) INode

FindPath finds a node with the specified path starting with this node and searching in all its children recursively. A path is the sequence of the names from the first node to the desired node separated by the forward slash.

func (*Node) GetNode Uses

func (n *Node) GetNode() *Node

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

func (*Node) Init Uses

func (n *Node) Init()

Init initializes the node. Normally called by other types which embed a Node.

func (*Node) LoaderID Uses

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 Uses

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

Matrix returns a copy of the local transformation matrix.

func (*Node) MatrixWorld Uses

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

MatrixWorld returns a copy of the matrix world of this node.

func (*Node) Name Uses

func (n *Node) Name() string

Name returns the (optional) name.

func (*Node) Parent Uses

func (n *Node) Parent() INode

Parent returns the parent.

func (*Node) Position Uses

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

Position returns the position as a vector.

func (*Node) Quaternion Uses

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

Quaternion returns the current quaternion.

func (*Node) QuaternionMult Uses

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

QuaternionMult multiplies the current quaternion by the specified quaternion.

func (*Node) Raycast Uses

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

Raycast satisfies the INode interface.

func (*Node) Remove Uses

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

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

func (*Node) RemoveAll Uses

func (n *Node) RemoveAll(recurs bool)

RemoveAll removes all children.

func (*Node) RemoveAt Uses

func (n *Node) RemoveAt(idx int) INode

RemoveAt removes the child at the specified index.

func (*Node) Render Uses

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

Render satisfies the INode interface.

func (*Node) RotateOnAxis Uses

func (n *Node) RotateOnAxis(axis *math32.Vector3, angle float32)

RotateOnAxis rotates around the specified local axis the specified angle in radians.

func (*Node) RotateX Uses

func (n *Node) RotateX(x float32)

RotateX rotates around the local X axis the specified angle in radians.

func (*Node) RotateY Uses

func (n *Node) RotateY(y float32)

RotateY rotates around the local Y axis the specified angle in radians.

func (*Node) RotateZ Uses

func (n *Node) RotateZ(z float32)

RotateZ rotates around the local Z axis the specified angle in radians.

func (*Node) Rotation Uses

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

Rotation returns the current global rotation in Euler angles (radians).

func (*Node) Scale Uses

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

Scale returns the current scale.

func (*Node) SetChanged Uses

func (n *Node) SetChanged(changed bool)

SetChanged sets the matNeedsUpdate flag of the node.

func (*Node) SetDirection Uses

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

SetDirection sets the direction.

func (*Node) SetDirectionVec Uses

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

SetDirectionVec sets the direction based on a vector pointer.

func (*Node) SetLoaderID Uses

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 Uses

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

SetMatrix sets the local transformation matrix.

func (*Node) SetName Uses

func (n *Node) SetName(name string)

SetName sets the (optional) name. The name can be used for debugging or other purposes.

func (*Node) SetParent Uses

func (n *Node) SetParent(iparent INode)

SetParent sets the parent.

func (*Node) SetPosition Uses

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

SetPosition sets the position.

func (*Node) SetPositionVec Uses

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

SetPositionVec sets the position based on the specified vector pointer.

func (*Node) SetPositionX Uses

func (n *Node) SetPositionX(x float32)

SetPositionX sets the X coordinate of the position.

func (*Node) SetPositionY Uses

func (n *Node) SetPositionY(y float32)

SetPositionY sets the Y coordinate of the position.

func (*Node) SetPositionZ Uses

func (n *Node) SetPositionZ(z float32)

SetPositionZ sets the Z coordinate of the position.

func (*Node) SetQuaternion Uses

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

SetQuaternion sets the quaternion based on the specified quaternion unit multiples.

func (*Node) SetQuaternionQuat Uses

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

SetQuaternionQuat sets the quaternion based on the specified quaternion pointer.

func (*Node) SetQuaternionVec Uses

func (n *Node) SetQuaternionVec(q *math32.Vector4)

SetQuaternionVec sets the quaternion based on the specified quaternion unit multiples vector.

func (*Node) SetRotation Uses

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

SetRotation sets the global rotation in Euler angles (radians).

func (*Node) SetRotationQuat Uses

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

SetRotationQuat sets the global rotation based on the specified quaternion pointer.

func (*Node) SetRotationVec Uses

func (n *Node) SetRotationVec(vrot *math32.Vector3)

SetRotationVec sets the global rotation in Euler angles (radians) based on the specified vector pointer.

func (*Node) SetRotationX Uses

func (n *Node) SetRotationX(x float32)

SetRotationX sets the global X rotation to the specified angle in radians.

func (*Node) SetRotationY Uses

func (n *Node) SetRotationY(y float32)

SetRotationY sets the global Y rotation to the specified angle in radians.

func (*Node) SetRotationZ Uses

func (n *Node) SetRotationZ(z float32)

SetRotationZ sets the global Z rotation to the specified angle in radians.

func (*Node) SetScale Uses

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

SetScale sets the scale.

func (*Node) SetScaleVec Uses

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

SetScaleVec sets the scale based on the specified vector pointer.

func (*Node) SetScaleX Uses

func (n *Node) SetScaleX(sx float32)

SetScaleX sets the X scale.

func (*Node) SetScaleY Uses

func (n *Node) SetScaleY(sy float32)

SetScaleY sets the Y scale.

func (*Node) SetScaleZ Uses

func (n *Node) SetScaleZ(sz float32)

SetScaleZ sets the Z scale.

func (*Node) SetUserData Uses

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

SetUserData sets the generic user data associated to the node.

func (*Node) SetVisible Uses

func (n *Node) SetVisible(state bool)

SetVisible sets the visibility of the node.

func (*Node) TranslateOnAxis Uses

func (n *Node) TranslateOnAxis(axis *math32.Vector3, dist float32)

TranslateOnAxis translates the specified distance on the specified local axis.

func (*Node) TranslateX Uses

func (n *Node) TranslateX(dist float32)

TranslateX translates the specified distance on the local X axis.

func (*Node) TranslateY Uses

func (n *Node) TranslateY(dist float32)

TranslateY translates the specified distance on the local Y axis.

func (*Node) TranslateZ Uses

func (n *Node) TranslateZ(dist float32)

TranslateZ translates the specified distance on the local Z axis.

func (*Node) UpdateMatrix Uses

func (n *Node) UpdateMatrix() bool

UpdateMatrix updates (if necessary) the local transform matrix of this node based on its position, quaternion, and scale.

func (*Node) UpdateMatrixWorld Uses

func (n *Node) UpdateMatrixWorld()

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

func (*Node) UserData Uses

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

UserData returns the generic user data associated to the node.

func (*Node) Visible Uses

func (n *Node) Visible() bool

Visible returns the visibility of the node.

func (*Node) WorldDirection Uses

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

WorldDirection updates the world matrix and sets the specified vector to the current world direction of this node.

func (*Node) WorldPosition Uses

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

WorldPosition updates the world matrix and sets the specified vector to the current world position of this node.

func (*Node) WorldQuaternion Uses

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

WorldQuaternion updates the world matrix and sets the specified quaternion to the current world quaternion of this node.

func (*Node) WorldRotation Uses

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

WorldRotation updates the world matrix and sets the specified vector to the current world rotation of this node in Euler angles.

func (*Node) WorldScale Uses

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

WorldScale updates the world matrix and sets the specified vector to the current world scale of this node.

type Raycaster Uses

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
}

Raycaster represents an empty object that can cast rays and check for ray intersections.

func NewRaycaster Uses

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

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

func (*Raycaster) IntersectObject Uses

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 Uses

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 Uses

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

RenderInfo is passed into Render/RenderSetup calls

type TimerCallback Uses

type TimerCallback func(interface{})

TimerCallback is the type for timer callback functions

type TimerManager Uses

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

TimerManager manages multiple timers

func NewTimerManager Uses

func NewTimerManager() *TimerManager

NewTimerManager creates and returns a new timer manager

func (*TimerManager) ClearTimeout Uses

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 Uses

func (tm *TimerManager) Initialize()

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

func (*TimerManager) ProcessTimers Uses

func (tm *TimerManager) ProcessTimers()

ProcessTimers should be called periodically to process the timers

func (*TimerManager) SetInterval Uses

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 Uses

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

Package core imports 6 packages (graph) and is imported by 19 packages. Updated 2018-08-19. Refresh now. Tools for package owners.