fix: fixed the Transform parenting MatrixForParenting. And yes it was just because of just one symbol in the code.
This commit is contained in:
parent
b7d7ab9bf9
commit
9203bd1e79
6 changed files with 46 additions and 39 deletions
|
@ -40,10 +40,10 @@ func (d *Debug) Draw(c *Context) []gg.EVertex {
|
|||
))
|
||||
|
||||
keyStrs = append(keyStrs, fmt.Sprintf(
|
||||
"relTriPos: %v", tri.Position(),
|
||||
"relTriPos: %v", relTri.Position(),
|
||||
))
|
||||
keyStrs = append(keyStrs, fmt.Sprintf(
|
||||
"absTriPos: %v", relTri.Position(),
|
||||
"absTriPos: %v", tri.Position(),
|
||||
))
|
||||
keyStrs = append(keyStrs, fmt.Sprintf(
|
||||
"absTriRot: %v", gg.Degree(tri.Rotation()),
|
||||
|
|
|
@ -41,7 +41,7 @@ func main() {
|
|||
Width: 720,
|
||||
Height: 480,
|
||||
VSync: true,
|
||||
Fullscreen: true,
|
||||
Fullscreen: false,
|
||||
})
|
||||
|
||||
var err error
|
||||
|
|
|
@ -32,10 +32,12 @@ func NewPlayer() *Player {
|
|||
ret.Collidable = true
|
||||
ret.Resolvable = true
|
||||
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *Player) Start(c *Context) {
|
||||
p.Connect(rect)
|
||||
}
|
||||
|
||||
func (p *Player) Draw(c *Context) []gg.EVertex {
|
||||
|
@ -68,14 +70,6 @@ func (p *Player) Update(c *Context) {
|
|||
gg.X(p.ScaleSpeed*dt),
|
||||
),
|
||||
)
|
||||
case gg.KeyArrowUp:
|
||||
cam.Move(gg.Y(-p.MoveSpeed * dt))
|
||||
case gg.KeyArrowDown:
|
||||
cam.Move(gg.Y(p.MoveSpeed * dt))
|
||||
case gg.KeyArrowLeft:
|
||||
cam.Move(gg.X(-p.MoveSpeed*dt))
|
||||
case gg.KeyArrowRight:
|
||||
cam.Move(gg.X(p.MoveSpeed * dt))
|
||||
case gg.KeyW:
|
||||
p.Move(gg.Y(-p.MoveSpeed * dt *10))
|
||||
walking = true
|
||||
|
@ -123,8 +117,9 @@ func (p *Player) Update(c *Context) {
|
|||
case gg.Key5:
|
||||
pp := *p
|
||||
counter++
|
||||
p.Spawned = true
|
||||
p.Collidable = false
|
||||
pp.Spawned = true
|
||||
pp.Collidable = false
|
||||
pp.Resolvable = false
|
||||
c.Spawn(&pp)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,18 @@ func (r *Rect) CollisionType() gg.CollisionType {
|
|||
|
||||
func (r *Rect) Update(c *Context) {
|
||||
//r.R += 0.3 * e.DT()
|
||||
dt := c.Dt().Seconds()
|
||||
//r.Position = c.AbsCursorPosition()
|
||||
for _, v := range c.Keys() { switch v {
|
||||
case gg.KeyArrowUp:
|
||||
r.Move(gg.Y(-10* dt))
|
||||
case gg.KeyArrowDown:
|
||||
r.Move(gg.Y(10 * dt))
|
||||
case gg.KeyArrowLeft:
|
||||
r.Move(gg.X(-10*dt))
|
||||
case gg.KeyArrowRight:
|
||||
r.Move(gg.X(10* dt))
|
||||
}}
|
||||
}
|
||||
|
||||
func (r *Rect) Event(c *Context) {
|
||||
|
|
|
@ -49,18 +49,14 @@ func (t *Tri) Update(c *Context) {
|
|||
}
|
||||
|
||||
for _, key := range keys { switch key {
|
||||
|
||||
case gg.KeyM:
|
||||
absPos := t.Position()
|
||||
t.SetPosition(
|
||||
absPos.Add(gg.V(0, 100*dt*d)),
|
||||
)
|
||||
t.Move(gg.Y(100*dt*d))
|
||||
case gg.KeyN:
|
||||
absPos := t.Position()
|
||||
t.SetPosition(
|
||||
absPos.Add(gg.V(100*dt*d, 0)),
|
||||
)
|
||||
t.Move(gg.X(100*dt*d))
|
||||
|
||||
case gg.KeyV:
|
||||
t.Rotate(d * gg.Pi * 0.3 * dt)
|
||||
t.Rotate(d * gg.Pi * 0.3 * dt)
|
||||
case gg.Key2 :
|
||||
if t.Spawned {
|
||||
break
|
||||
|
|
39
transform.go
39
transform.go
|
@ -74,11 +74,13 @@ func (t *Transform) SetRotation(rotation Float) {
|
|||
// Set the absolute object scale.
|
||||
func (t *Transform) SetScale(scale Vector) {
|
||||
t.dirty = true
|
||||
t.parentDirty = true
|
||||
t.scale = scale
|
||||
}
|
||||
|
||||
func (t *Transform) AddScale(add ...Vector) {
|
||||
t.dirty = true
|
||||
//t.parentDirty = true
|
||||
t.scale = t.scale.Add(add...)
|
||||
}
|
||||
|
||||
|
@ -93,17 +95,13 @@ func (t *Transform) Abs() Transform {
|
|||
return *t
|
||||
}
|
||||
|
||||
ret := T()
|
||||
ret := Transform{}
|
||||
ret.position = t.Position()
|
||||
ret.rotation = t.Rotation()
|
||||
|
||||
// Do not need that
|
||||
// cause parent does not affect
|
||||
// scaling.
|
||||
// (Should think if scaling from parent
|
||||
// can be used anyhow)
|
||||
|
||||
//ret.scale = t.Scale()
|
||||
ret.scale = t.Scale()
|
||||
ret.around = t.Around()
|
||||
ret.dirty = true
|
||||
ret.parentDirty = true
|
||||
|
||||
return ret
|
||||
}
|
||||
|
@ -141,8 +139,8 @@ func (t *Transform) Rotation() Float {
|
|||
}
|
||||
|
||||
func (t *Transform) Rotate(add Float) {
|
||||
t.rotation += add
|
||||
t.dirty = true
|
||||
t.rotation += add
|
||||
}
|
||||
func (t *Transform) Around() Vector {
|
||||
return t.around
|
||||
|
@ -157,11 +155,19 @@ func (t *Transform) Connected() bool {
|
|||
// Connect the object to another one making
|
||||
// it its parent.
|
||||
func (t *Transform) Connect(parent Transformer) {
|
||||
absPosition := t.Position()
|
||||
absRotation := t.Rotation()
|
||||
if parent == nil {
|
||||
return
|
||||
}
|
||||
if t.parent != nil {
|
||||
t.Disconnect()
|
||||
}
|
||||
|
||||
position := t.Position()
|
||||
rotation := t.Rotation()
|
||||
|
||||
t.parent = parent.GetTransform()
|
||||
t.SetPosition(absPosition)
|
||||
t.SetRotation(absRotation)
|
||||
t.SetPosition(position)
|
||||
t.SetRotation(rotation)
|
||||
}
|
||||
|
||||
// Disconnect from the parent.
|
||||
|
@ -175,15 +181,14 @@ func (t *Transform) Disconnect() {
|
|||
// Return the matrix and the inverted one for parenting children.
|
||||
func (t *Transform) MatrixForParenting() (Matrix, Matrix) {
|
||||
var m, mi Matrix
|
||||
|
||||
if t.parentDirty {
|
||||
|
||||
m.Scale(t.scale.X, t.scale.Y)
|
||||
//m.Scale(t.scale.X, t.scale.Y)
|
||||
m.Rotate(t.rotation)
|
||||
m.Translate(t.position.X, t.position.Y)
|
||||
t.parentMatrix = m
|
||||
|
||||
mi := m
|
||||
mi = m
|
||||
mi.Invert()
|
||||
t.parentInverted = mi
|
||||
|
||||
|
|
Loading…
Reference in a new issue