本文整理匯總了Golang中github.com/runningwild/mathgl.Vec2.Add方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vec2.Add方法的具體用法?Golang Vec2.Add怎麽用?Golang Vec2.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/runningwild/mathgl.Vec2
的用法示例。
在下文中一共展示了Vec2.Add方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DoAdvance
// Advances ent up to dist towards the target cell. Returns the distance
// traveled.
func (e *Entity) DoAdvance(dist float32, x, y int) float32 {
if dist <= 0 {
e.sprite.sp.Command("stop")
return 0
}
e.sprite.sp.Command("move")
source := mathgl.Vec2{float32(e.X), float32(e.Y)}
target := mathgl.Vec2{float32(x), float32(y)}
var seg mathgl.Vec2
seg.Assign(&target)
seg.Subtract(&source)
e.TurnToFace(x, y)
var traveled float32
if seg.Length() > dist {
seg.Scale(dist / seg.Length())
traveled = dist
} else {
traveled = seg.Length()
}
seg.Add(&source)
e.X = float64(seg.X)
e.Y = float64(seg.Y)
return dist - traveled
}
示例2: Think
func (hv *HouseViewer) Think(g *gui.Gui, t int64) {
dt := t - hv.last_timestamp
if hv.last_timestamp == 0 {
dt = 0
}
hv.last_timestamp = t
scale := 1 - float32(math.Pow(0.005, float64(dt)/1000))
if hv.target_on {
f := mathgl.Vec2{hv.fx, hv.fy}
v := mathgl.Vec2{hv.targetx, hv.targety}
v.Subtract(&f)
v.Scale(scale)
f.Add(&v)
hv.fx = f.X
hv.fy = f.Y
}
if hv.target_zoom_on {
exp := math.Log(float64(hv.zoom))
exp += (float64(hv.targetzoom) - exp) * float64(scale)
hv.zoom = float32(math.Exp(exp))
}
}
示例3: Think
func (hv *HouseViewer) Think(g *gui.Gui, t int64) {
dt := t - hv.last_timestamp
if hv.last_timestamp == 0 {
dt = 0
}
hv.last_timestamp = t
if hv.target_on {
f := mathgl.Vec2{hv.fx, hv.fy}
v := mathgl.Vec2{hv.targetx, hv.targety}
v.Subtract(&f)
scale := 1 - float32(math.Pow(0.005, float64(dt)/1000))
v.Scale(scale)
f.Add(&v)
hv.fx = f.X
hv.fy = f.Y
}
}