diff --git a/camera.go b/camera.go index bf36e34..1b3594b 100644 --- a/camera.go +++ b/camera.go @@ -24,3 +24,10 @@ func (c *Camera)RealMatrix( return *g } +func (c *Camera) AbsMatrix( + e *Engine, +) Matrix { + m := c.RealMatrix(e) + m.Invert() + return m +} diff --git a/cmd/test/main.go b/cmd/test/main.go index 58c283c..807edd3 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -263,6 +263,9 @@ func (d *Debug) Draw( keyStrs = append(keyStrs, "THIS IS SHIT") } + keyStrs = append(keyStrs, fmt.Sprintf("%v", e.CursorPosition())) + keyStrs = append(keyStrs, fmt.Sprintf("%v", e.AbsCursorPosition())) + e.DebugPrint(i, strings.Join(keyStrs, ", ")) diff --git a/event.go b/event.go index 4755c57..f645849 100644 --- a/event.go +++ b/event.go @@ -1,7 +1,7 @@ package gg import ( - "github.com/hajimehoshi/ebiten/v2" + //"github.com/hajimehoshi/ebiten/v2" ) type Eventer interface { @@ -38,7 +38,6 @@ type KeyUp struct { } -type MouseButton = ebiten.MouseButton type MouseButtonDown struct { MouseButton P Vector diff --git a/mouse.go b/mouse.go new file mode 100644 index 0000000..bedb13a --- /dev/null +++ b/mouse.go @@ -0,0 +1,19 @@ +package gg + +import ( + "github.com/hajimehoshi/ebiten/v2" +) + +type MouseButton = ebiten.MouseButton + +func (e *Engine) CursorPosition() Vector { + x, y := ebiten.CursorPosition() + return V(Float(x), Float(y)) +} + +func (e *Engine) AbsCursorPosition() Vector { + m := &Matrix{} + m.Concat(e.Camera().AbsMatrix(e)) + return e.CursorPosition().Apply(m) +} +