Пример #1
0
// ScreenTransf returns a new matrix that transforms vectors after projection
// to screen coordinates. The upper left corner of the near rectangle will be
// (0,0) and the bottom right will be (w,h). If the aspect ratio does not match
// the camera the image will be distorted.
func ScreenTransf(f *Frustum, w, h int) *geom.Mat4 {
	wf := float64(w)
	hf := float64(h)
	t := TranslTransf(&geom.Vec3{f.Nwidth / 2, -f.Nheight / 2, 0})
	m := geom.Mat4{
		wf / f.Nwidth, 0, 0, 0,
		0, -hf / f.Nheight, 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1,
	}
	m.Mul(t)
	return &m
}