Path: chuka.playstation.co.uk!news From: "Matt Verran" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Sine & Cosine Lookup Tables Date: Tue, 10 Dec 2002 17:25:53 -0800 Organization: PlayStation Net Yaroze (SCEE) Lines: 102 Message-ID: References: NNTP-Posting-Host: host213-122-139-25.in-addr.btopenworld.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 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; }