feat: added way to get absolute mouse position.
This commit is contained in:
parent
e1504de702
commit
9ab3b9bb4d
4 changed files with 30 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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, ", "))
|
||||
|
||||
|
|
3
event.go
3
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
|
||||
|
|
19
mouse.go
Normal file
19
mouse.go
Normal 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)
|
||||
}
|
||||
|
Loading…
Reference in a new issue