From 5cd9a65dfbce4c08ef99983dade68316259da37c Mon Sep 17 00:00:00 2001 From: surdeus Date: Sun, 2 Jun 2024 00:01:17 +0500 Subject: [PATCH] feat: FUCKING DID IT. --- cmd/test/camera.go | 28 ++++++++++++++++++-------- cmd/test/debug.go | 4 ++++ cmd/test/main.go | 6 +++++- cmd/test/player.go | 6 +++--- cmd/test/rect.go | 1 - cmd/test/trianlge.go | 3 ++- ox/camera.go | 1 + ox/feats.go | 7 ++++--- ox/object.go | 1 + ox/polygon.go | 2 -- ox/rect.go | 3 ++- ox/sprite.go | 1 - ox/text.go | 8 +------- ox/transform.go | 48 ++++++++++++++++++++++++++++++++------------ ox/tri.go | 1 - 15 files changed, 78 insertions(+), 42 deletions(-) diff --git a/cmd/test/camera.go b/cmd/test/camera.go index 29a8f1d..d25f98e 100644 --- a/cmd/test/camera.go +++ b/cmd/test/camera.go @@ -4,21 +4,26 @@ import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/mx" import "surdeus.su/core/gg" +import "log" + var ( - camera = &Camera{ - Camera: ox.NewCamera(), - ScaleSpeed: 5., - RotationSpeed: .3, - } + camera *Camera ) type Camera struct { - ox.ObjectImpl ox.Camera ScaleSpeed mx.Float RotationSpeed mx.Float } +func NewCamera() *Camera { + camera := &Camera{} + camera.Camera = ox.NewCamera() + camera.ScaleSpeed = 5. + camera.RotationSpeed = .3 + return camera +} + func (cam *Camera) OnUpdate(c gg.Context) { dt := c.Engine().DT().Seconds() mov := c.Events().Mouse.Move @@ -38,8 +43,15 @@ func (cam *Camera) OnUpdate(c gg.Context) { // Scale. if wheel != nil { - cam.AddScale(mx.V2( - wheel.Offset.Y * dt * cam.ScaleSpeed * 40, + k := 1.5 + log.Println(wheel.Offset.Y) + if wheel.Offset.Y < 0 { + k = 1/k + } + + cam.Scale(mx.V2( + k, + //wheel.Offset.Y * dt * cam.ScaleSpeed * 40, )) } diff --git a/cmd/test/debug.go b/cmd/test/debug.go index c75c783..aab4958 100644 --- a/cmd/test/debug.go +++ b/cmd/test/debug.go @@ -24,6 +24,10 @@ func (d *Debug) OnUpdate(c Context) { } } +func (d *Debug) OnStart(c Context) { + d.Visible = true +} + func (d *Debug) GetLayer() gg.Layer {return LayerHighest} func (d *Debug) Draw(c Context) *gg.Drawing { diff --git a/cmd/test/main.go b/cmd/test/main.go index 19ba017..5c3354d 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -78,6 +78,7 @@ func main() { VSync: true, Fullscreen: false, }) + camera = NewCamera() e.SetCamera(camera) e.Spawn(camera) @@ -89,13 +90,16 @@ func main() { rect = NewRect() - playerAnimations, _ = ax.AnimationSetFromImage( + playerAnimations, err = ax.AnimationSetFromImage( playerImg, 8, 3, 10, 1, ax.AD(Stand).DefRow(0, 0, 1, 2, 3, 4), ax.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7), ) + if err != nil { + panic(err) + } player = NewPlayer() tri = NewTri() diff --git a/cmd/test/player.go b/cmd/test/player.go index dda5615..545cc3e 100644 --- a/cmd/test/player.go +++ b/cmd/test/player.go @@ -4,7 +4,7 @@ import "surdeus.su/core/gg" import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/mx" import "time" -import "log" +//import "log" type Player struct { ox.AnimatedSprite @@ -18,7 +18,7 @@ func NewPlayer() *Player { //ret.Transform = ox.T() ret.AnimatedSprite = ox.NewAnimatedSprite( playerAnimations, - time.Second / 1, + time.Second / 10, ) @@ -52,7 +52,7 @@ func (p *Player) Draw(c Context) *gg.Drawing { } func (p *Player) OnUpdate(c Context) { - log.Println(p.IsVisible()) + //log.Println("OnUpdate(...)") if p.Spawned { return } diff --git a/cmd/test/rect.go b/cmd/test/rect.go index d7d81ce..8240026 100644 --- a/cmd/test/rect.go +++ b/cmd/test/rect.go @@ -5,7 +5,6 @@ import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/mx" type Rect struct { - ox.ObjectImpl ox.DrawableRectangle } diff --git a/cmd/test/trianlge.go b/cmd/test/trianlge.go index e5aabb3..103cf63 100644 --- a/cmd/test/trianlge.go +++ b/cmd/test/trianlge.go @@ -4,13 +4,13 @@ import "surdeus.su/core/gg" import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/mx" //import "fmt" +//import "log" var ( counter int ) type Tri struct { - ox.ObjectImpl ox.DrawablePolygon Spawned bool } @@ -37,6 +37,7 @@ func NewTri() *Tri { } func (t *Tri) OnUpdate(c Context) { + //log.Println("onup:", t.IsVisible()) //redges := rect.Edges() //tedges := t.Edges() //crosses, ok := tedges.CrossWithEdges(redges) diff --git a/ox/camera.go b/ox/camera.go index 3849479..72f6e39 100644 --- a/ox/camera.go +++ b/ox/camera.go @@ -7,6 +7,7 @@ import "surdeus.su/core/gg/mx" // Default camera implementation. var _ = gg.Camera(&Camera{}) type Camera struct { + ObjectImpl // The Transform to interact with // to change camera position, rotation etc. Transform diff --git a/ox/feats.go b/ox/feats.go index 3d04c38..6f9c59a 100644 --- a/ox/feats.go +++ b/ox/feats.go @@ -4,11 +4,12 @@ import "surdeus.su/core/gg" type Drawity struct { + ObjectImpl Visibility Colority Shaderity Floatity - Layerity + Layer } // Feat to emded for turning antialias on and off. @@ -24,7 +25,7 @@ func (v Visibility) IsVisible() bool { return v.Visible } -func (v Visibility) ToggleVisibility() bool { +func (v *Visibility) ToggleVisibility() bool { v.Visible = !v.Visible return v.IsVisible() } @@ -52,4 +53,4 @@ func (s Floatity) IsFloating() bool { return s.Floating } -type Layerity = gg.Layer +type Layer = gg.Layer diff --git a/ox/object.go b/ox/object.go index b7b1b7a..eb2015f 100644 --- a/ox/object.go +++ b/ox/object.go @@ -23,3 +23,4 @@ type ObjectImpl struct { DrawerImpl BeherImpl } + diff --git a/ox/polygon.go b/ox/polygon.go index 53feb68..173616e 100644 --- a/ox/polygon.go +++ b/ox/polygon.go @@ -7,7 +7,6 @@ import ( // Grouped triangles type. type Polygon struct { - ObjectImpl Transform mx.Triangles } @@ -45,7 +44,6 @@ var _ = gg.Drawer(&DrawablePolygon{}) // Polygon that can be drawn. type DrawablePolygon struct { Polygon - Drawity } diff --git a/ox/rect.go b/ox/rect.go index 04c7256..522efad 100644 --- a/ox/rect.go +++ b/ox/rect.go @@ -12,7 +12,6 @@ import "surdeus.su/core/gg/mx" // The type describes rectangle geometry with // way to move, rotate and scale it. type Rectangle struct { - ObjectImpl Transform Width, Height mx.Float } @@ -23,10 +22,12 @@ func (r Rectangle) Vertices() mx.Vectors { wh := mx.Vector{r.Width, r.Height} t.SetAround(t.GetAround().Mul(wh)) m := t.GetMatrice() + p1 := mx.Vector{0, 0}.Apply(m) p2 := mx.Vector{wh.X, 0}.Apply(m) p3 := mx.Vector{wh.X, wh.Y}.Apply(m) p4 := mx.Vector{0, wh.Y}.Apply(m) + return mx.Vectors{p1, p2, p3, p4} } diff --git a/ox/sprite.go b/ox/sprite.go index a31a546..f4b6f2b 100644 --- a/ox/sprite.go +++ b/ox/sprite.go @@ -11,7 +11,6 @@ import "surdeus.su/core/gg" var _ = gg.Drawer(&Sprite{}) type Sprite struct { Transform - Drawity } diff --git a/ox/text.go b/ox/text.go index 69f6415..fbfd849 100644 --- a/ox/text.go +++ b/ox/text.go @@ -8,14 +8,8 @@ import "github.com/hajimehoshi/ebiten/v2" // The type implements basic drawable text. // (Now needs to implement rotation, scaling etc, cause now only position) type Text struct { - ObjectImpl Transform - - Colority - Visibility - Shaderity - Floatity - + Drawity Face gg.Face Data string } diff --git a/ox/transform.go b/ox/transform.go index 5aeb247..ed6bda9 100644 --- a/ox/transform.go +++ b/ox/transform.go @@ -37,6 +37,7 @@ func T() Transform { // Rotate around the center. around: mx.V2(.5), } + ret.dirty = true return ret } @@ -52,45 +53,59 @@ func (t *Transform) GetTransform() *Transform { } // Set the absolute object position. -func (t *Transform) SetPosition(position mx.Vector) { +func (t *Transform) SetPosition(position mx.Vector) *Transform { t.dirty = true t.parentDirty = true if t.parent == nil { t.position = position - return + return t } _, mi := t.parent.GetMatriceForParenting() t.position = position.Apply(mi) + + return t } // Set the absolute object rotation. -func (t *Transform) SetRotation(rotation mx.Float) { +func (t *Transform) SetRotation(rotation mx.Float) *Transform { t.dirty = true t.parentDirty = true if t.parent == nil { t.rotation = rotation - return + return t } t.rotation -= t.parent.GetRotation() + + return t } // Set the absolute object scale. -func (t *Transform) SetScale(scale mx.Vector) { +func (t *Transform) SetScale(scale mx.Vector) *Transform { t.dirty = true t.parentDirty = true t.scale = scale + return t } -func (t *Transform) AddScale(add mx.Vector) { +func (t *Transform) AddScale(add mx.Vector) *Transform { t.dirty = true //t.parentDirty = true t.scale = t.scale.Add(add) + return t } -func (t *Transform) SetAround(around mx.Vector) { +func (t *Transform) Scale(mul mx.Vector) *Transform { + t.dirty = true + t.scale = t.scale.Mul(mul) + return t +} + +func (t *Transform) SetAround(around mx.Vector) *Transform { t.dirty = true t.around = around + + return t } // Get the absolute representation of the transform. @@ -143,10 +158,12 @@ func (t *Transform) GetRotation() mx.Float { return t.rotation + t.parent.GetRotation() } -func (t *Transform) Rotate(rot mx.Float) { +func (t *Transform) Rotate(rot mx.Float) *Transform { t.dirty = true t.parentDirty = true t.rotation += rot + + return t } func (t *Transform) GetAround() mx.Vector { return t.around @@ -160,9 +177,9 @@ func (t *Transform) IsConnected() bool { // Connect the object to another one making // it its parent. -func (t *Transform) Connect(parent Transformer) { +func (t *Transform) Connect(parent Transformer) *Transform { if parent == nil { - return + return t } if t.parent != nil { t.Disconnect() @@ -174,17 +191,22 @@ func (t *Transform) Connect(parent Transformer) { t.parent = parent.GetTransform() t.SetPosition(position) t.SetRotation(rotation) + + return t } // Disconnect from the parent. -func (t *Transform) Disconnect() { +func (t *Transform) Disconnect() *Transform { if t.parent == nil { - return + return t } *t = t.Abs() + + return t } -// Return the matrix and the inverted one for parenting children. +// Return the matrix and the inverted +// one for parenting children. func (t *Transform) GetMatriceForParenting( ) (mx.Matrice, mx.Matrice) { var m, mi mx.Matrice diff --git a/ox/tri.go b/ox/tri.go index 089e968..af5ff66 100644 --- a/ox/tri.go +++ b/ox/tri.go @@ -6,7 +6,6 @@ import "surdeus.su/core/gg" type DrawableTriangles struct { mx.Triangles - Drawity }