本文整理匯總了Golang中github.com/runningwild/linear.Vec2.Norm方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vec2.Norm方法的具體用法?Golang Vec2.Norm怎麽用?Golang Vec2.Norm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/runningwild/linear.Vec2
的用法示例。
在下文中一共展示了Vec2.Norm方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
})
}