feat: started implementing the methods for absolute values.

This commit is contained in:
Andrey Parhomenko 2023-12-27 01:35:50 +03:00
parent 373086a709
commit c4c17fbaec
4 changed files with 42 additions and 8 deletions

View file

@ -27,6 +27,9 @@ func (d *Debug) Draw(c *Context) {
keyStrs = append(keyStrs, fmt.Sprintf( keyStrs = append(keyStrs, fmt.Sprintf(
"absTriPos: %v", tri.AbsPosition(), "absTriPos: %v", tri.AbsPosition(),
)) ))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriRot: %v", gg.Degree(tri.AbsRotation()),
))
keys := []string{} keys := []string{}
for _, k := range e.Keys() { for _, k := range e.Keys() {

View file

@ -15,14 +15,9 @@ func NewTri() *Tri {
ret.Triangles = gg.Triangles{ ret.Triangles = gg.Triangles{
gg.Triangle{ gg.Triangle{
gg.V(0, 0), gg.V(0, 10),
gg.V(100, 100), gg.V(100, 0),
gg.V(0, -50), gg.V(0, -10),
},
gg.Triangle{
gg.V(0, 0),
gg.V(-100, -100),
gg.V(0, 50),
}, },
} }
ret.Color = gg.Color{gg.MaxColorV, gg.MaxColorV, 0, gg.MaxColorV} ret.Color = gg.Color{gg.MaxColorV, gg.MaxColorV, 0, gg.MaxColorV}

View file

@ -15,6 +15,10 @@ const (
//PiRad = Pi * Rad //PiRad = Pi * Rad
) )
func Degree(f Float) Float {
return (f/(2*Pi))*360
}
// Returns square of the value. // Returns square of the value.
func Sqr(v Float) Float { func Sqr(v Float) Float {
return v * v return v * v

View file

@ -60,13 +60,45 @@ func (t *Transform) SetAbsPosition(absPosition Vector) {
t.Position = absPosition.Apply(m) 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 { func (t *Transform) AbsPosition() Vector {
return t.Position.Apply(t.Matrix()) 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) Connect(p Transformer) {
} }
func (t *Transform) Disconnect() {
if t.Parent == nil {
return
}
*t = t.Abs()
t.Parent = nil
}
// Returns the GeoM with corresponding // Returns the GeoM with corresponding
// to the transfrom transformation. // to the transfrom transformation.
func (t *Transform)Matrix() *Matrix { func (t *Transform)Matrix() *Matrix {