scene

package
v0.0.0-...-47e0a63 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Scene provides a widget for duit, that can render a 3d scene and react to mouse and key events with changing the transformation matrix.

The opengl style 3d interface is based on github.com/foglman/{fauxl,ln,pt}. For the arcball see: github.com/fogleman/meshview/interactor.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matrix

type Matrix struct {
	X00, X01, X02, X03 float64
	X10, X11, X12, X13 float64
	X20, X21, X22, X23 float64
	X30, X31, X32, X33 float64
}

func Frustum

func Frustum(l, r, b, t, n, f float64) Matrix

func Identity

func Identity() Matrix

func LookAt

func LookAt(eye, center, up Vector) Matrix

func LookAtDirection

func LookAtDirection(forward, up Vector) Matrix

func Orient

func Orient(position, size, up Vector, rotation float64) Matrix

func Orthographic

func Orthographic(l, r, b, t, n, f float64) Matrix

func Perspective

func Perspective(fovy, aspect, near, far float64) Matrix

func Rotate

func Rotate(v Vector, a float64) Matrix

func RotateTo

func RotateTo(a, b Vector) Matrix

func Scale

func Scale(v Vector) Matrix

func Screen

func Screen(w, h int) Matrix

func Translate

func Translate(v Vector) Matrix

func Viewport

func Viewport(x, y, w, h float64) Matrix

func (Matrix) Determinant

func (a Matrix) Determinant() float64

func (Matrix) Frustum

func (m Matrix) Frustum(l, r, b, t, n, f float64) Matrix

func (Matrix) Inverse

func (a Matrix) Inverse() Matrix

func (Matrix) LookAt

func (m Matrix) LookAt(eye, center, up Vector) Matrix

func (Matrix) Mul

func (a Matrix) Mul(b Matrix) Matrix

func (Matrix) MulDirection

func (a Matrix) MulDirection(b Vector) Vector

func (Matrix) MulPosition

func (a Matrix) MulPosition(b Vector) Vector

func (Matrix) MulPositionW

func (a Matrix) MulPositionW(b Vector) VectorW

func (Matrix) MulScalar

func (a Matrix) MulScalar(b float64) Matrix

func (Matrix) Orthographic

func (m Matrix) Orthographic(l, r, b, t, n, f float64) Matrix

func (Matrix) Perspective

func (m Matrix) Perspective(fovy, aspect, near, far float64) Matrix

func (Matrix) Rotate

func (m Matrix) Rotate(v Vector, a float64) Matrix

func (Matrix) RotateTo

func (m Matrix) RotateTo(a, b Vector) Matrix

func (Matrix) Scale

func (m Matrix) Scale(v Vector) Matrix

func (Matrix) Translate

func (m Matrix) Translate(v Vector) Matrix

func (Matrix) Transpose

func (a Matrix) Transpose() Matrix

func (Matrix) Viewport

func (m Matrix) Viewport(x, y, w, h float64) Matrix

type Scene

type Scene struct {
	View
	SceneDrawer `json:"-"`
}

Scene is a UI which renders a 3d scene and reacts to events with pan, zoom and rotate.

func (*Scene) Draw

func (s *Scene) Draw(dui *duit.DUI, self *duit.Kid, img *duitdraw.Image, orig image.Point, m duitdraw.Mouse, force bool)

func (*Scene) FirstFocus

func (s *Scene) FirstFocus(dui *duit.DUI, self *duit.Kid) (warp *image.Point)

func (*Scene) Focus

func (s *Scene) Focus(dui *duit.DUI, self *duit.Kid, o duit.UI) (warp *image.Point)

func (*Scene) Key

func (s *Scene) Key(dui *duit.DUI, self *duit.Kid, k rune, m duitdraw.Mouse, orig image.Point) (r duit.Result)

func (*Scene) Layout

func (s *Scene) Layout(dui *duit.DUI, self *duit.Kid, sizeAvail image.Point, force bool)

func (*Scene) Mark

func (s *Scene) Mark(self *duit.Kid, o duit.UI, forLayout bool) (marked bool)

func (*Scene) Mouse

func (s *Scene) Mouse(dui *duit.DUI, self *duit.Kid, m duitdraw.Mouse, origM duitdraw.Mouse, orig image.Point) (r duit.Result)

func (*Scene) Print

func (s *Scene) Print(self *duit.Kid, indent int)

type SceneDrawer

type SceneDrawer interface {
	DrawScene(im *duitdraw.Image, view View)
}

SceneDrawer can draw a 3d object onto an image.

type Vector

type Vector struct {
	X, Y, Z float64
}

func RandomUnitVector

func RandomUnitVector() Vector

func V

func V(x, y, z float64) Vector

func (Vector) Abs

func (a Vector) Abs() Vector

func (Vector) Add

func (a Vector) Add(b Vector) Vector

func (Vector) AddScalar

func (a Vector) AddScalar(b float64) Vector

func (Vector) Ceil

func (a Vector) Ceil() Vector

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

func (Vector) Distance

func (a Vector) Distance(b Vector) float64

func (Vector) DistanceSquared

func (a Vector) DistanceSquared(b Vector) float64

func (Vector) Div

func (a Vector) Div(b Vector) Vector

func (Vector) DivScalar

func (a Vector) DivScalar(b float64) Vector

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

func (Vector) Floor

func (a Vector) Floor() Vector

func (Vector) IsDegenerate

func (a Vector) IsDegenerate() bool

func (Vector) Length

func (a Vector) Length() float64

func (Vector) LengthSquared

func (a Vector) LengthSquared() float64

func (Vector) Lerp

func (a Vector) Lerp(b Vector, t float64) Vector

func (Vector) LerpDistance

func (a Vector) LerpDistance(b Vector, d float64) Vector

func (Vector) Less

func (a Vector) Less(b Vector) bool

func (Vector) Max

func (a Vector) Max(b Vector) Vector

func (Vector) MaxComponent

func (a Vector) MaxComponent() float64

func (Vector) Min

func (a Vector) Min(b Vector) Vector

func (Vector) MinComponent

func (a Vector) MinComponent() float64

func (Vector) Mod

func (a Vector) Mod(b Vector) Vector

func (Vector) Mul

func (a Vector) Mul(b Vector) Vector

func (Vector) MulScalar

func (a Vector) MulScalar(b float64) Vector

func (Vector) Negate

func (a Vector) Negate() Vector

func (Vector) Normalize

func (a Vector) Normalize() Vector

func (Vector) Perpendicular

func (a Vector) Perpendicular() Vector

func (Vector) Reflect

func (i Vector) Reflect(n Vector) Vector

func (Vector) SegmentDistance

func (p Vector) SegmentDistance(v Vector, w Vector) float64

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

func (Vector) SubScalar

func (a Vector) SubScalar(b float64) Vector

func (Vector) VectorW

func (a Vector) VectorW() VectorW

type VectorW

type VectorW struct {
	X, Y, Z, W float64
}

func (VectorW) Add

func (a VectorW) Add(b VectorW) VectorW

func (VectorW) DivScalar

func (a VectorW) DivScalar(b float64) VectorW

func (VectorW) Dot

func (a VectorW) Dot(b VectorW) float64

func (VectorW) MulScalar

func (a VectorW) MulScalar(b float64) VectorW

func (VectorW) Outside

func (a VectorW) Outside() bool

func (VectorW) Sub

func (a VectorW) Sub(b VectorW) VectorW

func (VectorW) Vector

func (a VectorW) Vector() Vector

type View

type View struct {
	Eye           Vector  // Eye position in object space
	Center        Vector  // Centeral position (where the eye looks at) in object space.
	Up            Vector  // Unit direction going up in object space.
	Near, Far     float64 // Clipping planes
	Fovy          float64 // Field of view angle in degree in y direction (normally 45..60 deg)
	Width, Height float64 // Destination image dimensions.
	// contains filtered or unexported fields
}

View defines where we look at.

func NewView

func NewView() View

NewView initializes the view and arcball with default values. The values can be changed afterwards.

func (*View) Rotate

func (v *View) Rotate(dx, dy float64)

Rotate the camera location (eye vector). Dx and Dy are relative mouse movements in relation to width and height.

func (*View) Zoom

func (v *View) Zoom(scale float64)

Zoom moves the camera (Eye) towards or away from the center.

Directories

Path Synopsis
examples
ln

Jump to

Keyboard shortcuts

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