diff --git a/cmd/test/debug.go b/cmd/test/debug.go index 4dff5f0..af824ea 100644 --- a/cmd/test/debug.go +++ b/cmd/test/debug.go @@ -27,6 +27,9 @@ func (d *Debug) Draw(c *Context) { keyStrs = append(keyStrs, fmt.Sprintf( "absTriPos: %v", tri.AbsPosition(), )) + keyStrs = append(keyStrs, fmt.Sprintf( + "absTriRot: %v", gg.Degree(tri.AbsRotation()), + )) keys := []string{} for _, k := range e.Keys() { diff --git a/cmd/test/trianlge.go b/cmd/test/trianlge.go index 09b82cd..281b044 100644 --- a/cmd/test/trianlge.go +++ b/cmd/test/trianlge.go @@ -15,14 +15,9 @@ func NewTri() *Tri { ret.Triangles = gg.Triangles{ gg.Triangle{ - gg.V(0, 0), - gg.V(100, 100), - gg.V(0, -50), - }, - gg.Triangle{ - gg.V(0, 0), - gg.V(-100, -100), - gg.V(0, 50), + gg.V(0, 10), + gg.V(100, 0), + gg.V(0, -10), }, } ret.Color = gg.Color{gg.MaxColorV, gg.MaxColorV, 0, gg.MaxColorV} diff --git a/math.go b/math.go index a1bed90..6b18728 100644 --- a/math.go +++ b/math.go @@ -15,6 +15,10 @@ const ( //PiRad = Pi * Rad ) +func Degree(f Float) Float { + return (f/(2*Pi))*360 +} + // Returns square of the value. func Sqr(v Float) Float { return v * v diff --git a/transform.go b/transform.go index c0478b2..7d7b4f8 100644 --- a/transform.go +++ b/transform.go @@ -60,13 +60,45 @@ func (t *Transform) SetAbsPosition(absPosition Vector) { t.Position = absPosition.Apply(m) } +// Get the absolute representation of the transform. +func (t *Transform) Abs() Transform { + m := t.Matrix() + ret := Transform{} + ret.Position = t.Position.Apply(m) + ret.Rotation = t.AbsRotation() + return ret +} + func (t *Transform) AbsPosition() Vector { return t.Position.Apply(t.Matrix()) } +func (t *Transform) AbsScale() Vector { + return V2(0) +} + +func (t *Transform) AbsRotation() Float { + if t.Parent == nil { + return t.Rotation + } + return t.Rotation + t.Parent.GetTransform().AbsRotation() +} + +func (t *Transform) Connected() bool { + return t.Parent != nil +} + func (t *Transform) Connect(p Transformer) { } +func (t *Transform) Disconnect() { + if t.Parent == nil { + return + } + *t = t.Abs() + t.Parent = nil +} + // Returns the GeoM with corresponding // to the transfrom transformation. func (t *Transform)Matrix() *Matrix {