本文整理汇总了Golang中github.com/runningwild/linear.Vec2.Mag2方法的典型用法代码示例。如果您正苦于以下问题:Golang Vec2.Mag2方法的具体用法?Golang Vec2.Mag2怎么用?Golang Vec2.Mag2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/runningwild/linear.Vec2
的用法示例。
在下文中一共展示了Vec2.Mag2方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getControllerDirection
// 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
}
示例2: BasicPropertiesSpec
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)
})
}
示例3: BasicOperationsSpec
func BasicOperationsSpec(c gospec.Context) {
a := linear.Vec2{3, 4}
b := linear.Vec2{5, 6}
c.Specify("Make sure adding vectors works.", func() {
VecExpect(c, a.Add(b), Equals, linear.Vec2{8, 10})
})
c.Specify("Make sure subtracting vectors works.", func() {
VecExpect(c, a.Sub(b), Equals, linear.Vec2{-2, -2})
})
c.Specify("Make sure dotting vectors works.", func() {
c.Expect(a.Dot(b), IsWithin(1e-9), 39.0)
})
c.Specify("Make sure crossing vectors works.", func() {
VecExpect(c, a.Cross(), Equals, linear.Vec2{-4, 3})
})
c.Specify("Make sure taking the magnitude of vectors works.", func() {
c.Expect(a.Mag(), IsWithin(1e-9), 5.0)
c.Expect(a.Mag2(), IsWithin(1e-9), 25.0)
})
c.Specify("Make sure scaling vectors works.", func() {
VecExpect(c, a.Scale(3), Equals, linear.Vec2{9, 12})
})
}