本文整理汇总了Golang中github.com/runningwild/linear.Vec2.Sub方法的典型用法代码示例。如果您正苦于以下问题:Golang Vec2.Sub方法的具体用法?Golang Vec2.Sub怎么用?Golang Vec2.Sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/runningwild/linear.Vec2
的用法示例。
在下文中一共展示了Vec2.Sub方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: thinkAbility
func (l *LocalData) thinkAbility(g *Game, abs *personalAbilities, gid Gid) {
if abs.activeAbility == nil {
return
}
var mouse linear.Vec2
if l.mode == LocalModeArchitect {
mx, my := l.sys.GetCursorPos()
mouse.X = float64(mx)
mouse.Y = float64(my)
mouse = mouse.Sub(l.architect.camera.regionPos)
mouse.X /= l.architect.camera.regionDims.X
mouse.Y /= l.architect.camera.regionDims.Y
mouse.X *= l.architect.camera.current.dims.X
mouse.Y *= l.architect.camera.current.dims.Y
mouse = mouse.Sub(l.architect.camera.current.dims.Scale(0.5))
mouse = mouse.Add(l.architect.camera.current.mid)
}
events, die := abs.activeAbility.Think(gid, g, mouse)
for _, event := range events {
l.engine.ApplyEvent(event)
}
if die {
base.Log().Printf("Deactivate on die")
more_events := abs.activeAbility.Deactivate(gid)
abs.activeAbility = nil
for _, event := range more_events {
l.engine.ApplyEvent(event)
}
}
}
示例2: Dir
func (pd *PathingData) Dir(src, dst linear.Vec2) linear.Vec2 {
x := int(src.X / pathingDataGrid)
y := int(src.Y / pathingDataGrid)
x2 := int(dst.X / pathingDataGrid)
y2 := int(dst.Y / pathingDataGrid)
if x < 0 || y < 0 || x >= len(pd.dstData) || y >= len(pd.dstData[x]) {
return linear.Vec2{0, 0}
}
if x2 < 0 || y2 < 0 || x2 >= len(pd.dstData) || y2 >= len(pd.dstData[x2]) {
return linear.Vec2{0, 0}
}
dstData := &pd.dstData[x2][y2]
dstData.RLock()
defer dstData.RUnlock()
if !dstData.complete {
dstData.once.Do(func() {
base.Log().Printf("Eval: %2.2v %2.2v", src, dst)
go func() {
pd.finishDirectPaths.Wait()
dstData.Lock()
defer dstData.Unlock()
pd.findAllPaths(x2, y2)
dstData.complete = true
}()
})
return dst.Sub(src).Norm()
}
cell := pd.dirs[x2][y2][x][y]
if !cell.direct {
return (linear.Vec2{1, 0}).Rotate(cell.angle)
}
return dst.Sub(src).Norm()
}
示例3: Think
func (p *pullProcess) Think(g *game.Game) {
_player := g.GetEnt(p.Player_id)
player := _player.(*game.Player)
base_force := p.Force * p.supplied / p.required
for _, _target := range g.Ents {
target, ok := _target.(*game.Player)
if !ok || target == player {
continue
}
target_pos := linear.Vec2{target.X, target.Y}
ray := target_pos.Sub(player.Pos())
target_angle := ray.Angle() - player.Angle
for target_angle < 0 {
target_angle += math.Pi * 2
}
for target_angle > math.Pi*2 {
target_angle -= math.Pi * 2
}
if target_angle > p.Angle/2 && target_angle < math.Pi*2-p.Angle/2 {
continue
}
ray = player.Pos().Sub(target.Pos())
// dist := ray.Mag()
ray = ray.Norm()
force := base_force // / math.Pow(dist, p.Angle/(2*math.Pi))
target.ApplyForce(ray.Scale(-force))
player.ApplyForce(ray.Scale(force))
}
}
示例4: cursorPosInGameCoords
func (editor *editorData) cursorPosInGameCoords(room *Room) linear.Vec2 {
x, y := editor.sys.GetCursorPos()
pos := linear.Vec2{float64(x), float64(y)}
regionPos := linear.Vec2{float64(editor.region.Pos.X), float64(editor.region.Pos.Y)}
pos = pos.Sub(regionPos)
pos = pos.Scale(float64(room.Dx) / float64(editor.region.Dims.Dx))
cameraOffset := linear.Vec2{
editor.camera.current.dims.X/2 - editor.camera.current.mid.X,
editor.camera.current.dims.Y/2 - editor.camera.current.mid.Y,
}
pos = pos.Sub(cameraOffset)
return pos
}
示例5: 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)
})
}
示例6: FocusRegion
func (camera *cameraInfo) FocusRegion(g *Game, side int) {
min := linear.Vec2{1e9, 1e9}
max := linear.Vec2{-1e9, -1e9}
player := g.Ents[g.local.Gid]
if player == nil {
min.X = 0
min.Y = 0
max.X = float64(g.Level.Room.Dx)
max.Y = float64(g.Level.Room.Dy)
} else {
min.X = player.Pos().X - player.Stats().Vision()
min.Y = player.Pos().Y - player.Stats().Vision()
if min.X < 0 {
min.X = 0
}
if min.Y < 0 {
min.Y = 0
}
max.X = player.Pos().X + player.Stats().Vision()
max.Y = player.Pos().Y + player.Stats().Vision()
if max.X > float64(g.Level.Room.Dx) {
max.X = float64(g.Level.Room.Dx)
}
if max.Y > float64(g.Level.Room.Dy) {
max.Y = float64(g.Level.Room.Dy)
}
}
mid := min.Add(max).Scale(0.5)
dims := max.Sub(min)
if dims.X/dims.Y < camera.regionDims.X/camera.regionDims.Y {
dims.X = dims.Y * camera.regionDims.X / camera.regionDims.Y
} else {
dims.Y = dims.X * camera.regionDims.Y / camera.regionDims.X
}
camera.target.dims = dims
camera.target.mid = mid
camera.approachTarget()
}
示例7: 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})
})
}
示例8: findAllDirectPaths
func (pd *PathingData) findAllDirectPaths(dstx, dsty int, room *Room) {
defer pd.finishDirectPaths.Done()
dst := linear.Vec2{(float64(dstx) + 0.5) * pathingDataGrid, (float64(dsty) + 0.5) * pathingDataGrid}
for x := range pd.dirs[dstx][dsty] {
for y := range pd.dirs[dstx][dsty][x] {
src := linear.Vec2{(float64(x) + 0.5) * pathingDataGrid, (float64(y) + 0.5) * pathingDataGrid}
if dstx == 1 && dsty == 4 {
}
if room.ExistsLos(src, dst) {
if dstx == 1 && dsty == 4 {
}
pd.conns[dstx][dsty] = append(pd.conns[dstx][dsty], pathingConnection{
x: x,
y: y,
dist: dst.Sub(src).Mag(),
})
data := &pd.dirs[dstx][dsty][x][y]
data.angle = src.Sub(dst).Angle()
data.direct = true
// data.filled = true
}
}
}
}
示例9: doInvadersFocusRegion
func (camera *cameraInfo) doInvadersFocusRegion(g *Game, side int) {
min := linear.Vec2{1e9, 1e9}
max := linear.Vec2{-1e9, -1e9}
hits := 0
for _, ent := range g.temp.AllEnts {
if ent.Side() != side {
continue
}
if player, ok := ent.(*PlayerEnt); ok {
hits++
pos := player.Pos()
if pos.X < min.X {
min.X = pos.X
}
if pos.Y < min.Y {
min.Y = pos.Y
}
if pos.X > max.X {
max.X = pos.X
}
if pos.Y > max.Y {
max.Y = pos.Y
}
}
}
if hits == 0 {
min.X = 0
min.Y = 0
max.X = float64(g.Levels[GidInvadersStart].Room.Dx)
max.Y = float64(g.Levels[GidInvadersStart].Room.Dy)
} else {
min.X -= stats.LosPlayerHorizon + 50
min.Y -= stats.LosPlayerHorizon + 50
if min.X < 0 {
min.X = 0
}
if min.Y < 0 {
min.Y = 0
}
max.X += stats.LosPlayerHorizon + 50
max.Y += stats.LosPlayerHorizon + 50
if max.X > float64(g.Levels[GidInvadersStart].Room.Dx) {
max.X = float64(g.Levels[GidInvadersStart].Room.Dx)
}
if max.Y > float64(g.Levels[GidInvadersStart].Room.Dy) {
max.Y = float64(g.Levels[GidInvadersStart].Room.Dy)
}
}
mid := min.Add(max).Scale(0.5)
dims := max.Sub(min)
if dims.X/dims.Y < camera.regionDims.X/camera.regionDims.Y {
dims.X = dims.Y * camera.regionDims.X / camera.regionDims.Y
} else {
dims.Y = dims.X * camera.regionDims.Y / camera.regionDims.X
}
camera.target.dims = dims
camera.target.mid = mid
if camera.current.mid.X == 0 && camera.current.mid.Y == 0 {
// On the very first frame the current midpoint will be (0,0), which should
// never happen after the game begins. In this one case we'll immediately
// set current to target so we don't start off by approaching it from the
// origin.
camera.current = camera.target
} else {
// speed is in (0, 1), the higher it is, the faster current approaches target.
speed := 0.1
camera.current.dims = camera.current.dims.Scale(1 - speed).Add(camera.target.dims.Scale(speed))
camera.current.mid = camera.current.mid.Scale(1 - speed).Add(camera.target.mid.Scale(speed))
}
}