当前位置: 首页>>代码示例>>Golang>>正文


Golang Seg2.Isect方法代码示例

本文整理汇总了Golang中github.com/runningwild/linear.Seg2.Isect方法的典型用法代码示例。如果您正苦于以下问题:Golang Seg2.Isect方法的具体用法?Golang Seg2.Isect怎么用?Golang Seg2.Isect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/runningwild/linear.Seg2的用法示例。


在下文中一共展示了Seg2.Isect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fireDoLine

func fireDoLine(c *cmwc.Cmwc, pos linear.Vec2, angle, stored float64, speed int, level *game.Level) fireExplosion {
	rng := rand.New(c)
	ray := (linear.Vec2{1, 0})
	// ray.Scale(math.Abs(rng.NormFloat64()/10) + 50)
	scale := (stored/5 + 50) * (1 + rng.Float64()*(0.2+stored/2000))
	ray = ray.Rotate(angle).Rotate(rng.NormFloat64() * (0.2 + stored/7500)).Scale(scale)
	seg := linear.Seg2{pos, pos.Add(ray)}
	base.DoOrdered(level.Room.Walls, func(a, b string) bool { return a < b }, func(_ string, poly linear.Poly) {
		for i := range poly {
			if seg.DoesIsect(poly.Seg(i)) {
				isect := seg.Isect(poly.Seg(i))
				seg.Q = isect
			}
		}
	})
	p1 := rng.Intn(speed)
	p2 := rng.Intn(speed)
	p3 := rng.Intn(speed)
	return fireExplosion{
		Pos:    seg.Q,
		Radius: rng.Float64()*40 + 30,
		Timer:  0,
		Start:  1*speed + p1,
		Peak:   4*speed + p1 + p2,
		End:    5*speed + p1 + p2 + p3,
	}
}
开发者ID:runningwild,项目名称:magnus,代码行数:27,代码来源:fire.go

示例2: Think

func (b *BaseEnt) Think(g *Game) {
	// This will clear out old conditions
	b.StatsInst.Think()

	var dead []int
	// Calling DoOrdered is too slow, so we just sort the Gids ourselves and go
	// through them in order.
	pids := make([]int, len(b.Processes))[0:0]
	for pid := range b.Processes {
		pids = append(pids, pid)
	}
	sort.Ints(pids)
	for _, pid := range pids {
		proc := b.Processes[pid]
		proc.Think(g)
		if proc.Dead() {
			dead = append(dead, pid)
		} else {
			b.StatsInst.ApplyCondition(proc)
		}
	}

	// Removed dead processes from the ent
	for _, id := range dead {
		delete(b.Processes, id)
	}

	if b.Delta.Speed < -1.0 {
		b.Delta.Speed = -1.0
	}
	if b.Delta.Speed > 1.0 {
		b.Delta.Speed = 1.0
	}

	// TODO: Speed is a complete misnomer now - fix it!
	force := b.Delta.Speed * (linear.Vec2{1, 0}).Rotate(b.Target.Angle).Dot((linear.Vec2{1, 0}).Rotate(b.Angle_))
	b.ApplyForce((linear.Vec2{1, 0}).Rotate(b.Angle_).Scale(force * b.Stats().MaxAcc()))

	mangle := math.Atan2(b.Velocity.Y, b.Velocity.X)
	friction := g.Friction
	b.Velocity = b.Velocity.Scale(
		math.Pow(friction, 1+3*math.Abs(math.Sin(b.Angle_-mangle))))

	if b.Velocity.Mag2() < 0.01 {
		b.Velocity = linear.Vec2{0, 0}
	} else {
		size := b.Stats().Size()
		sizeSq := size * size
		// We pretend that the player is started from a little behind wherever they
		// actually are.  This makes it a lot easier to get collisions to make sense
		// from frame to frame.
		epsilon := b.Velocity.Norm().Scale(size / 2)
		move := linear.Seg2{b.Position.Sub(epsilon), b.Position.Add(b.Velocity)}
		prev := b.Position
		walls := g.local.temp.WallCache.GetWalls(int(b.Position.X), int(b.Position.Y))
		for _, wall := range walls {
			// Don't bother with back-facing segments
			if wall.Right(b.Position) {
				continue
			}

			// Check against the segment itself
			if wall.Ray().Cross().Dot(move.Ray()) <= 0 {
				shiftNorm := wall.Ray().Cross().Norm()
				shift := shiftNorm.Scale(size)
				col := linear.Seg2{shift.Add(wall.P), shift.Add(wall.Q)}
				if move.DoesIsect(col) {
					cross := col.Ray().Cross()
					fix := linear.Seg2{move.Q, cross.Add(move.Q)}
					isect := fix.Isect(col)
					move.Q = isect
				}
			}
		}
		for _, wall := range walls {
			// Check against the leading vertex
			{
				v := wall.P
				originMove := linear.Seg2{move.P.Sub(v), move.Q.Sub(v)}
				originPerp := linear.Seg2{linear.Vec2{}, move.Ray().Cross()}
				dist := originMove.DistFromOrigin()
				if originPerp.DoesIsect(originMove) && dist < size {
					// Stop passthrough
					isect := originMove.Isect(originPerp).Add(v)
					diff := math.Sqrt(sizeSq - dist*dist)
					finalLength := isect.Sub(move.P).Mag() - diff
					move.Q = move.Ray().Norm().Scale(finalLength).Add(move.P)
				} else if v.Sub(move.Q).Mag2() < sizeSq {
					move.Q = move.Q.Sub(v).Norm().Scale(size).Add(v)
				}
			}
		}
		b.Position = move.Q
		b.Velocity = b.Position.Sub(prev)
	}

	if math.Abs(b.Angle_+b.Target.Angle-math.Pi) < 0.01 {
		b.Angle_ += 0.1
	} else {
		frac := 0.80
//.........这里部分代码省略.........
开发者ID:runningwild,项目名称:jota,代码行数:101,代码来源:base_ent.go

示例3: Think

func (p *Player) Think(g *Game) {
	if p.Exile_frames > 0 {
		p.Exile_frames--
		return
	}

	// This will clear out old conditions
	p.Stats.Think()
	var dead []int
	for i, process := range p.Processes {
		process.Think(g)
		if process.Phase() == PhaseComplete {
			dead = append(dead, i)
		}
	}
	for _, i := range dead {
		delete(p.Processes, i)
	}
	// And here we add back in all processes that are still alive.
	for _, process := range p.Processes {
		p.Stats.ApplyCondition(process)
	}

	if p.Delta.Speed > p.Stats.MaxAcc() {
		p.Delta.Speed = p.Stats.MaxAcc()
	}
	if p.Delta.Speed < -p.Stats.MaxAcc() {
		p.Delta.Speed = -p.Stats.MaxAcc()
	}
	if p.Delta.Angle < -p.Stats.MaxTurn() {
		p.Delta.Angle = -p.Stats.MaxTurn()
	}
	if p.Delta.Angle > p.Stats.MaxTurn() {
		p.Delta.Angle = p.Stats.MaxTurn()
	}

	in_lava := false
	for _, lava := range g.Room.Lava {
		if vecInsideConvexPoly(p.Pos(), lava) {
			in_lava = true
		}
	}
	if in_lava {
		p.Stats.ApplyDamage(stats.Damage{stats.DamageFire, 5})
	}

	p.Vx += p.Delta.Speed * math.Cos(p.Angle)
	p.Vy += p.Delta.Speed * math.Sin(p.Angle)
	mangle := math.Atan2(p.Vy, p.Vx)
	friction := g.Friction
	if in_lava {
		friction = g.Friction_lava
	}
	p.Vx *= math.Pow(friction, 1+3*math.Abs(math.Sin(p.Angle-mangle)))
	p.Vy *= math.Pow(friction, 1+3*math.Abs(math.Sin(p.Angle-mangle)))

	move := linear.MakeSeg2(p.X, p.Y, p.X+p.Vx, p.Y+p.Vy)
	size := 12.0
	px := p.X
	py := p.Y
	p.X += p.Vx
	p.Y += p.Vy
	for _, poly := range g.Room.Walls {
		for i := range poly {
			// First check against the leading vertex
			{
				v := poly[i]
				dist := v.DistToLine(move)
				if v.Sub(move.Q).Mag() < size {
					dist = v.Sub(move.Q).Mag()
					// Add a little extra here otherwise a player can sneak into geometry
					// through the corners
					ray := move.Q.Sub(v).Norm().Scale(size + 0.1)
					final := v.Add(ray)
					move.Q.X = final.X
					move.Q.Y = final.Y
				} else if dist < size {
					// TODO: This tries to prevent passthrough but has other problems
					// cross := move.Ray().Cross()
					// perp := linear.Seg2{v, cross.Sub(v)}
					// if perp.Left(move.P) != perp.Left(move.Q) {
					//   shift := perp.Ray().Norm().Scale(size - dist)
					//   move.Q.X += shift.X
					//   move.Q.Y += shift.Y
					// }
				}
			}

			// Now check against the segment itself
			w := poly.Seg(i)
			if w.Ray().Cross().Dot(move.Ray()) <= 0 {
				shift := w.Ray().Cross().Norm().Scale(size)
				col := linear.Seg2{shift.Add(w.P), shift.Add(w.Q)}
				if move.DoesIsect(col) {
					cross := col.Ray().Cross()
					fix := linear.Seg2{move.Q, cross.Add(move.Q)}
					isect := fix.Isect(col)
					move.Q.X = isect.X
					move.Q.Y = isect.Y
				}
//.........这里部分代码省略.........
开发者ID:dgthunder,项目名称:magnus,代码行数:101,代码来源:game.go


注:本文中的github.com/runningwild/linear.Seg2.Isect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。