TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RICHARD VAN BERKUM
from: MATHIEU BOUCHARD
date: 1998-05-12 03:03:00
subject: Rotate

 RVB> There is a small problem in rotating a point using fixedpoint. The 
 RVB> rotation
 RVB> wont work and I don't know why.
 RVB> If you could help me I would appriciate it.
 RVB> Here's the source I compile. It's not much but it's all there is ;)
 RVB> Ok, see what you do with it. Have a nice day.
like, have you inited the sintab[] and costab[] ? and you ain't
incrementing sinptr and cosptr from within the loop, so you're plotting
the same dot 360 times. The rest looks like a nice effort of
pipeline-optimizations for the 586. I hope you use the "use registers"
compiler option though, otherwise you're better off with longer
expressions. that doesn't matter in recent GNU compilers.
 RVB>                    x1 = (cos*x);    
 RVB>                    y1 = (sin*y);
 RVB>                    x2 = x1 - y1;    // cos*x - sin*y
 RVB>                    x1 = (sin*x);
 RVB>                    offset = y * 320;
if you're using TC++ 3.00, offset = y * 256 + y * 64 will be several
times faster in execution. With GNU C++ though, it doesn't matter, if
the optimizations are turned on, y*320 will be broken down in
y*256+y*64 and then optimized to (y<<8)+(y<<6). TC++ only does the
latter optimization so you have to help it a bit (no pun intended)
BTW, it also helps the memory cache if you merge both tables... after
all, a cosine is just a sine shifted by 90 degrees... and also, use
"brads" instead of "degrees". 360 degrees = 256 brads; using that
property, if you want to loop through the circle, using
foo=(foo+1)%360, you will do it faster using foo=(foo+1)&255, in which
&255 is an optimization of %256.
matju
--- Terminate 4.00/Pro
---------------
* Origin: The Lost Remains Of SatelliteSoft BBS (1:163/215.42)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.