feat: added way to get absolute mouse position.

This commit is contained in:
Andrey Parhomenko 2023-11-23 23:12:41 +03:00
parent e1504de702
commit 9ab3b9bb4d
4 changed files with 30 additions and 2 deletions

View file

@ -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
}

View file

@ -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, ", "))

View file

@ -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

19
mouse.go Normal file
View file

@ -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)
}