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


Golang mgl32.DegToRad函数代码示例

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


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

示例1: TestStackPushPopPeek

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

	if !stack.Peek().ApproxEqual(mgl32.Ident4()) {
		t.Errorf("Peek not working")
	}

	stack.Push(mgl32.HomogRotate3DY(mgl32.DegToRad(90)))

	if !stack.Peek().ApproxEqual(mgl32.HomogRotate3DY(mgl32.DegToRad(90))) {
		t.Errorf("Peek not working")
	}

	if stack.Len() != 2 {
		t.Errorf("Peek alters stack length")
	}

	pop, err := stack.Pop()
	if err != nil || !pop.ApproxEqual(mgl32.HomogRotate3DY(mgl32.DegToRad(90))) {
		t.Errorf("Pop is unsuccessful")
	}

	if stack.Len() != 1 {
		t.Errorf("Pop does not actually shorten stack")
	}

	_, err = stack.Pop()

	if err == nil {
		t.Errorf("Popping stack with 1 element does not return error as expected")
	}
}
开发者ID:rdterner,项目名称:mathgl,代码行数:32,代码来源:transformstack_test.go

示例2: GetCone

// GetCone returns the Source's directional volume cones by inner angle, outer angle,
// and outer volume.
func (s *Source) GetCone() (float32, float32, float32) {
	if s.isValid() {
		c := s.source.Cone()
		return mgl32.DegToRad(float32(c.InnerAngle)), mgl32.DegToRad(float32(c.OuterAngle)), c.OuterVolume
	}
	return mgl32.DegToRad(float32(s.cone.InnerAngle)), mgl32.DegToRad(float32(s.cone.OuterAngle)), s.cone.OuterVolume
}
开发者ID:tanema,项目名称:amore,代码行数:9,代码来源:source.go

示例3: 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

示例4: NewTransform

//NewTransform defines a new Rotation and Translation
//x, y, z are the angle in degrees rotation around the repsective axis
//addition is true when this will be applied in addition to an existing orientation
//localref is true if the orientation should be applied in the object local reference
//or in the absolute reference.  If addition is false this has no effect
//xt, yt, zt are the translation offset to apply in the x, y, and z axis
//transabs is true when this translation will be applied in relation to the current
//translation ZXY YZX XYZ
func NewTransform(x, y, z float32, rot RotationType, xt, yt, zt float32, tran TranslationType) *Transform {
	return &Transform{
		quat:  mgl32.AnglesToQuat(mgl32.DegToRad(z), mgl32.DegToRad(y), mgl32.DegToRad(x), mgl32.ZYX),
		rType: rot,
		trans: mgl32.Vec3{xt, yt, zt},
		tType: tran,
	}
}
开发者ID:bvandre,项目名称:object,代码行数:16,代码来源:transform.go

示例5: 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

示例6: 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

示例7: onStart

func onStart(glctx gl.Context, sz size.Event) {
	log.Printf("creating GL program")
	var err error
	keystate = map[touch.Sequence]int{}
	program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	glctx.Enable(gl.DEPTH_TEST)

	position = glctx.GetAttribLocation(program, "position")
	texCordIn = glctx.GetAttribLocation(program, "texCordIn")
	color = glctx.GetUniformLocation(program, "color")
	drawi = glctx.GetUniformLocation(program, "drawi")
	projection = glctx.GetUniformLocation(program, "projection")
	camera = glctx.GetUniformLocation(program, "camera")

	loadTexture(glctx)
	glctx.UseProgram(program)

	projectionMat := mgl32.Perspective(mgl32.DegToRad(75.0), float32(1), 0.5, 40.0)
	glctx.UniformMatrix4fv(projection, projectionMat[:])

	cameraMat := mgl32.LookAtV(mgl32.Vec3{0.5, 0, 1.5}, mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 1, 0})
	glctx.UniformMatrix4fv(camera, cameraMat[:])

	board = NewBoard(glctx, float32(0.05), 10)

	numKeys := len(board.bigKeys) + len(board.smallKeys)

	InitializeSound(numKeys)
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:34,代码来源:main.go

示例8: 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

示例9: makePerspective

func makePerspective(fov, aspect, near, far float32) mgl32.Mat4 {
	ymax := near * float32(math.Tan(float64(mgl32.DegToRad(fov*0.5))))
	ymin := -ymax
	xmin := ymin * aspect
	xmax := ymax * aspect

	return mgl32.Frustum(xmin, xmax, ymin, ymax, near, far)
}
开发者ID:nobonobo,项目名称:go-three,代码行数:8,代码来源:perspective_camera.go

示例10: Load

// Load loads and sets up the model
func (m *Model) Load(fileName string) {

	m.loadFile(fileName)

	shader := sm.Shader{VertSrcFile: m.data.VertShaderFile, FragSrcFile: m.data.FragShaderFile, Name: fmt.Sprintf("%s:%s", m.data.VertShaderFile, m.data.FragShaderFile)}
	program, err := m.shaders.LoadProgram(shader, false)
	if err != nil {
		return
	}
	m.currentProgram = program

	gl.UseProgram(m.currentProgram)

	m.projection = mgl32.Perspective(mgl32.DegToRad(45.0), float32(windowWidth)/windowHeight, 0.1, 10.0)
	m.projectionUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("projection\x00"))
	gl.UniformMatrix4fv(m.projectionUniform, 1, false, &m.projection[0])

	m.camera = mgl32.LookAtV(mgl32.Vec3{3, 3, 3}, mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 1, 0})
	m.cameraUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("camera\x00"))
	gl.UniformMatrix4fv(m.cameraUniform, 1, false, &m.camera[0])

	m.modelUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("model\x00"))
	gl.UniformMatrix4fv(m.modelUniform, 1, false, &m.model[0])

	m.textureUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("tex\x00"))
	gl.Uniform1i(m.textureUniform, 0)

	gl.BindFragDataLocation(m.currentProgram, 0, gl.Str("outputColor\x00"))

	// Load the texture
	m.textures.LoadTexture(m.data.TextureFile, m.data.TextureFile)

	// Configure the vertex data
	gl.GenVertexArrays(1, &m.vao)
	gl.BindVertexArray(m.vao)

	var vbo uint32
	gl.GenBuffers(1, &vbo)
	gl.BindBuffer(gl.ARRAY_BUFFER, vbo)
	gl.BufferData(gl.ARRAY_BUFFER, len(m.data.Verts)*4, gl.Ptr(m.data.Verts), gl.STATIC_DRAW)

	vertAttrib := uint32(gl.GetAttribLocation(m.currentProgram, gl.Str("vert\x00")))
	gl.EnableVertexAttribArray(vertAttrib)
	gl.VertexAttribPointer(vertAttrib, 3, gl.FLOAT, false, m.data.VertSize*4, gl.PtrOffset(0)) // 4:number of bytes in a float32

	texCoordAttrib := uint32(gl.GetAttribLocation(m.currentProgram, gl.Str("vertTexCoord\x00")))
	gl.EnableVertexAttribArray(texCoordAttrib)
	gl.VertexAttribPointer(texCoordAttrib, 2, gl.FLOAT, true, m.data.VertSize*4, gl.PtrOffset(3*4)) // 4:number of bytes in a float32

	if m.data.Indexed {
		var indices uint32
		gl.GenBuffers(1, &indices)
		gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, indices)
		gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, len(m.data.Indices)*4, gl.Ptr(m.data.Indices), gl.STATIC_DRAW)
	}

	gl.BindVertexArray(0)
}
开发者ID:Ariemeth,项目名称:frame-assault-2,代码行数:59,代码来源:model.go

示例11: SetPerspective

func SetPerspective(width, height int) {
	Projection := mathgl.Perspective(mathgl.DegToRad(45.0), float32(width/height), 0.1, 100.0)
	viewM = mathgl.LookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
	projectionM = Projection

	gl.Disable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

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

示例12: EngineLoop

//TestLoop is a method that initiate the game
func EngineLoop(window *glfw.Window) {
	mat := mgl32.Perspective(mgl32.DegToRad(45.0), float32(graphics.WIDTH)/graphics.HEIGHT, 0.1, 100.0).Mul4(mgl32.Translate3D(0.0, 0.0, -5.0))

	shader, err := mvcShader.CreateMVCShader()
	if err != nil {
		panic(err)
	}
	mesh := cubeMesh.CreateVertexArray()
	newEngine := Engine{mat: mat, shader: shader.BlankShader, mesh: mesh, BaseEngine: BaseEngine{run: true, window: window}}
	mesh.SetPos(newEngine.shader)
	newEngine.loop(&newEngine)

}
开发者ID:manueldun,项目名称:Game,代码行数:14,代码来源:Engine.go

示例13: Display

func (me *test) Display(c *Core) {
	me.o1.Draw(c)
	me.o2.Draw(c)

	projection := mgl32.Perspective(mgl32.DegToRad(Fov), float32(WindowWidth)/WindowHeight, Near, Far)
	view := mgl32.LookAtV(mgl32.Vec3{3, 3, 3}, mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 1, 0})
	model := mgl32.Ident4()
	MVP := projection.Mul4(view).Mul4(model)

	gl.UniformMatrix4fv(mvpLoc, 1, false, &MVP[0])
	gl.Uniform1i(TexLoc, 0)

}
开发者ID:Nekony,项目名称:go-gl-test,代码行数:13,代码来源:test.go

示例14: GetMouseVector

func (c *Camera) GetMouseVector(windowSize mgl32.Vec2, mouse mgl32.Vec2) mgl32.Vec3 {
	v, err := mgl32.UnProject(
		mgl32.Vec3{mouse.X(), windowSize.Y() - mouse.Y(), 0.5},
		mgl32.LookAtV(c.Translation, c.Lookat, c.Up),
		mgl32.Perspective(mgl32.DegToRad(c.Angle), windowSize.X()/windowSize.Y(), c.Near, c.Far),
		0, 0, int(windowSize.X()), int(windowSize.Y()),
	)
	if err == nil {
		return v.Sub(c.Translation).Normalize()
	} else {
		log.Println("Error converting camera vector: ", err)
	}
	return c.Lookat
}
开发者ID:walesey,项目名称:go-engine,代码行数:14,代码来源:camera.go

示例15: GetModel

func (i *Instance) GetModel() mgl32.Mat4 {
	if i.dirty {
		var model mgl32.Mat4
		model = mgl32.Translate3D(
			i.position.X(),
			i.position.Y(),
			i.position.Z(),
		)
		model = model.Mul4(mgl32.HomogRotate3DZ(mgl32.DegToRad(i.rotation)))
		model = model.Mul4(mgl32.Scale3D(i.scale.X(), i.scale.Y(), i.scale.Z()))
		i.model = model
		i.dirty = false
	}
	return i.model
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:15,代码来源:instance.go


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