Path: chuka.playstation.co.uk!news From: "Andrew Murray" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Sine & Cosine Lookup Tables Date: Wed, 11 Dec 2002 11:33:45 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 111 Message-ID: References: NNTP-Posting-Host: pc-80-195-1-24-dn.blueyonder.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Thanks guys, if I do use it I'll be sure to put in the credit. I have to figure out how it works first :) Andrew. "Matt Verran" wrote in message news:at58g9$5s01@www.netyaroze-europe.com... > Jon Prestidge has kindly passed on this code, remember to thank him if you > use it! > > long auto_arc_tan( long v_dx, long v_dy ) > { > // V1 > // > // (C) Jon Prestidge, 1998. > // > long grad, ang, deg, abs_dx, abs_dy, half; > > abs_dx = v_dx; > if ( abs_dx < 0 ) abs_dx *= -1; > abs_dy = v_dy; > if ( abs_dy < 0 ) abs_dy *= -1; > > // find the gradient between 0 and one (or 0 and 4096 in this > impelmentation).... > if ( abs_dy <= abs_dx ) > { > if ( abs_dx == 0 ) > > > // exact angle can be returned... also this prevents divide by 0 > error... > if ( v_dy >= 0 ) > return 0; > else > return 2048; > } > grad = abs_dy; > grad <<= 12; > grad /= abs_dx; > half = 1; > } > else > { > if ( abs_dy == 0 ) > > > // exact angle can be returned... also this prevents divide by 0 > error... > if ( v_dx >= 0 ) > return 1024; > else > return 3072; > } > grad = abs_dx; > grad <<= 12; > grad /= abs_dy; > half = 0; > } > > ang = ( grad * 2409 ) >> 12; > ang *= 4096 - ang; > ang += grad * 3097; > ang >>= 15; > > deg = ang * 90 / 1024; > > if ( v_dx >= 0 ) > { > if ( v_dy >= 0 ) > { > if ( half ) ang = 1024 - ang; > } > else > { > if ( half ) > ang += 1024; > else > ang = 2048 - ang; > } > } > else > { > if ( v_dy >= 0 ) > { > if ( half ) > ang += 3072; > else > ang = 4096 - ang; > } > else > { > if ( half ) > ang = 3072 - ang; > else > ang += 2048; > } > } > > return ang; > } > > > > > > > >