delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/17/08:40:39

From: Ludvig Larsson <ludvig AT club-internet DOT fr>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: perspective
Date: Sat, 17 Oct 1998 05:40:11 +0200
Organization: Faas-Goldhart
Lines: 37
Message-ID: <3628119B.4597@club-internet.fr>
References: <6vuak6$qa6$1 AT supernews DOT com>
NNTP-Posting-Host: toulouse-camichel5-132.club-internet.fr
Mime-Version: 1.0
X-Trace: front2.grolier.fr 908595691 7282 195.36.147.132 (17 Oct 1998 03:41:31 GMT)
NNTP-Posting-Date: 17 Oct 1998 03:41:31 GMT
X-Mailer: Mozilla 3.01C-CLUB (Win95; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

jud wrote:
> 
> im making a cad type program and i was wondering if any of you know a good
> algorithm for calculationg perspective

Well, make the translations needed to get your screencoordinates(like
translation and rotations) then either use the matrix:

1  0  0  0
0  1  0  0
0  0  0 -1/d
0  0  0  1

where (0,0,d) is the projection plane.

or (same thing but without the use of a matrix):

multiply all x and y (after the translations) with 
the z-coordinate *(-d)

I think

s=0;
if(1-z/5000>0)
 s=1/(1-z/5000);
x=x*s;
y=y*s;

(and then just translate the coordinates to the center of the
screen(like x+=320;y+=240; in a 640x480 window))

will work, but it's just ripped out of an old code so I don't know if
it'l work or not...

Hop it helped anyway.

Ludvig Larsson

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019