Exemplo n.º 1
0
// Returns x, y in window co-ordinates at 0 in the z direction
func ProjToWindow(x, y float64) (float64, float64) {
	var projmat, modelmat [16]float64
	var viewport [4]int32

	gl.GetDoublev(gl.PROJECTION_MATRIX, projmat[:])
	gl.GetDoublev(gl.MODELVIEW_MATRIX, modelmat[:])
	gl.GetIntegerv(gl.VIEWPORT, viewport[:])

	px, py, _ := glu.Project(float64(x), float64(y), 0,
		&modelmat, &projmat, &viewport)

	//return int(px), int(viewport[3]) - int(py)
	return px, float64(viewport[3]) - py
}
Exemplo n.º 2
0
// Returns x, y in window co-ordinates at 0 in the z direction
func WindowToProj(x, y int) (float64, float64) {
	var projmat, modelmat [16]float64
	var viewport [4]int32

	gl.GetDoublev(gl.PROJECTION_MATRIX, projmat[:])
	gl.GetDoublev(gl.MODELVIEW_MATRIX, modelmat[:])

	gl.GetIntegerv(gl.VIEWPORT, viewport[:])
	// Need to convert so that y is at lower left
	y = int(viewport[3]) - y

	px, py, _ := glu.UnProject(float64(x), float64(y), 0,
		&modelmat, &projmat, &viewport)

	return px, py
}