Screen to World coordinate mapping

Kenneth Josiah Harris kj at sgi.com
Thu Mar 29 09:14:51 AEST 1990


In article <18930 at boulder.Colorado.EDU> jdm at boulder.Colorado.EDU (James D. Meiss) writes:
>
>	I am just learning how to program using gl on our new
>personal Iris, and enjoying it for the most part!
>	I am trying to read the position of the mouse to use
>as input to my program. The problem is that GetValuator(MOUSEX)
>returns the position in screen coordinates. How do I convert
>this position to World coordinates?
>	map2w seems to do this but only if I create an object.
>It seems like there should be some simpler way. I use
>ortho2(-1.,1.,-1.,1.) to set up my world coordinates.
>
>	Thanks
>	Jim Meiss
>	jdm at boulder.colorado.edu

	Here's a routine I use to do that.


void scr2unit(sx,sy,unit)
Screencoord sx,sy;
float unit[];
/* convert from screen coordinates to unit cube coordinates */
{
	Screencoord vl, vr, vb, vt;
	long ox,oy;

	getorigin(&ox,&oy); /* 4d getviewport isn't screen coords */
	sx -= ox;
	sy -= oy;

	getviewport (&vl,&vr,&vb,&vt);

	unit[0] = (2.0*sx - vl - vr)/(vr - vl + 1);
	unit[1] = (2.0*sy - vb - vt)/(vt - vb + 1);
}
--
Ken J. Harris -- kj at sgi.com or {decwrl,pyramid,ucbvax}!sgi!kj



More information about the Comp.sys.sgi mailing list