Xref: utzoo rec.games.programmer:3398 comp.os.msdos.programmer:4604 comp.graphics:17200 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!wrdis01!gatech!taco!shaman.cc.ncsu.edu!rcb From: rcb@shaman.cc.ncsu.edu (Randy Buckland) Newsgroups: rec.games.programmer,comp.os.msdos.programmer,comp.graphics Subject: Re: Need hard core help doing some 3d optimizations Message-ID: Date: 12 Apr 91 12:38:47 GMT References: <27979@uflorida.cis.ufl.EDU> Sender: news@ncsu.edu (USENET News System) Organization: North Carolina State University Lines: 43 jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes: >void Calc3D ( int WorldX, int WorldY, int WorldZ, > int MX, int MY, int MZ, > int *DisplayX, int *DisplayY) >{ >float xa, ya, za; > WorldX=-WorldX; > xa=_yawCosFactor*WorldX-_yawSinFactor*WorldZ; > za=_yawSinFactor*WorldX+_yawCosFactor*WorldZ; > WorldX=_rollCosFactor*xa+_rollSinFactor*WY; > ya=_rollCosFactor*WorldY-_rollSinFactor*xa; > WorldZ=_pitchCosFactor*za-_pitchSinFactor*ya; > WorldY=_pitchSinFactor*za+_pitchCosFactor*ya; > WorldX+=MX; > WorldY+=MY; > WorldZ+=MZ; > *DisplayX=AngPerspFactor*WorldX/WorldZ; > *DisplayY=AngPerspFactor*WorldY/WorldZ; >} Try this Store your cos/sin values as (int)(cos(angle)*1024) Then do the matrix multiply as c(0,0) = (a(0,0)*b(0,0) + a(0,1)*b(1,0) + a(0,2)*b(2,0) + (a(0,3)*b(3,0)) >> 10; where a is your initial 4x4 coordinate matrix and b is your translation matrix that is precomputed. ALL values in the b matrix should be integers that are 1024 times their proper values while a is an integer matrix with the proper values and c is an integer matrix. This results in 4 integer multiplies, 3 integer adds and 1 shift (the reason for 1024 instead of 1000 scale factor) No floating point at all. Also, try to determine if you are really rotating about all 3 axes. If not, you can drastically simplify the computations and increase the speed. -- Randy Buckland "It's hard to work North Carolina State University in a group when you're randy@ncsu.edu (919) 737-2517 omnipotent" -- Q