made getIsoDirection() and getProjectedIsoDirection() more accurate.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1388 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2002-05-24 20:15:04 +00:00
parent 16d4bfabca
commit 984fa75229
@@ -1,5 +1,5 @@
// //
// $Id: IsoUtil.java,v 1.30 2002/04/16 17:20:09 mdb Exp $ // $Id: IsoUtil.java,v 1.31 2002/05/24 20:15:04 ray Exp $
package com.threerings.miso.scene.util; package com.threerings.miso.scene.util;
@@ -264,24 +264,29 @@ public class IsoUtil
*/ */
public static int getIsoDirection (int ax, int ay, int bx, int by) public static int getIsoDirection (int ax, int ay, int bx, int by)
{ {
if (bx > ax) { // head off a div by 0 at the pass..
if (by == ay) { if (bx == ax) {
return SOUTH;
}
return (by < ay) ? SOUTHEAST : SOUTHWEST;
} else if (bx == ax) {
if (by == ay) { if (by == ay) {
return DirectionCodes.NONE; return DirectionCodes.NONE;
} }
return (by < ay) ? EAST : WEST; return (by < ay) ? EAST : WEST;
} else { // bx < ax
if (by == ay) {
return NORTH;
}
return (by < ay) ? NORTHEAST : NORTHWEST;
} }
// figure direction base on the slope of the line
float slope = ((float) (ay - by)) / ((float) Math.abs(ax - bx));
if (slope > 2f) {
return EAST;
}
if (slope > .5f) {
return (bx < ax) ? NORTHEAST : SOUTHEAST;
}
if (slope > -.5f) {
return (bx < ax) ? NORTH : SOUTH;
}
if (slope > -2f) {
return (bx < ax) ? NORTHWEST : SOUTHWEST;
}
return WEST;
} }
/** /**
@@ -300,24 +305,12 @@ public class IsoUtil
*/ */
public static int getProjectedIsoDirection (int ax, int ay, int bx, int by) public static int getProjectedIsoDirection (int ax, int ay, int bx, int by)
{ {
if (bx > ax) { int dir = getIsoDirection(ax, ay, bx, by);
if (by == ay) { if (dir != DirectionCodes.NONE) {
return SOUTHEAST; // offset the direction by -1, ie change SOUTHWEST to SOUTH
} dir = (dir + 7) % 8;
return (by < ay) ? EAST : SOUTH;
} else if (bx == ax) {
if (by == ay) {
return DirectionCodes.NONE;
}
return (by < ay) ? NORTHEAST : SOUTHWEST;
} else { // bx < ax
if (by == ay) {
return NORTHWEST;
}
return (by < ay) ? NORTH : WEST;
} }
return nonproj;
} }
/** /**