func (l *Lever) SetDirection(point1 sf.Vector2f, point2 sf.Vector2f) { direction := point2.Minus(point1) direction = Vector.DirV2(direction) dir1 := direction dir2 := direction dir1.X *= l.radius1 dir1.Y *= l.radius1 dir2.X *= l.radius2 dir2.Y *= l.radius2 l.ctrlPoint1 = l.point.Minus(dir1) l.ctrlPoint2 = l.point.Plus(dir2) }
func (g *Game) getSpeedAndMovementFromControl() (sf.Vector2f, sf.Vector2f) { movement := sf.Vector2f{0, 0} speed := sf.Vector2f{2, 2} if sf.KeyboardIsKeyPressed(sf.KeySpace) { speed.X *= 3 speed.Y *= 3 } if sf.KeyboardIsKeyPressed(sf.KeyRight) { movement.X += 1.0 } if sf.KeyboardIsKeyPressed(sf.KeyLeft) { movement.X += -1.0 } if sf.KeyboardIsKeyPressed(sf.KeyUp) { movement.Y += -1.0 } if sf.KeyboardIsKeyPressed(sf.KeyDown) { movement.Y += 1.0 } return speed, movement }
func (v vectorUtil) DistanceV2f(point1, point2 sf.Vector2f) (output float32) { vector := point2.Minus(point1) output = float32(math.Sqrt(math.Pow(float64(vector.X), 2) + math.Pow(float64(vector.Y), 2))) return }