🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: rec.games.programmer
1 messages
1 total messages Started by Brian K. W. Hook Fri, 12 Apr 1991 23:14
3D int/float optimizations stuff
#1434
Author: Brian K. W. Hook
Date: Fri, 12 Apr 1991 23:14
68 lines
2568 bytes
Thanks to everyone who helped with the optimizations.  For those
interested, I am posting the results of each optimization followed by the
final source code.

Summary:  WOW!

First pass:    	21.86 seconds
Optimizations: none (this means all doubles/floats)

Second pass:   	21.48 seconds
Optimizations:  converted functions to pass pointers to objects instead of
                copies of objects

Third pass:	13.40 seconds(!)
Optimizations:	converted most of the calculations to fixed point integer
		calculations versus floating point

Fourth pass:	13.35 seconds
Optimizations:	converted "tmp" variable from long to int

Fifth pass:	12.46 seconds
Optimizations:	converted global variable from double to int

Last pass:	12.20 seconds
Optimizations:	converted _yaw, _roll, and _pitch to ints from doubles

I am sure that a couple of optimizations can still be done, most obviously
those bit shifts (although I really doubt they matter much).  I am not sure
how accurate these calculations are, but I do know that they don't distort
when displaying wireframe images which is all I care about.  I chose to
shift by 10 completely arbitrarily.

If you have any suggestions, please post or mail.

This is the actual function.  It is based on pseudo code from Lee Adam's "
Hi Performance Interactive Graphics in C" but is a pretty crappy book
otherwise.

/*

WX, WY, and WY:   World coordinates of object (relative to object's center)
MX, MY, and MZ:	  Distance object is from viewpoint
*DX, *DY:	  Final display coordinates

*/

void Calc3D ( int WX, int WY, int WZ, int MX, int MY, int MZ, int *DX, int
		*DY)
{
int tmp;
long xa, ya, za;   // Temp variables

   WX=-WX;
   xa=(_yawCosFactor*WX-_yawSinFactor*WZ)>>10;
   za=(_yawSinFactor*WX-_yawCosFactor*WZ)>>10;
   WX=(_rollCosFactor*xa+_rollSinFactor*WY)>>10;
   ya=(_rollCosFactor*WY-_rollSinFactor*xa)>>10;
   WZ=(_pitchCosFactor*za-_pitchSinFactor*ya)>>10;
   WY=(_pitchSinFactor*za+_pitchCosFactor*ya)>>10;
   WX+=MX;
   WY+=MY;
   WZ+=MZ;
   if (WZ==0)
      WZ=-1;
   tmp=AngularPerspFactor/WZ;
   *DX=tmp*WX+400;
   *DY=tmp*WY+300;
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads