// Queries the input system for the direction that this controller is moving in func getControllerDirection(controller gin.DeviceId) linear.Vec2 { v := linear.Vec2{ axisControl(control.right.CurPressAmt()) - axisControl(control.left.CurPressAmt()), axisControl(control.down.CurPressAmt()) - axisControl(control.up.CurPressAmt()), } if v.Mag2() > 1 { v = v.Norm() } return v }
func BasicPropertiesSpec(c gospec.Context) { a := linear.Vec2{3, 4} b := linear.Vec2{5, 6} c.Specify("Check that (cross a) dot a == 0.", func() { c.Expect(a.Cross().Dot(a), Equals, 0.0) }) c.Specify("Check that a normalize vector's magnitude is 1.", func() { c.Expect(a.Norm().Mag(), IsWithin(1e-9), 1.0) }) c.Specify("Check that v.Mag2() == v.Mag()*v.Mag()", func() { c.Expect(a.Mag2(), IsWithin(1e-9), a.Mag()*a.Mag()) }) c.Specify("Check that a scaled vector's magnitude is appropriately scaled.", func() { c.Expect(a.Scale(3.5).Mag(), IsWithin(1e-9), a.Mag()*3.5) }) c.Specify("Check that a-(a-b) == b.", func() { VecExpect(c, a.Sub(a.Sub(b)), IsWithin(1e-9), b) }) }