Re: 3D math
- Posted by mwfch at MWEB.CO.ZA Apr 26, 2001
- 427 views
Thanks a lot , that cleard it up a lot ! Read ya later ! Ferdinand Greyling(DukeFungus) ----- Original Message ----- From: Chris Bensler <bensler at mailops.com> To: <EUforum at topica.com> Subject: RE: 3D math > > > > Hi Ferdinand, > > Here is how it works.. (I may be mistaken, I haven't done 3d code in a > while) > > You start with your 3d point (X,Y,Z) > > the formula for converting to screen coordinates is.. > > X = (X * FOV)/Z + (screen_width/2) > Y = (Y * FOV)/Z + (screen_height/2) > > FOV is the Field Of View, which is just so your 3d objects arent very, > very small.. Usually FOV is 256 or something close to that. It's up to > you. > > Z is in the range >0 to FOV.. > a big Zvalue is closer , a small Zvalue is farther > > make sure you test to make sure Z is never 0, or you will get a divide > _by_zero error. > > I don't understand it very well myself.. I just get it to work and then > I'm happy . :P > > here is some example code in C some docs I have.... > I just draws a dot in 3d > > -- EXAMPLE > x = 1 > y = 1 > z = 256 > FOV = 256 > while (gx<320) and (gx>-1) and (gy<200) and (gy>-1) > gx = x * FOV / z + 160 ; center = the center of the screen > gy = y * FOV / z + 100 ; (mode 320x200) > putpixel(gx,gy,15) > z = z - 1 > if (z = 0) > z = -1 ; just to ensure... > endif > endwhile > -- END of EXAMPLE > > NOTE.. > You can get rid of the FOV if Z is in the range 0.1 to 1.0 > > Hope that helps.. > <snip> > > > >