Article View: rec.games.programmer
Article #1425Re: Need hard core help doing some 3d optimizations
From: Charles K Hughes
Date: Sat, 13 Apr 1991 01:57
Date: Sat, 13 Apr 1991 01:57
62 lines
2355 bytes
2355 bytes
Does this discussion really need to be in 3 newsgroups?
Brian writes:
>
>I just ran Turbo Profiler on some code of mine, and it looks like roughly
>90% of my CPU time is being shoved into one function. Any help on the
I don't know what the rest of your program looks like, but I don't think
this code should take up 90% of it.
(Before following my mediocre suggestions, follow the others that have been
posted - TSR removal, use Ints, etc.)
>optimizations would be really appreciated.
>
>E-mail would be preferred, however posts are fine too.
>
>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;
Change these last two to:
yes_a_temp=AngPerspFactor/WorldZ;
*DisplayX=yes_a_temp*WorldX
*DisplayY=yes_a_temp*WorldY
Division costs a lot more than multiplication or storage.
>}
>
>AngPerspFactor is a float, as are the assorted factors. I have already
>used a COS and SIN lookup table in another part of the module to expedite
>things, but this is really slowing things down considerably.
>
>Any help is appreciated.
>
>Brian
>
>
Now, for independend thoughts that don't quite fit into the program...
There are formulas for transforming the equations you have above.
Calculus and trig books should have them.
Good luck.
Charles_K_Hughes@cup.portal.com
Technical Details
Message-ID:
<41220@cup.portal.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!mips!apple!portal!cup.portal.com!Ordania-DMReferences:
<27979@uflorida.cis.ufl.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!mips!apple!portal!cup.portal.com!Ordania-DM From: Ordania-DM@cup.portal.com (Charles K Hughes) Newsgroups: rec.games.programmer,comp.os.msdos.programmer,comp.graphics Subject: Re: Need hard core help doing some 3d optimizations Message-ID: <41220@cup.portal.com> Date: 13 Apr 91 01:57:18 GMT References: <27979@uflorida.cis.ufl.EDU> Organization: The Portal System (TM) Lines: 62