Пример #1
0
func (s *FpsController) SetupCamera() {
	hor := v.MatrixRotate(v.Angle(-s.HorAxis), 0, 1, 0)
	ver := v.MatrixRotate(v.Angle(-s.VerAxis), 1, 0, 0)
	tr := v.MatrixTranslate(-s.Pos.X, -s.Pos.Y, -s.Pos.Z)

	rot := ver.Mul(hor)
	mat := rot.Mul(tr)
	s.Camera.SetCustomModelview(s.Pos.X, s.Pos.Y, s.Pos.Z, &mat)
}
Пример #2
0
func CreateLookAtMatrix(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz float32) *v.Matrix4 {

	var x, y, z [3]float32
	var mag float32

	/* Make rotation matrix */

	/* Z vector */
	z[0] = centerx - eyex
	z[1] = centery - eyey
	z[2] = centerz - eyez
	mag = float32(math.Sqrt(float64(z[0]*z[0] + z[1]*z[1] + z[2]*z[2])))
	if mag != 0 { /* mpichler, 19950515 */
		z[0] /= mag
		z[1] /= mag
		z[2] /= mag
	}

	/* Y vector */
	y[0] = upx
	y[1] = upy
	y[2] = upz

	/* X vector = Z cross Y */
	x[0] = z[1]*y[2] - z[2]*y[1]
	x[1] = -z[0]*y[2] + z[2]*y[0]
	x[2] = z[0]*y[1] - z[1]*y[0]

	mag = float32(math.Sqrt(float64(x[0]*x[0] + x[1]*x[1] + x[2]*x[2])))
	if mag != 0 {
		x[0] /= mag
		x[1] /= mag
		x[2] /= mag
	}

	/* Recompute Y = X cross Z */
	y[0] = x[1]*z[2] - x[2]*z[1]
	y[1] = -x[0]*z[2] + x[2]*z[0]
	y[2] = x[0]*z[1] - x[1]*z[0]

	// TODO inline this shit
	a := (v.Matrix4{x[0], x[1], -x[2], 0,
		y[0], y[1], -y[2], 0,
		z[0], z[1], -z[2], 0,
		0, 0, 0, 1.0})
	r := a.Mul(v.MatrixTranslate(-eyex, -eyey, -eyez))
	return &r
}
Пример #3
0
func (s *SimpleRendererWModule) Render() {
	rop := glutils.NewSimpleRenderOp(false, s.Mesh)
	pos := s.Object.Position
	matrix := v.MatrixTranslate(pos.X, pos.Y, pos.Z)
	rop.Render(s.Context.Camera, matrix)
}