Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!sgi!shinobu!odin!kj From: kj@sgi.com (Kenneth Josiah Harris) Newsgroups: comp.sys.sgi Subject: Re: Screen to World coordinate mapping Keywords: GetValuator, MOUSEX, map2w Message-ID: <5831@odin.corp.sgi.com> Date: 28 Mar 90 23:14:51 GMT References: <18930@boulder.Colorado.EDU> Sender: news@odin.corp.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 38 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