diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index 2809c07..64ed6b2 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -26,9 +26,9 @@ type Rect struct { func NewRect() *Rect { return &Rect{&gx.DrawableRectangle{ Rectangle: gx.Rectangle{ + Transform: gx.T(), W: 200, H: 400, - T: gx.T(), }, Color: gx.Color{ gx.MaxColorV, @@ -60,13 +60,15 @@ var ( func NewPlayer() *Player { ret := &Player{ Sprite: &gx.Sprite{ - T: gx.Transform { + Transform: gx.Transform { S: gx.Vector{5, 5}, RA: gx.Vector{320, 240}, }, Visible: true, - Shader: gx.SolidWhiteColorShader, - Uniforms: make(map[string] any), + ShaderOptions: gx.ShaderOptions { + Shader: gx.SolidWhiteColorShader, + Uniforms: make(map[string] any), + }, }, MoveSpeed: 90., ScaleSpeed: .2, @@ -80,7 +82,7 @@ func NewPlayer() *Player { func (p *Player) Start(e *gx.Engine, v ...any) { fmt.Println("starting") c := e.Camera() - c.T.RA = gx.V(360, -240) + c.RA = gx.V(360, -240) } func (p *Player) Update(e *gx.Engine) error { @@ -91,51 +93,51 @@ func (p *Player) Update(e *gx.Engine) error { p.Uniforms["Random"] = any(rand.Float32()) for _, v := range keys {switch v { case ebiten.KeyArrowUp : - c.T.P.Y += p.MoveSpeed * dt + c.P.Y += p.MoveSpeed * dt case ebiten.KeyArrowLeft : - c.T.P.X -= p.MoveSpeed * dt + c.P.X -= p.MoveSpeed * dt case ebiten.KeyArrowDown : - c.T.P.Y -= p.MoveSpeed * dt + c.P.Y -= p.MoveSpeed * dt case ebiten.KeyArrowRight : - c.T.P.X += p.MoveSpeed * dt + c.P.X += p.MoveSpeed * dt case ebiten.KeyW : - p.T.P.Y += p.MoveSpeed * dt + p.P.Y += p.MoveSpeed * dt case ebiten.KeyA : - p.T.P.X -= p.MoveSpeed * dt + p.P.X -= p.MoveSpeed * dt case ebiten.KeyS : - p.T.P.Y -= p.MoveSpeed * dt + p.P.Y -= p.MoveSpeed * dt case ebiten.KeyD : - p.T.P.X += p.MoveSpeed * dt + p.P.X += p.MoveSpeed * dt case ebiten.KeyR : - c.T.R += gx.Pi * p.ScaleSpeed * dt + c.R += gx.Pi * p.ScaleSpeed * dt case ebiten.KeyT : - c.T.R -= gx.Pi * p.ScaleSpeed * dt + c.R -= gx.Pi * p.ScaleSpeed * dt case ebiten.KeyF : if e.KeyIsPressed(ebiten.KeyShift) { - c.T.S.X -= gx.Pi * p.ScaleSpeed * dt + c.S.X -= gx.Pi * p.ScaleSpeed * dt } else { - c.T.S.X += gx.Pi * p.ScaleSpeed * dt + c.S.X += gx.Pi * p.ScaleSpeed * dt } case ebiten.KeyG : if e.KeyIsPressed(ebiten.KeyShift) { - c.T.S.Y -= gx.Pi * p.ScaleSpeed * dt + c.S.Y -= gx.Pi * p.ScaleSpeed * dt } else { - c.T.S.Y += gx.Pi * p.ScaleSpeed * dt + c.S.Y += gx.Pi * p.ScaleSpeed * dt } case ebiten.KeyZ : if e.KeyIsPressed(ebiten.KeyShift) { - c.T.RA.X -= gx.Pi * p.MoveSpeed * dt + c.RA.X -= gx.Pi * p.MoveSpeed * dt } else { - c.T.RA.X += gx.Pi * p.MoveSpeed * dt + c.RA.X += gx.Pi * p.MoveSpeed * dt } - log.Println(c.T.RA.X) + log.Println(c.RA.X) case ebiten.KeyX : if e.KeyIsPressed(ebiten.KeyShift) { - c.T.RA.Y -= gx.Pi * p.MoveSpeed * dt + c.RA.Y -= gx.Pi * p.MoveSpeed * dt } else { - c.T.RA.Y += gx.Pi * p.MoveSpeed * dt + c.RA.Y += gx.Pi * p.MoveSpeed * dt } - log.Println(c.T.RA.Y) + log.Println(c.RA.Y) case ebiten.Key0 : e.Del(p) }} diff --git a/src/gx/camera.go b/src/gx/camera.go index f8d7088..4388aea 100644 --- a/src/gx/camera.go +++ b/src/gx/camera.go @@ -3,7 +3,7 @@ package gx // Implements the camera component // for the main window. type Camera struct { - T Transform + Transform } // Returns the matrix satysfying camera @@ -21,20 +21,20 @@ func (c *Camera)RealMatrix( if scale { g.Scale( - c.T.S.X, - c.T.S.Y, + c.S.X, + c.S.Y, ) } g.Translate( - -c.T.P.X, - c.T.P.Y, + -c.P.X, + c.P.Y, ) - g.Rotate(-c.T.R) + g.Rotate(-c.R) g.Translate( - c.T.RA.X, - -c.T.RA.Y, + c.RA.X, + -c.RA.Y, ) return *g diff --git a/src/gx/main.go b/src/gx/main.go index 863b7ea..bde8e22 100644 --- a/src/gx/main.go +++ b/src/gx/main.go @@ -63,7 +63,7 @@ func New( *poolx.Pool[Drawer], ](true), camera: &Camera{ - T: Transform{ + Transform: Transform{ S: Vector{1, 1}, }, }, diff --git a/src/gx/rect.go b/src/gx/rect.go index 0252bcc..2220f7f 100644 --- a/src/gx/rect.go +++ b/src/gx/rect.go @@ -12,7 +12,7 @@ type Rectangle struct { // Position of up left corner // and the point to // rotate around(relatively of position, not absolute). - T Transform + Transform // Width and height. W, H Float @@ -21,19 +21,13 @@ type Rectangle struct { // The type describes rectangle that can be drawn. type DrawableRectangle struct { Rectangle + ShaderOptions // Solid color of the rectangle. // Will be ignored if the Shader // field is not nil. Color Color - // Shader to be applied - Shader *Shader - // Shader variables. - Uniforms map[string] any - // Shader images - Images [4]*Image - // Should be draw or not. Visible bool } @@ -73,7 +67,7 @@ func (r *DrawableRectangle) Draw( e *Engine, i *Image, ) { - t := r.T + t := r.Transform // Draw solid color if no shader. if r.Shader == nil { diff --git a/src/gx/sprite.go b/src/gx/sprite.go index f230be1..ac5b0e4 100644 --- a/src/gx/sprite.go +++ b/src/gx/sprite.go @@ -5,10 +5,8 @@ import ( ) type Sprite struct { - T Transform - Shader *Shader - Images [4]*Image - Uniforms map[string] any + Transform + ShaderOptions Floating, Visible bool } @@ -23,7 +21,7 @@ func (s *Sprite) Draw( m := &Matrix{} - m.Concat(s.T.Matrix(e)) + m.Concat(s.Matrix(e)) if !s.Floating { m.Concat(e.Camera().RealMatrix( e,