Newsgroups: comp.graphics
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!mgobbi
From: mgobbi@cs.ubc.ca (Mike Gobbi)
Subject: Re: How do I draw a perspective view?
Message-ID: <1991Jun3.213012.7393@cs.ubc.ca>
Sender: usenet@cs.ubc.ca (Usenet News)
Organization: University of British Columbia, Vancouver, B.C., Canada
References: <9106010027.AA01356@bruny.cc.utas.edu.au>
Date: Mon, 3 Jun 91 21:30:12 GMT

In article <9106010027.AA01356@bruny.cc.utas.edu.au> u906400@BRUNY.CC.UTAS.EDU.AU (Roger Scott) writes:
>Could somebody please explain to me how to take a point (x,y,z) in space and
>map it onto a screen as a single point perspective view in (x,y)?  I've had
> ...
>by now.  Any help appreciated.
>
>	Roger.

Okay. Assuming that you are using a left-handed coordinate system:
  X -> distance to right
  Y -> distance up
  Z -> distance forward

I don't know if it is correct (I just came up with it myself after doing
some geometry), but this method works for me:

  px = x / z * tan(FOV)
  py = y / z * tan(FOV)

where FOV is the desired field of view (humans see 180 degrees, most
rendering works best if FOV is between 30 and 60).  This maps x&y into
values from -1 to 1, which you translate & scale to position in your
window nicely.

Note that you MUST clip any polygon which has ANY vertex behind the eye
(negative or 0 z-value) or else really wierd stuff will happen.



--
    __     In Quest of Knowledge...
   /..\
--mm--mm--     Mike Gobbi
               (mgobbi@cs.ubc.ca)
