當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Vec2.Transform方法代碼示例

本文整理匯總了Golang中github.com/runningwild/mathgl.Vec2.Transform方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vec2.Transform方法的具體用法?Golang Vec2.Transform怎麽用?Golang Vec2.Transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/runningwild/mathgl.Vec2的用法示例。


在下文中一共展示了Vec2.Transform方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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.Transform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。