world2d

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type View

type View struct {

	// width of lines for shape rendering, in normalized units
	LineWidth float32

	// projection matrix for converting 3D to 2D -- resulting X, Y coordinates are used from Vector3
	Projection math32.Matrix4

	// the root Group node of the virtual world
	World *physics.Group

	// the SVG rendering canvas for visualizing in 2D
	Scene *svg.SVG

	// the root Group node in the Scene under which the world is rendered
	Root *svg.Group

	// library of shapes for bodies -- name matches Body.Vis
	Library map[string]*svg.Group
}

View connects a Virtual World with a 2D SVG Scene to visualize the world

func NewView

func NewView(world *physics.Group, sc *svg.SVG, root *svg.Group) *View

NewView returns a new View that links given world with given scene and root group

func (*View) AddFromLibrary

func (vw *View) AddFromLibrary(nm string, gp *svg.Group)

AddFromLibrary adds shape from library to given group

func (*View) ConfigBodyShape

func (vw *View) ConfigBodyShape(bod physics.Body, shp svg.Node)

ConfigBodyShape configures a shape for a body with current values

func (*View) ConfigView

func (vw *View) ConfigView(wn physics.Node, vn svg.Node)

ConfigView configures the view node to properly display world node

func (*View) Image

func (vw *View) Image() (*image.RGBA, error)

Image returns the current rendered image

func (*View) InitLibShape

func (vw *View) InitLibShape(bod physics.Body)

InitLibShape initializes Scene library with basic shape for given body

func (*View) InitLibrary

func (vw *View) InitLibrary()

InitLibrary initializes Scene library with basic shapes based on bodies in the virtual world. More complex visualizations can be configured after this.

func (*View) InitLibraryBody

func (vw *View) InitLibraryBody(wn physics.Node)

InitLibraryBody initializes Scene library with basic shapes based on bodies in the virtual world. More complex visualizations can be configured after this.

func (*View) NewInLibrary

func (vw *View) NewInLibrary(nm string) *svg.Group

NewInLibrary adds a new item of given name in library

func (*View) ProjectXY

func (vw *View) ProjectXY()

ProjectXY sets 2D projection to reflect 3D X,Y coords

func (*View) ProjectXZ

func (vw *View) ProjectXZ()

ProjectXZ sets 2D projection to reflect 3D X,Z coords

func (*View) Projection2D

func (vw *View) Projection2D(pos math32.Vector3) math32.Vector2

Projection2D projects position from 3D to 2D

func (*View) Sync

func (vw *View) Sync() bool

Sync synchronizes the view to the world

func (*View) SyncNode

func (vw *View) SyncNode(wn physics.Node, vn svg.Node) bool

SyncNode updates the view tree to match the world tree, using ConfigChildren to maximally preserve existing tree elements returns true if view tree was modified (elements added / removed etc)

func (*View) Transform2D

func (vw *View) Transform2D(phys *physics.State) math32.Matrix2

Transform2D returns the full 2D transform matrix for a given position and quat rotation in 3D

func (*View) UpdateBodyView

func (vw *View) UpdateBodyView(bodyNames ...string)

UpdateBodyView updates the display properties of given body name recurses the tree until this body name is found.

func (*View) UpdateBodyViewNode

func (vw *View) UpdateBodyViewNode(bodyNames []string, wn physics.Node, vn svg.Node)

UpdateBodyViewNode updates the body view info for given name(s) Essential that both trees are already synchronized.

func (*View) UpdatePose

func (vw *View) UpdatePose()

UpdatePose updates the view pose values only from world tree. Essential that both trees are already synchronized.

func (*View) UpdatePoseNode

func (vw *View) UpdatePoseNode(wn physics.Node, vn svg.Node)

UpdatePoseNode updates the view pose values only from world tree. Essential that both trees are already synchronized.

Jump to

Keyboard shortcuts

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