Пример #1
0
// Perspective sets m to a screen space perspective with origin at bottom-left.
func Perspective(m *f32.Mat4, l, r float32, b, t float32) {
	m.Identity()
	// TODO i think [2][2] is best as t-b, or, shortest path, but maybe worth picking something that's consistent
	// e.g. always 1000
	(*m)[0][0] = 2 / (r - l)
	(*m)[0][3] = -1 // offset for [0][0]
	(*m)[1][1] = 2 / (t - b)
	(*m)[1][3] = -1               // offset for [1][1]
	(*m)[2][2] = 2 / (r * 10)     //(r - l) // TODO should maybe pick consistent result, such as whichever is smaller; r-l or t-b
	(*m)[3][2] = -(*m)[2][2] * 10 // pronounced z effect with increased factor
}
Пример #2
0
// Ortho provides a general purpose orthographic projection.
// TODO probably just get rid of this and pass in zero'd out z to perspective
func Ortho(m *f32.Mat4, l, r float32, b, t float32, n, f float32) {
	m.Identity()
	m.Scale(m, 2/(r-l), 2/(t-b), 2/(f-n))
	m.Translate(m, -((l + r) / 2), -((t + b) / 2), (f+n)/2)
}
Пример #3
0
func AnimateRotate(angle f32.Radian, axis f32.Vec3, mat *f32.Mat4, interp Interpolator) (quit chan struct{}) {
	return Animate(mat, interp, func(m *f32.Mat4, dt float32) {
		mat.Rotate(m, f32.Radian(dt*float32(angle)), &axis)
	})
}