drw

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const Auto = -1

Auto is constant that if you pass as resolution to Circle, auto resolution will be used

Variables

View Source
var (
	Default = &LineDrawerBase{}
	Sharp   = &SharpLine{}
	// Round holds some inner state so if you are drawing on multiple threads, you need to create own instances
	Round = &RoundLine{}
)

Line Modes

View Source
var AutoResolutionSpacing float64 = 1

AutoResolutionSpacing is size of fraction of the circle that has Auto resolution

View Source
var LineIndicePatern = ggl.Indices{0, 1, 3, 0, 3, 2}

Functions

func AutoResolution

func AutoResolution(radius, start, end, spacing float64) int

Types

type Base

type Base []mat.Vec

func (*Base) Resize

func (v *Base) Resize(size int)

Resize resizes the Base

type Circle

type Circle struct {
	ggl.Data
	Base
	// contains filtered or unexported fields
}

Circle is a drawing tool that can draw circles with different resolution efficiently as everithing is precalculated upon creation

func NArc

func NArc(radius, thickness, start, end float64, resolution int) Circle

func NCircle

func NCircle(radius, thickness float64, resolution int) Circle

NCircle creates ready-to-use Circle, choose resolution based of how big circles you want to draw bigger the circle more resolution matters, radius is not that important ac you can scale circle how ever you like

func (*Circle) Draw

func (c *Circle) Draw(t ggl.Target, tran mat.Mat, rgba mat.RGBA)

Draw implements ggl.Drawer interface

func (*Circle) Filled

func (c *Circle) Filled(radius, start, end float64, resolution int)

func (*Circle) Outline

func (c *Circle) Outline(radius, thickness, start, end float64, resolution int)

func (*Circle) Update

func (c *Circle) Update(tran mat.Mat, rgba mat.RGBA)

Update updates circle state to given transformation and color

type ClampedViewport

type ClampedViewport struct {
	ggl.Data
	Area mat.AABB
}

ClampedViewport clamps all vertices into Area

func (*ClampedViewport) Accept

func (p *ClampedViewport) Accept(vertexes ggl.Vertexes, indices ggl.Indices)

Accept implements ggl.Target interface

type Edge

type Edge struct {
	End
	C, BC, B3, B4 mat.Vec
	Convex        bool
}

func (*Edge) Init

func (e *Edge) Init(points []mat.Vec, thickness float64, i, ln int)

type End

type End struct {
	A, B, BA, B1, B2 mat.Vec
	Thickness        float64
}

func (*End) Init

func (e *End) Init(a, b mat.Vec, thickness float64)

type Geom

type Geom struct {
	ggl.Data
	// contains filtered or unexported fields
}

Geom is is small abstraction around Data that allows drawing of geometric shapes, geomdrawer can be used as canvas for creating complex shapes, Drawers can draw to each other, though if you don't want triangles to get modified by target drawer use drawer.Data as target

 // use as is or create with NGeom that sets some default values
 d := drw.Geom{}

 // red rectangle
 d.Color(mat.Red).Fill(true).AABB(mat.A(0, 0, 100, 100))

 // draws green outline to red rectangel with total thickness 10
 d.Color(mat.Green).Thickness(5).Fill(false).AABB(mat.A(0, 0, 100, 100))

 // draws line closed in triangle with custom edge style
 d.Color(mat.RGB(0, 1, 1)).Loop(true).Thickness(10).Edge(CutEdge{})
 d.Line(mat.V(0, -100), mat.V(-100, -200), mat.V(100, -200))

 // draw everithing to target with no transformation
 d.Fetch(t)

 // draw to target with ewerithing transformed by matrix and masked, in this case
	// everithing is shifted by 100 to right, twice as big and rotated by 90 degrees
	d.Draw(t, mat.M(mat.V(100, 0), mat.V(2, 2), math.Phi*.5), mat.RGB(.5, .5, .5))

func NGeomDrawer

func NGeomDrawer() Geom

NGeomDrawer sets some nice default values

func (*Geom) AABB

func (g *Geom) AABB(value mat.AABB)

AABB draws AABB appliable(Fill, Edge, Thickness)

func (*Geom) Accept

func (g *Geom) Accept(vertexes ggl.Vertexes, indices ggl.Indices)

Accept implements ggl.Target interface

func (*Geom) Apply

func (g *Geom) Apply(start, end int)

Apply applies curent color and intensity to slice of vertices

func (*Geom) Arc

func (g *Geom) Arc(start, end float64) *Geom

func (*Geom) Circle

func (g *Geom) Circle(c mat.Circ)

func (*Geom) Color

func (g *Geom) Color(value mat.RGBA) *Geom

Color sets drawind color

func (*Geom) Draw

func (g *Geom) Draw(t ggl.Target, mat mat.Mat, rgba mat.RGBA)

Draw implements ggl.Drawer interface

func (*Geom) Fetch

func (g *Geom) Fetch(t ggl.Target)

Fetch implements ggl.Fetcher interface

func (*Geom) Fill

func (g *Geom) Fill(fill bool) *Geom

Fill decides whether shapes should be filled or just outlines

func (*Geom) Intensity

func (g *Geom) Intensity(value float64) *Geom

Intensity sets drawing intensity

func (*Geom) Line

func (g *Geom) Line(points ...mat.Vec)

func (*Geom) LineType

func (g *Geom) LineType(ld LineDrawer) *Geom

func (*Geom) Loop

func (g *Geom) Loop(loop bool) *Geom

Loop sets whether lines should be closed into loops

func (*Geom) Rect

func (g *Geom) Rect(corners [4]mat.Vec)

Rect draws rectangle appliable(Fill, Edge, Thickness)

func (*Geom) Reserve

func (g *Geom) Reserve(amount int) ggl.Vertexes

Reserve reserves vertexes, sets theier intensity and color and returns slice that points to them

func (*Geom) Resolution

func (g *Geom) Resolution(resolution int) *Geom

Resolution sets resolution of circle, it can be set to Auto but if spacing is 0 nothing will be drawn

func (*Geom) Restart

func (g *Geom) Restart()

Restart restarts the configuration to default one

func (*Geom) Spacing

func (g *Geom) Spacing(value float64) *Geom

Spacing sets circle spacing, if you pass 0 old resolution will be used if you pass any positive number, resolution will be set to auto

func (*Geom) Thickness

func (g *Geom) Thickness(thickness float64) *Geom

Thickness sets line thickness of drawer

type LineDrawer

type LineDrawer interface {
	Init(thickness float64)
	Start(*End, *LineProcessor)
	End(*End, *LineProcessor)
	Edge(*Edge, *LineProcessor)
	Close(*Edge, *LineProcessor)
}

type LineDrawerBase

type LineDrawerBase struct{}

func (*LineDrawerBase) Close

func (l *LineDrawerBase) Close(e *Edge, lp *LineProcessor)

func (*LineDrawerBase) Edge

func (l *LineDrawerBase) Edge(e *Edge, lp *LineProcessor)

func (*LineDrawerBase) End

func (*LineDrawerBase) End(e *End, lp *LineProcessor)

func (*LineDrawerBase) Init

func (*LineDrawerBase) Init(thickness float64)

func (*LineDrawerBase) PostEnge

func (*LineDrawerBase) PostEnge(e *Edge, lp *LineProcessor)

func (*LineDrawerBase) PreEdge

func (*LineDrawerBase) PreEdge(e *Edge, lp *LineProcessor)

func (*LineDrawerBase) Start

func (*LineDrawerBase) Start(e *End, lp *LineProcessor)

type LineProcessor

type LineProcessor struct {
	Points  []mat.Vec
	Indices ggl.Indices
}

func (*LineProcessor) AppendIndices

func (l *LineProcessor) AppendIndices(indices ...uint32)

func (*LineProcessor) AppendPoints

func (l *LineProcessor) AppendPoints(center mat.Vec, points ...mat.Vec)

func (*LineProcessor) Process

func (l *LineProcessor) Process(g *Geom, ld LineDrawer, points ...mat.Vec)

type Preprocessor

type Preprocessor interface {
	ggl.Fetcher
	ggl.Target
	Clear()
}

Preprocessor is something that changes triangles in some way and can draw them, for example multiplying of seting color mask

type RoundLine

type RoundLine struct {
	LineDrawerBase
	Circle
}

func (*RoundLine) Close

func (r *RoundLine) Close(e *Edge, lp *LineProcessor)

func (*RoundLine) Edge

func (r *RoundLine) Edge(e *Edge, lp *LineProcessor)

func (*RoundLine) End

func (r *RoundLine) End(e *End, lp *LineProcessor)

func (*RoundLine) Init

func (r *RoundLine) Init(thickness float64)

func (*RoundLine) Start

func (r *RoundLine) Start(e *End, lp *LineProcessor)

type SharpLine

type SharpLine struct{ LineDrawerBase }

func (*SharpLine) AddEnd

func (s *SharpLine) AddEnd(e *End, lp *LineProcessor)

func (*SharpLine) Close

func (s *SharpLine) Close(e *Edge, lp *LineProcessor)

func (*SharpLine) Edge

func (s *SharpLine) Edge(e *Edge, lp *LineProcessor)

func (*SharpLine) End

func (s *SharpLine) End(e *End, lp *LineProcessor)

func (*SharpLine) Start

func (s *SharpLine) Start(e *End, lp *LineProcessor)

type SpriteViewport

type SpriteViewport struct {
	ggl.Data
	Area mat.AABB
}

SpriteViewport is able to crop sprite triangles that are not rotated thus i makes effect like sprites are only visible from Area, if you try to clamp rotated sprites they will get deformed, trying to clamp something other then sprites will also result in random deformation of corse vertices will be visible only inside the View but for unreasonable performance cost.

func (*SpriteViewport) Accept

func (p *SpriteViewport) Accept(vertexes ggl.Vertexes, indices ggl.Indices)

Accept implements ggl.Target interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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