Path: chuka.playstation.co.uk!news From: "pal" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Daft Question [long] Date: 20 Aug 2001 22:54:50 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 88 Message-ID: <01c129ca$a5a6f700$d81fe4d5@pal-s-omnibook> References: <9loc6a$p3k2@www.netyaroze-europe.com> <9loeu8$p3k3@www.netyaroze-europe.com> <01c1297e$8cb6e8a0$LocalHost@pal-s-omnibook> <9lrqqf$3j63@www.netyaroze-europe.com> NNTP-Posting-Host: nas-cbv-2-31-216.dial.proxad.net X-Newsreader: Microsoft Internet News 4.70.1155 John ( QuietBloke ) wrote in article <9lrqqf$3j63@www.netyaroze-europe.com>... > As it seems you have done all the hard work and come up with a solution Id > be very grateful if you could pass it on to me. Ok here is the full code. I adapted it so that it should be usable as is. It might still need some adjustments depending on precise intended use of course. 1. Lookup table maker (in Java). You have to specify the maximum dx or dy, big numbers take a lot of time (32 is ok on my P166). /** * This is a small utility that produces a table for retrieving angles from dx, dy, to be used * in Invs. The angles are adapted to the final needs: unit 4096 = 1 degree, 0 degrees position corresponds to linked position. * Argument: the maximum x or y distance. */ public class MathAnnexMaker { public static void main(String[] args) throws java.io.IOException { // get parameters if (args.length != 1) throw new Error("Wrong number of arguments. Usage : java MathAnnexMaker XYRange"); int xyRange = Integer.decode(args[0]).intValue(); // produce code String code = ""; code += "// File automatically generated by MathAnnexMaker.\n"; code += "\n"; code += "#define XYRange " + xyRange + " // maximum dx or dy\n"; code += "\n"; code += "long angleForXY[XYRange*2+1][XYRange*2+1] = {\n"; for (double y = -xyRange; y <= xyRange; y++) { code += "\t{"; for (double x = -xyRange; x <= xyRange; x++) { code += ((int) Math.toDegrees(Math.atan2(x, y))) * 4096; code += ",\t"; } code += "},\n"; } code += "};\n"; // output code System.out.println(code); } } The output resembles this: // File automatically generated by MathAnnexMaker. #define XYRange 64 // maximum dx or dy long angleForXY[XYRange*2+1][XYRange*2+1] = { {-552960, -552960, -552960, //... //... 2. Lookup table user function. #include "lookup.c" // or whatever file you put the output of MathAnnexMaker in. You can also of course directly paste it here. long getAngleForXY(int dx, int dy, long currentAngle) { if ((dx == 0) && (dy == 0)) return currentAngle; if (dx < -XYRange) dx = -XYRange; if (dx > XYRange) dx = XYRange; if (dy < -XYRange) dy = -XYRange; if (dy > XYRange) dy = XYRange; return angleForXY[dy+XYRange][dx+XYRange]; } 3. Example of use. long rotate = getAngleForXY(x - oldX, oldY - y, oldRotate); Let me know if you encounter any problems or need any further comment. Also please let me know whether it works for you and if any modifications were needed. pal