mechtree

package
v0.0.0-...-a3e6692 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mechtree implements a hierarchical tree structure of nodes in 3D space that ultimately form the visual content of a Mechane world.

Index

Constants

View Source
const (
	Top         = OverlayOrigin("top")
	Bottom      = OverlayOrigin("bottom")
	Left        = OverlayOrigin("left")
	Right       = OverlayOrigin("right")
	Center      = OverlayOrigin("center")
	IconCenter  = OverlayOrigin("icon-center") // Useful for a button with an icon.
	TopLeft     = OverlayOrigin("top-left")
	TopRight    = OverlayOrigin("top-right")
	BottomRight = OverlayOrigin("bottom-right")
	BottomLeft  = OverlayOrigin("bottom-left")
)
View Source
const (
	// Flat does not apply an orientation to the overlay element, it is always
	// flat on and front facing.
	Flat = OverlayOrientation(iota)
	// XY orientation orients the overlay element so it matches the XY-plane
	// (Z=0) of its in-world frame as seen from the camera. When viewing the
	// element from the rear of the frame you see the same contents as the front
	// face but in an unusual right to left order, making it obvious it is the
	// rear side.
	XY
	// XYFront orientation orients the overlay element so it matches the
	// XY-plane (Z=0) of its in-world frame as seen from the camera, but does
	// not allow the overlay element's rear face to be seen. When viewing the
	// element from the rear of the frame the overlay element is rotated around
	// its in-world frame's Y-axis by 180 degrees.
	XYFront
)

Variables

This section is empty.

Functions

func Localise

func Localise(cam Camera) (mech.Depiction, mechoverlayer.Elements)

Localise the visual components on the tree from their various frames to that of the given camera's frame.

func LocaliseDepictions

func LocaliseDepictions(local *Node) mech.Depiction

LocaliseDepictions on the tree from their various frames to that of the given node's frame.

func NewChangeOfFrame

func NewChangeOfFrame(from *Node, to *Node) (maf.Aff, error)

NewChangeOfFrame transformation from coordinates in the 'from' frame to coordinates in the 'to' frame.

func NewLocaliser

func NewLocaliser(
	f func(*Node, maf.Aff),
) func(*Node, leafstar.PreviousStep, LocAcc) LocAcc

NewLocaliser maps the given function, which expects a localising transformation argument, to a function suitable for use in a leafstar traversal.

A leafstar traversal used in conjunction with the returned function calls the given function for each node: providing the given function with the current node and a change of frame transformation that goes from the current node's frame to the leafstar traversal's start frame.

Types

type Camera

type Camera struct {
	Inverse maf.Mat4 // Inverse transformation to the lens transformation.
	Lens    maf.Mat4
	Name    string
	Node    *Node
}

A Camera which is attached to a tree node and is used to view the contents of the tree from that node.

The camera is positioned at the origin of the node and looks down its negative Z-axis with the positive Y-axis direction as the 'up' direction.

func (Camera) Project

func (c Camera) Project(p maf.Vec) maf.Vec

Project the given point, which shall be specified in the coords of the camera's frame, to the OpenGL NDC space/cube.

type Interframe

type Interframe struct {
	// Transform the coordinates of a point in frame A to its coordinates in
	// frame B.
	AToB maf.Aff
	// Transform the coordinates of a point in frame B to its coordinates in
	// frame A.
	BToA maf.Aff
}

An Interframe has two change of frame transformations, one for each direction between two frames on a tree.

func NewInterframe

func NewInterframe(a *Node, b *Node) (Interframe, error)

NewInterframe to change coordinates in either direction between the two given nodes on a tree.

type LocAcc

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

LocAcc is the accumulator for a localising leafstar traversal.

type Node

type Node struct {
	sync.Mutex
	Cashpoint    *Node
	Depictioners map[string]mech.Depictioner
	maf.Frame
	Kids           []*Node
	OverlayElement OverlayElement
}

A Node with its own coordinate system, a coordinate system which is embedded in (and specified relative to) the coordinate system of its parent node.

For the root node of a Mechane tree with no parent node the position and orientation of its frame are effectively meaningless.

func NewNode

func NewNode() *Node

func (*Node) AddChild

func (nde *Node) AddChild(child *Node)

AddChild to the receiver node, detaching it from its current parent, if any.

Adding a child is not an atomic operation: the detach is done first as a separate op.

Nothing happens if the child and receiver are the same node.

func (*Node) AddDepictioner

func (nde *Node) AddDepictioner(dpr mech.Depictioner)

AddDepictioner to the node.

func (*Node) AddDepictioners

func (nde *Node) AddDepictioners(vd ...mech.Depictioner)

AddDepictioners to the node.

func (*Node) Children

func (nde *Node) Children() []*Node

Children of the receiver node.

func (*Node) Detach

func (nde *Node) Detach()

Detach the receiver node from its parent making it the root of its own tree.

func (*Node) Get

func (nde *Node) Get() maf.Frame

Get the frame of the node.

func (*Node) GetElement

func (nde *Node) GetElement() OverlayElement

GetElement of the node.

func (*Node) IsMe

func (nde *Node) IsMe(node *Node) bool

IsMe reports whether the argument is the same instance as the receiver.

func (*Node) IsRoot

func (nde *Node) IsRoot() bool

IsRoot reports whether the receiver node has no parent.

func (*Node) Orient

func (nde *Node) Orient(fr maf.Frame)

Orient the frame of the node.

func (*Node) Overlay

func (nde *Node) Overlay(e OverlayElement)

Overlay the display area with the given element.

The top left corner of the overlay element will coincide with the origin of the node's frame.

func (*Node) Parent

func (nde *Node) Parent() *Node

Parent of the node which may be nil for a root node.

func (*Node) RemoveDepictioner

func (nde *Node) RemoveDepictioner(dpr mech.Depictioner)

RemoveDepictioner from the node.

func (*Node) Set

func (nde *Node) Set(fr maf.Frame)

Set the frame of the node.

type OverlayElement

type OverlayElement struct {
	// The HTML of the overlay element.
	HTML string
	// Each overlay element on a tree should have a unique name.
	Name string
	// On-screen orientation of an overlay element relative to its in-world
	// orientation.
	Orientation OverlayOrientation
	// Adjust the on-screen position of an overlay element relative to its node.
	OriginPosition OverlayOrigin
	// contains filtered or unexported fields
}

An OverlayElement attached to a node on a tree.

type OverlayOrientation

type OverlayOrientation int

An OverlayOrientation decides how an overlay element should be oriented on the screen.

The element's on-screen orientation can be made to match its in-world orientation.

type OverlayOrigin

type OverlayOrigin string

An OverlayOrigin specifies which part of the overlay element coincides with the node's onscreen origin.

Directories

Path Synopsis
wire_example
sin

Jump to

Keyboard shortcuts

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