當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。