feat: finished incapsulating the Transform.
This commit is contained in:
parent
b479bf1988
commit
b7d7ab9bf9
6 changed files with 40 additions and 53 deletions
|
@ -67,13 +67,13 @@ func main() {
|
|||
e.Spawn(rect)
|
||||
e.Spawn(tri)
|
||||
|
||||
circle := &gg.Circle{}
|
||||
/*circle := &gg.Circle{}
|
||||
circle.Transform = gg.T()
|
||||
circle.Rotation = 300
|
||||
circle.Color = gg.Rgba(1, 1, 1, 1)
|
||||
circle.Antialias = true
|
||||
circle.Layer = HighestL
|
||||
circle.Visible = true
|
||||
circle.Visible = true*/
|
||||
//e.Spawn(circle)
|
||||
|
||||
txt := &Text{}
|
||||
|
|
|
@ -48,7 +48,8 @@ func (p *Player) Draw(c *Context) []gg.EVertex {
|
|||
}
|
||||
|
||||
func (p *Player) Update(c *Context) {
|
||||
p.SetPosition(p.Position().Sub(gg.Y(2)))
|
||||
//p.SetPosition(p.Position().Sub(gg.Y(2)))
|
||||
p.Move(gg.Y(1))
|
||||
if p.Spawned {
|
||||
return
|
||||
}
|
||||
|
@ -76,51 +77,45 @@ func (p *Player) Update(c *Context) {
|
|||
case gg.KeyArrowRight:
|
||||
cam.Move(gg.X(p.MoveSpeed * dt))
|
||||
case gg.KeyW:
|
||||
p.Move(gg.Y(p.MoveSpeed * dt*10))
|
||||
p.Move(gg.Y(-p.MoveSpeed * dt *10))
|
||||
walking = true
|
||||
p.Animate(Walk)
|
||||
case gg.KeyA:
|
||||
p.Move(gg.X(-MoveSpeed * dt))
|
||||
p.SetScale(gg.V(-1, 1)
|
||||
p.Move(gg.X(-p.MoveSpeed * dt))
|
||||
p.SetScale(gg.V(-1, 1))
|
||||
walking = true
|
||||
p.Animate(Walk)
|
||||
case gg.KeyS:
|
||||
p.Move(gg.X(-MoveSpeed * dt))
|
||||
p.Position.Y -= p.MoveSpeed * dt
|
||||
p.Move(gg.X(-p.MoveSpeed * dt))
|
||||
//p.Position.Y -= p.MoveSpeed * dt
|
||||
walking = true
|
||||
p.Animate(Walk)
|
||||
case gg.KeyD:
|
||||
p.Position.X += p.MoveSpeed * dt
|
||||
p.Scale.X = 1
|
||||
p.Move(gg.X(p.MoveSpeed * dt))
|
||||
p.SetScale(gg.V(1, 1))
|
||||
walking = true
|
||||
p.Animate(Walk)
|
||||
case gg.KeyR:
|
||||
cam.Rotation += gg.Pi * p.ScaleSpeed * dt
|
||||
cam.Rotate(gg.Pi * p.ScaleSpeed * dt)
|
||||
case gg.KeyT:
|
||||
cam.Rotation -= gg.Pi * p.ScaleSpeed * dt
|
||||
cam.Rotate(-gg.Pi * p.ScaleSpeed * dt)
|
||||
case gg.KeyRightBracket:
|
||||
if shift {
|
||||
p.Rotation -= gg.Pi * 0.3 * dt
|
||||
p.Rotate(-gg.Pi * 0.3 * dt)
|
||||
} else {
|
||||
p.Rotation += gg.Pi * 0.3 * dt
|
||||
p.Rotate(+gg.Pi * 0.3 * dt)
|
||||
}
|
||||
case gg.KeyF:
|
||||
if shift {
|
||||
cam.Scale = cam.Scale.Add(gg.V2(p.ScaleSpeed * dt))
|
||||
cam.AddScale(gg.V2(p.ScaleSpeed * dt))
|
||||
} else {
|
||||
cam.Scale = cam.Scale.Add(gg.V2(-p.ScaleSpeed * dt))
|
||||
}
|
||||
case gg.KeyG:
|
||||
if shift {
|
||||
cam.Scale.Y -= gg.Pi * p.ScaleSpeed * dt
|
||||
} else {
|
||||
cam.Scale.Y += gg.Pi * p.ScaleSpeed * dt
|
||||
cam.AddScale(gg.V2(-p.ScaleSpeed * dt))
|
||||
}
|
||||
case gg.KeyLeftBracket:
|
||||
if shift {
|
||||
rect.Rotation -= gg.Pi * 0.3 * dt
|
||||
rect.Rotate(-gg.Pi * 0.3 * dt)
|
||||
} else {
|
||||
rect.Rotation += gg.Pi * 0.3 * dt
|
||||
rect.Rotate(+gg.Pi * 0.3 * dt)
|
||||
}
|
||||
case gg.Key0:
|
||||
c.Del(p)
|
||||
|
@ -153,10 +148,9 @@ func (p *Player) Update(c *Context) {
|
|||
if !c.IsButtoned(gg.MouseButtonRight) {
|
||||
break
|
||||
}
|
||||
pos := c.Camera.Position
|
||||
c.Camera.Position = pos.Sub(ec.Abs)
|
||||
c.Camera.Move(ec.Abs)
|
||||
case *gg.WheelChange:
|
||||
c.Camera.Scale = c.Camera.Scale.Add(gg.V2(
|
||||
c.Camera.AddScale(gg.V2(
|
||||
ec.Offset.Y * dt * p.ScaleSpeed * 40,
|
||||
))
|
||||
}}
|
||||
|
@ -178,7 +172,7 @@ func (p *Player) Resolve(c *Context) {
|
|||
case gg.CollisionStaticPhysics :
|
||||
LOOP:
|
||||
for {
|
||||
p.Position.Y -= 1
|
||||
p.Move(gg.Y(-1))
|
||||
_, collides := gg.Collide(p, col.With)
|
||||
if !collides {
|
||||
break LOOP
|
||||
|
|
|
@ -8,7 +8,7 @@ type Rect struct {
|
|||
|
||||
func NewRect() *Rect {
|
||||
ret := &Rect{}
|
||||
ret.Scale = gg.V(200, 400)
|
||||
ret.SetScale(gg.V(200, 400))
|
||||
ret.Color = gg.Color{
|
||||
gg.MaxColorV,
|
||||
0,
|
||||
|
|
|
@ -14,8 +14,7 @@ type Tri struct {
|
|||
|
||||
func NewTri() *Tri {
|
||||
ret := &Tri{}
|
||||
ret.Transform.Scale = gg.V2(1)
|
||||
|
||||
ret.Transform = gg.T()
|
||||
ret.Triangles = gg.Triangles{
|
||||
gg.Triangle{
|
||||
gg.V(0, 10),
|
||||
|
@ -51,17 +50,17 @@ func (t *Tri) Update(c *Context) {
|
|||
|
||||
for _, key := range keys { switch key {
|
||||
case gg.KeyM:
|
||||
absPos := t.AbsPosition()
|
||||
t.SetAbsPosition(
|
||||
absPos := t.Position()
|
||||
t.SetPosition(
|
||||
absPos.Add(gg.V(0, 100*dt*d)),
|
||||
)
|
||||
case gg.KeyN:
|
||||
absPos := t.AbsPosition()
|
||||
t.SetAbsPosition(
|
||||
absPos := t.Position()
|
||||
t.SetPosition(
|
||||
absPos.Add(gg.V(100*dt*d, 0)),
|
||||
)
|
||||
case gg.KeyV:
|
||||
t.Rotation += d * gg.Pi * 0.3 * dt
|
||||
t.Rotate(d * gg.Pi * 0.3 * dt)
|
||||
case gg.Key2 :
|
||||
if t.Spawned {
|
||||
break
|
||||
|
|
18
shader.go
18
shader.go
|
@ -21,23 +21,7 @@ var (
|
|||
|
||||
func Fragment(dst vec4, src vec2, _ vec4) vec4 {
|
||||
c := imageSrc0UnsafeAt(src)
|
||||
size := imageSrc0Size()
|
||||
//ret := vec4(0.1) * src.x/size.x
|
||||
//ret := c * src.x/size.x
|
||||
//ret.r = 1
|
||||
//ret.a = c.a
|
||||
//c.a = 0
|
||||
//c.rg = vec2(0)
|
||||
//c.a = c.b
|
||||
//ret := vec4(1, 1, 1, 0)
|
||||
//ret.a /= 5
|
||||
//ret.a = src.x
|
||||
//c.a /= 5
|
||||
//c = vec4(c.a)
|
||||
orig := imageSrc0Origin()
|
||||
src -= orig
|
||||
c.a *= (size.x-src.x)/size.x
|
||||
return c
|
||||
return c * sin(dst.x)
|
||||
}
|
||||
`))
|
||||
)
|
||||
|
|
10
transform.go
10
transform.go
|
@ -77,6 +77,11 @@ func (t *Transform) SetScale(scale Vector) {
|
|||
t.scale = scale
|
||||
}
|
||||
|
||||
func (t *Transform) AddScale(add ...Vector) {
|
||||
t.dirty = true
|
||||
t.scale = t.scale.Add(add...)
|
||||
}
|
||||
|
||||
func (t *Transform) SetAround(around Vector) {
|
||||
t.dirty = true
|
||||
t.around = around
|
||||
|
@ -134,6 +139,11 @@ func (t *Transform) Rotation() Float {
|
|||
}
|
||||
return t.rotation + t.parent.Rotation()
|
||||
}
|
||||
|
||||
func (t *Transform) Rotate(add Float) {
|
||||
t.rotation += add
|
||||
t.dirty = true
|
||||
}
|
||||
func (t *Transform) Around() Vector {
|
||||
return t.around
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue