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


Golang mathgl.Vec2类代码示例

本文整理汇总了Golang中github.com/runningwild/mathgl.Vec2的典型用法代码示例。如果您正苦于以下问题:Golang Vec2类的具体用法?Golang Vec2怎么用?Golang Vec2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: 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))
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:25,代码来源:house_viewer.go

示例2: TurnToFace

func (e *Entity) TurnToFace(x, y int) {
	target := mathgl.Vec2{float32(x), float32(y)}
	source := mathgl.Vec2{float32(e.X), float32(e.Y)}
	var seg mathgl.Vec2
	seg.Assign(&target)
	seg.Subtract(&source)
	target_facing := facing(seg)
	f_diff := target_facing - e.sprite.sp.StateFacing()
	if f_diff != 0 {
		f_diff = (f_diff + 6) % 6
		if f_diff > 3 {
			f_diff -= 6
		}
		for f_diff < 0 {
			e.sprite.sp.Command("turn_left")
			f_diff++
		}
		for f_diff > 0 {
			e.sprite.sp.Command("turn_right")
			f_diff--
		}
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:23,代码来源:entity.go

示例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
	}
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:17,代码来源:house_viewer.go

示例4: 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
}
开发者ID:RickDakan,项目名称:haunts,代码行数:28,代码来源:entity.go

示例5: setupGlStuff

func (wt *WallTexture) setupGlStuff(x, y, dx, dy int, gl_ids *wallTextureGlIds) {
	if gl_ids.vbuffer != 0 {
		gl.DeleteBuffers(1, &gl_ids.vbuffer)
		gl.DeleteBuffers(1, &gl_ids.left_buffer)
		gl.DeleteBuffers(1, &gl_ids.right_buffer)
		gl.DeleteBuffers(1, &gl_ids.floor_buffer)
		gl_ids.vbuffer = 0
		gl_ids.left_buffer = 0
		gl_ids.right_buffer = 0
		gl_ids.floor_buffer = 0
	}

	// All vertices for both walls and the floor will go here and get sent to
	// opengl all at once
	var vs []roomVertex

	// Conveniently casted values
	frx := float32(x)
	fry := float32(y)
	frdx := float32(dx)
	frdy := float32(dy)
	tdx := float32(wt.Texture.Data().Dx()) / 100
	tdy := float32(wt.Texture.Data().Dy()) / 100

	wtx := wt.X
	wty := wt.Y
	wtr := wt.Rot

	if wtx > frdx {
		wtr -= 3.1415926535 / 2
	}

	// Floor
	verts := []mathgl.Vec2{
		{-tdx / 2, -tdy / 2},
		{-tdx / 2, tdy / 2},
		{tdx / 2, tdy / 2},
		{tdx / 2, -tdy / 2},
	}
	var m, run mathgl.Mat3
	run.Identity()
	m.Translation(wtx, wty)
	run.Multiply(&m)
	m.RotationZ(wtr)
	run.Multiply(&m)
	if wt.Flip {
		m.Scaling(-1, 1)
		run.Multiply(&m)
	}
	for i := range verts {
		verts[i].Transform(&run)
	}
	p := mathgl.Poly(verts)
	p.Clip(&mathgl.Seg2{A: mathgl.Vec2{0, 0}, B: mathgl.Vec2{0, frdy}})
	p.Clip(&mathgl.Seg2{A: mathgl.Vec2{0, frdy}, B: mathgl.Vec2{frdx, frdy}})
	p.Clip(&mathgl.Seg2{A: mathgl.Vec2{frdx, frdy}, B: mathgl.Vec2{frdx, 0}})
	p.Clip(&mathgl.Seg2{A: mathgl.Vec2{frdx, 0}, B: mathgl.Vec2{0, 0}})
	if len(p) >= 3 {
		// floor indices
		var is []uint16
		for i := 1; i < len(p)-1; i++ {
			is = append(is, uint16(len(vs)+0))
			is = append(is, uint16(len(vs)+i))
			is = append(is, uint16(len(vs)+i+1))
		}
		gl.GenBuffers(1, &gl_ids.floor_buffer)
		gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl_ids.floor_buffer)
		gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, gl.Sizeiptr(int(unsafe.Sizeof(is[0]))*len(is)), gl.Pointer(&is[0]), gl.STATIC_DRAW)
		gl_ids.floor_count = gl.Sizei(len(is))

		run.Inverse()
		for i := range p {
			v := mathgl.Vec2{p[i].X, p[i].Y}
			v.Transform(&run)
			vs = append(vs, roomVertex{
				x:     p[i].X,
				y:     p[i].Y,
				u:     v.X/tdx + 0.5,
				v:     -(v.Y/tdy + 0.5),
				los_u: (fry + p[i].Y) / LosTextureSize,
				los_v: (frx + p[i].X) / LosTextureSize,
			})
		}
	}

	// Left Wall
	verts = []mathgl.Vec2{
		{-tdx / 2, -tdy / 2},
		{-tdx / 2, tdy / 2},
		{tdx / 2, tdy / 2},
		{tdx / 2, -tdy / 2},
	}
	run.Identity()
	m.Translation(wtx, wty)
	run.Multiply(&m)
	m.RotationZ(wtr)
	run.Multiply(&m)
	if wt.Flip {
		m.Scaling(-1, 1)
		run.Multiply(&m)
//.........这里部分代码省略.........
开发者ID:RickDakan,项目名称:haunts,代码行数:101,代码来源:wall_texture.go


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