jdm@boulder.Colorado.EDU (James D. Meiss) (03/29/90)
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@boulder.colorado.edu
kj@sgi.com (Kenneth Josiah Harris) (03/29/90)
In article <18930@boulder.Colorado.EDU> jdm@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@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@sgi.com or {decwrl,pyramid,ucbvax}!sgi!kj