Exemplo n.º 1
1
// Check that the inverse of a perspective view is correct.
func TestInverseVp(t *testing.T) {
	v := newCamera()
	v.at.Loc.SetS(10, 10, 10)
	v.at.Rot.SetAa(1, 0, 0, -lin.Rad(90))
	vm := VP(v.at, lin.NewQ(), &lin.M4{})
	ivm := ivp(v.at, &lin.Q{X: 1, Y: 0, Z: 0, W: 1}, lin.NewQ(), &lin.M4{})
	if !vm.Mult(vm, ivm).Aeq(lin.M4I) {
		t.Errorf("Matrix times inverse should be identity")
	}
}
Exemplo n.º 2
1
func (c *camera) SetYaw(deg float64) {
	c.ydeg = deg
	c.yrot.SetAa(0, 1, 0, lin.Rad(c.ydeg))
	c.at.Rot.Mult(c.xrot, c.yrot)
	c.updateTransform()
}
Exemplo n.º 3
0
Arquivo: pov.go Projeto: toophy/vu
// Implement Pov.
func (p *pov) Spin(x, y, z float64) {
	if x != 0 {
		p.rot.SetAa(1, 0, 0, lin.Rad(x))
		p.at.Rot.Mult(p.rot, p.at.Rot)
	}
	if y != 0 {
		p.rot.SetAa(0, 1, 0, lin.Rad(y))
		p.at.Rot.Mult(p.rot, p.at.Rot)
	}
	if z != 0 {
		p.rot.SetAa(0, 0, 1, lin.Rad(z))
		p.at.Rot.Mult(p.rot, p.at.Rot)
	}
}
Exemplo n.º 4
0
Arquivo: tr.go Projeto: skyview059/vu
// drawScene renders the 3D models consisting of one VAO
func (tag *trtag) drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	tag.checkError("gl.Clear")
	gl.UseProgram(tag.shaders)
	tag.checkError("gl.UseProgram")
	gl.BindVertexArray(tag.vao)
	tag.checkError("gl.BindVertexArray")

	// Use a modelview matrix and quaternion to rotate the 3D object.
	tag.mvp64.SetQ(lin.NewQ().SetAa(0, 1, 0, lin.Rad(-tag.rotateAngle)))
	tag.mvp64.TranslateMT(0, 0, -4)
	tag.mvp.Set(tag.mvp64.Mult(tag.mvp64, tag.persp))
	gl.UniformMatrix4fv(tag.mvpRef, 1, false, tag.mvp.Pointer())
	if err := gl.GetError(); err != 0 {
		fmt.Printf("gl.UniformMatrix error %d\n", err)
	}
	gl.DrawElements(gl.TRIANGLES, int32(len(tag.faces)), gl.UNSIGNED_BYTE, 0)
	if err := gl.GetError(); err != 0 {
		fmt.Printf("gl.DrawElements error %d\n", err)
	}

	// cleanup
	gl.UseProgram(0)
	tag.checkError("gl.UseProgram-0")
	gl.BindVertexArray(0)
	tag.checkError("gl.BindVertexArray-0")

	// rotate based on time... not on how fast the computer runs.
	if time.Now().Sub(tag.lastTime).Seconds() > 0.01 {
		tag.rotateAngle += 1
		tag.lastTime = time.Now()
	}
}
Exemplo n.º 5
0
// XZ_XY perspective to ortho view transform.
// Can help transform a 3D map to a 2D overlay.
func XZ_XY(at *lin.T, scr *lin.Q, vm *lin.M4) *lin.M4 {
	rot := scr.SetAa(1, 0, 0, -lin.Rad(90))
	l := at.Loc
	return vm.SetQ(rot).ScaleMS(1, 1, 0).TranslateTM(-l.X, -l.Y, -l.Z)
}