Article View: rec.games.programmer
Article #1423Re: Need hard core help doing some 3d optimizations
From: Randy Buckland
Date: Fri, 12 Apr 1991 12:38
Date: Fri, 12 Apr 1991 12:38
43 lines
2109 bytes
2109 bytes
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
Technical Details
Message-ID:
<rcb.671459927@shaman.cc.ncsu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!wrdis01!gatech!taco!shaman.cc.ncsu.edu!rcbReferences:
<27979@uflorida.cis.ufl.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <rcb.671459927@shaman.cc.ncsu.edu> 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