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


Golang mgl32.Translate3D函数代码示例

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


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

示例1: ExampleRebase

func ExampleRebase() {
	parent1 := NewTransformStack()

	scale := mgl32.Scale3D(2, 2, 2)
	rot := mgl32.HomogRotate3DY(mgl32.DegToRad(90))
	trans := mgl32.Translate3D(5, 5, 5)

	parent1.Push(trans)
	parent1.Push(rot)
	parent1.Push(scale)

	parent2 := parent1.Copy()

	trans2 := mgl32.Translate3D(1, 1, 1)
	rot2 := mgl32.HomogRotate3DX(mgl32.DegToRad(45))
	parent1.Push(trans2)
	parent1.Push(rot2)

	// Replay the pushes the changes from parent1 after the copy onto parent2, as if
	// they had been done on parent2 instead
	parent2, err := Rebase(parent1, 4, parent2)

	if err != nil {
		panic(err)
	}

	// Now parent2 and parent 1 should be the same!
	fmt.Println(parent2.Peek().ApproxEqualThreshold(parent1.Peek(), 1e-4))
	// Output: true
}
开发者ID:rdterner,项目名称:mathgl,代码行数:30,代码来源:transformstack_test.go

示例2: init

func init() {
	uvRotations = make(map[int]*mgl32.Mat4)
	for i := 0; i < 4; i++ {
		matrix := mgl32.Translate3D(0.5, 0.5, 0.0).
			Mul4(mgl32.HomogRotate3DZ(float32(math.Pi * float32(i) / 2.0))).
			Mul4(mgl32.Translate3D(-0.5, -0.5, 0.0))
		uvRotations[i] = &matrix
	}
}
开发者ID:inkyblackness,项目名称:shocked-client,代码行数:9,代码来源:TileTextureMapRenderable.go

示例3: GetMtx

func (k PianoKey) GetMtx() mgl32.Mat4 {
	axis := mgl32.Vec3{1, 0, 0}
	keyLen := float32(2.0)
	if !k.white {
		keyLen = 1.0
	}
	modelMtx := mgl32.Ident4()
	modelMtx = modelMtx.Mul4(mgl32.Translate3D(k.Pos[0], k.Pos[1], k.Pos[2]-2))
	modelMtx = modelMtx.Mul4(mgl32.HomogRotate3D(k.Angle, axis))
	modelMtx = modelMtx.Mul4(mgl32.Translate3D(0, 0, keyLen))
	modelMtx = modelMtx.Mul4(mgl32.Scale3D(0.5, 0.5, keyLen))

	return modelMtx
}
开发者ID:xnattack,项目名称:GCSolutions,代码行数:14,代码来源:piano.go

示例4: Update

func (b *blockBreakComponent) Update() {
	if b.model != nil {
		b.model.Free()
	}
	bounds := chunkMap.Block(b.Location.X, b.Location.Y, b.Location.Z).CollisionBounds()
	tex := render.GetTexture(fmt.Sprintf("blocks/destroy_stage_%d", b.stage))

	var verts []*render.StaticVertex
	for _, bo := range bounds {
		// Slightly bigger than the block to prevent clipping
		bo = bo.Grow(0.01, 0.01, 0.01)
		verts = appendBox(verts,
			bo.Min.X(), bo.Min.Y(), bo.Min.Z(),
			bo.Max.X()-bo.Min.X(), bo.Max.Y()-bo.Min.Y(), bo.Max.Z()-bo.Min.Z(),
			[6]render.TextureInfo{
				tex, tex, tex, tex, tex, tex,
			})
	}
	b.model = render.NewStaticModel([][]*render.StaticVertex{verts})

	b.model.Matrix[0] = mgl32.Translate3D(
		float32(b.Location.X),
		-float32(b.Location.Y),
		float32(b.Location.Z),
	)
}
开发者ID:suedadam,项目名称:steven,代码行数:26,代码来源:blockentity.go

示例5: TestStackMultiPush

func TestStackMultiPush(t *testing.T) {
	stack := NewTransformStack()

	scale := mgl32.Scale3D(2, 2, 2)
	rot := mgl32.HomogRotate3DY(mgl32.DegToRad(90))
	trans := mgl32.Translate3D(4, 5, 6)

	stack.Push(trans)
	stack.Push(rot)

	if !stack.Peek().ApproxEqualThreshold(trans.Mul4(rot), 1e-4) {
		t.Errorf("Stack does not multiply first two pushes correctly")
	}

	stack.Push(scale)

	if !stack.Peek().ApproxEqualThreshold(trans.Mul4(rot).Mul4(scale), 1e-4) {
		t.Errorf("Stack does not multiple third push correctly")
	}

	stack.Unwind(2)
	stack.Push(scale)

	if !stack.Peek().ApproxEqualThreshold(trans.Mul4(scale), 1e-4) {
		t.Errorf("Unwinding and multiplying does not work correctly")
	}
}
开发者ID:rdterner,项目名称:mathgl,代码行数:27,代码来源:transformstack_test.go

示例6: onPaint

func onPaint(glctx gl.Context, sz size.Event) {

	glctx.Viewport(0, 0, sz.WidthPx, sz.HeightPx)
	glctx.ClearColor(0.5, 0.5, 0.5, 1)
	glctx.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	glctx.UseProgram(program)

	projectionMtx = mgl32.Perspective(45, float32(width)/float32(height), 0.1, 100)

	arcBallMtx := arcball.getMtx()

	glctx.UniformMatrix4fv(projection, projectionMtx[:])

	glctx.UniformMatrix4fv(view, arcBallMtx[:])

	glctx.BindBuffer(gl.ARRAY_BUFFER, triBuf)
	glctx.EnableVertexAttribArray(position)
	glctx.EnableVertexAttribArray(color)
	glctx.EnableVertexAttribArray(normals)

	vertSize := 4 * (coordsPerVertex + colorPerVertex + normalsPerVertex)

	glctx.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, vertSize, 0)
	glctx.VertexAttribPointer(color, colorPerVertex, gl.FLOAT, false, vertSize, 4*coordsPerVertex)
	glctx.VertexAttribPointer(normals, normalsPerVertex, gl.FLOAT, false, vertSize, 4*(coordsPerVertex+colorPerVertex))

	glctx.DepthMask(true)

	glctx.Uniform3fv(lightPos, light.Pos[:])
	glctx.Uniform3fv(lightIntensity, light.Intensities[:])

	for _, k := range piano.Keys {
		glctx.Uniform4fv(tint, k.Color[:])

		mtx := k.GetMtx()
		normMat := mtx.Mat3().Inv().Transpose()
		glctx.UniformMatrix3fv(normalMatrix, normMat[:])
		glctx.UniformMatrix4fv(model, mtx[:])
		glctx.DrawArrays(gl.TRIANGLES, 0, len(triangleData)/vertSize)
	}

	modelMtx := mgl32.Ident4()
	modelMtx = modelMtx.Mul4(mgl32.Translate3D(worldPos.X(), worldPos.Y(), worldPos.Z()))
	modelMtx = modelMtx.Mul4(mgl32.Scale3D(0.5, 0.5, 0.5))

	/*
		glctx.Uniform4fv(tint, red[:])
		// Disable depthmask so we dont get the pixel depth of the cursor cube
		glctx.DepthMask(false)
		glctx.UniformMatrix4fv(model, modelMtx[:])
		glctx.DepthMask(true)
	*/

	glctx.DisableVertexAttribArray(position)
	glctx.DisableVertexAttribArray(color)
	glctx.DisableVertexAttribArray(normals)

	fps.Draw(sz)
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:60,代码来源:main.go

示例7: renderCallback

func renderCallback(delta float64) {
	gl.Viewport(0, 0, int32(app.Width), int32(app.Height))
	gl.ClearColor(0.196078, 0.6, 0.8, 1.0) // some pov-ray sky blue
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// make the projection and view matrixes
	projection := mgl.Perspective(mgl.DegToRad(60.0), float32(app.Width)/float32(app.Height), 1.0, 200.0)
	view := app.CameraRotation.Mat4()
	view = view.Mul4(mgl.Translate3D(-app.CameraPos[0], -app.CameraPos[1], -app.CameraPos[2]))

	// draw the cube
	cube.Node.Draw(projection, view)

	// draw all of the bullets
	for _, bullet := range bullets {
		bullet.Node.Draw(projection, view)
	}

	// draw the backboard
	backboard.Node.Draw(projection, view)

	// draw the ground
	ground.Draw(projection, view)

	//time.Sleep(10 * time.Millisecond)
}
开发者ID:tbogdala,项目名称:cubez,代码行数:26,代码来源:ballistic.go

示例8: Update

/* Update transform matrix and right/up/forward vectors */
func (t *Transform) Update(dt float32) {
	// todo: avoid recalculating unless something has changed

	/* Update transform */
	rad := t.Rotation.Mul(math.Pi / 180.0) // translate rotaiton to radians
	rotation := mgl.AnglesToQuat(rad[0], rad[1], rad[2], mgl.XYZ).Mat4()
	scaling := mgl.Scale3D(t.Scale[0], t.Scale[1], t.Scale[2])
	translation := mgl.Translate3D(t.Position[0], t.Position[1], t.Position[2])

	/* New transform matrix: S * R * T */
	//m := scaling.Mul4(rotation.Mul4(translation))
	m := translation.Mul4(rotation.Mul4(scaling))

	/* Grab axis vectors from transformation matrix */
	t.Right[0] = m[4*0+0] // first column
	t.Right[1] = m[4*1+0]
	t.Right[2] = m[4*2+0]
	t.Up[0] = m[4*0+1] // second column
	t.Up[1] = m[4*1+1]
	t.Up[2] = m[4*2+1]
	t.Forward[0] = -m[4*0+2] // third column
	t.Forward[1] = -m[4*1+2]
	t.Forward[2] = -m[4*2+2]

	/* Update transformation matrix */
	t.Matrix = m
}
开发者ID:johanhenriksson,项目名称:goworld,代码行数:28,代码来源:transform.go

示例9: ToSpritesheetFrame

func (c SpritesheetFrameConfig) ToSpritesheetFrame() *SpritesheetFrame {
	var (
		texX = c.textureX / c.textureOriginalW
		texY = c.textureY / c.textureOriginalH
		texW = c.textureW / c.textureOriginalW
		texH = c.textureH / c.textureOriginalH
	)
	var (
		texMove   = mgl32.Translate3D(texX, -texH-texY, 0.0)
		texScale  = mgl32.Scale3D(texW, texH, 1.0)
		texRotate = mgl32.HomogRotate3DZ(mgl32.DegToRad(0))
		texAdj    = texMove.Mul4(texScale).Mul4(texRotate).Transpose()
	)
	var (
		ptScale = mgl32.Scale3D(c.sourceW/c.pxPerUnit, c.sourceH/c.pxPerUnit, 1.0)
		ptAdj   = ptScale.Transpose()
	)
	return &SpritesheetFrame{
		Frame: FrameConfig{
			PointAdjustment:   ptAdj,
			TextureAdjustment: texAdj,
		},
		Width:  c.sourceW / c.pxPerUnit,
		Height: c.sourceH / c.pxPerUnit,
	}
}
开发者ID:pikkpoiss,项目名称:twodee,代码行数:26,代码来源:spritesheet.go

示例10: GetTransformMat4

// GetTransformMat4 creates a transform matrix: scale * transform
func (r *Renderable) GetTransformMat4() mgl.Mat4 {
	scaleMat := mgl.Scale3D(r.Scale[0], r.Scale[1], r.Scale[2])
	transMat := mgl.Translate3D(r.Location[0], r.Location[1], r.Location[2])
	localRotMat := r.LocalRotation.Mat4()
	rotMat := r.Rotation.Mat4()
	modelTransform := rotMat.Mul4(transMat).Mul4(localRotMat).Mul4(scaleMat)
	return modelTransform
}
开发者ID:tbogdala,项目名称:cubez,代码行数:9,代码来源:exampleapp.go

示例11: TextTransform

func (this *TextRenderer) TextTransform(vertex mathgl.Vec4) mathgl.Vec4 {
	// apply font transforms
	scale := float32(this.size) / 100.0
	t := mathgl.Translate3D(curTotWidth, 0, 0).Mul4x1(vertex)

	t = mathgl.Scale3D(scale, scale, 1).Mul4x1(t)

	return t
}
开发者ID:Triangle345,项目名称:GT,代码行数:9,代码来源:TextRenderer.go

示例12: tickClouds

func tickClouds(delta float64) {
	if Client != nil && Client.WorldType != wtOverworld {
		render.DrawClouds = false
		if sunModel != nil {
			sunModel.Free()
			moonModel.Free()
			sunModel = nil
			moonModel = nil
		}
		return
	}
	render.DrawClouds = true
	if Client == nil && Client.entity != nil {
		return
	}
	if sunModel == nil {
		genSunModel()
	}

	phase := int((Client.WorldAge / 24000) % 8)
	if phase != moonPhase {
		moonPhase = phase
		genSunModel()
	}

	x, y, z := Client.entity.Position()

	time := Client.WorldTime / 12000
	ox := math.Cos(time*math.Pi) * 300
	oy := math.Sin(time*math.Pi) * 300

	sunModel.Matrix[0] = mgl32.Translate3D(
		float32(x+ox),
		-float32(y+oy),
		float32(z),
	).Mul4(mgl32.Rotate3DZ(-float32(time * math.Pi)).Mat4())

	moonModel.Matrix[0] = mgl32.Translate3D(
		float32(x-ox),
		-float32(y-oy),
		float32(z),
	).Mul4(mgl32.Rotate3DZ(math.Pi - float32(time*math.Pi)).Mat4())
}
开发者ID:num5,项目名称:steven,代码行数:43,代码来源:clouds.go

示例13: TestReseed

func TestReseed(t *testing.T) {
	stack := NewTransformStack()

	scale := mgl32.Scale3D(2, 2, 2)
	rot := mgl32.HomogRotate3DY(mgl32.DegToRad(90))
	trans := mgl32.Translate3D(4, 5, 6)

	stack.Push(trans)
	stack.Push(rot)
	stack.Push(scale)

	trans2 := mgl32.Translate3D(1, 2, 3)
	err := stack.Reseed(1, trans2)

	if err != nil {
		t.Fatalf("Rebase returned error when it should not %v", err)
	}

	if !stack.Peek().ApproxEqualThreshold(trans2.Mul4(rot).Mul4(scale), 1e-4) {
		t.Fatalf("Rebase does not remultiply correctly. Got\n %v expected\n %v. (Previous state:\n %v)", stack.Peek(), trans2.Mul4(rot).Mul4(scale), trans.Mul4(rot).Mul4(scale))
	}
}
开发者ID:rdterner,项目名称:mathgl,代码行数:22,代码来源:transformstack_test.go

示例14: TestRebase

func TestRebase(t *testing.T) {
	stack := NewTransformStack()
	stack2 := NewTransformStack()

	scale := mgl32.Scale3D(2, 2, 2)
	rot := mgl32.HomogRotate3DY(mgl32.DegToRad(90))
	trans := mgl32.Translate3D(4, 5, 6)
	trans2 := mgl32.Translate3D(1, 2, 3)

	stack.Push(trans)
	stack.Push(rot)

	stack2.Push(trans2)
	stack2.Push(scale)

	out, _ := Rebase(stack2, 1, stack)

	if !out.Peek().ApproxEqualThreshold(trans.Mul4(rot).Mul4(trans2).Mul4(scale), 1e-4) {
		t.Log("\n", out)
		t.Errorf("Rebase unsuccessful. Got\n %v, expected\n %v", out.Peek(), trans.Mul4(rot).Mul4(trans2).Mul4(scale))
	}
}
开发者ID:rdterner,项目名称:mathgl,代码行数:22,代码来源:transformstack_test.go

示例15: Draw

func (r *BatchRenderer) Draw(batch *Batch, x, y, rot float32) error {
	batch.Texture.Bind()
	gl.BindBuffer(gl.ARRAY_BUFFER, batch.Buffer)
	gl.EnableVertexAttribArray(r.PositionLoc)
	gl.VertexAttribPointer(r.PositionLoc, 3, gl.FLOAT, false, 5*4, gl.PtrOffset(0))
	gl.EnableVertexAttribArray(r.TextureLoc)
	gl.VertexAttribPointer(r.TextureLoc, 2, gl.FLOAT, false, 5*4, gl.PtrOffset(3*4))
	m := mgl32.Translate3D(x, y, 0.0).Mul4(mgl32.HomogRotate3DZ(rot))
	gl.UniformMatrix4fv(r.ModelViewLoc, 1, false, &m[0])
	gl.Uniform2f(r.TexOffsetLoc, batch.textureOffset.X(), batch.textureOffset.Y())
	gl.DrawArrays(gl.TRIANGLES, 0, int32(batch.Count))
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	return nil
}
开发者ID:pikkpoiss,项目名称:twodee,代码行数:14,代码来源:renderer_batch.go


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