Added getProjectedIsoDirection() for obtaining the isometric direction
between two screen coordinates. The screen coordinates are "projected" into isometric space and the vector between them is calculated (except we don't actually do the projection because we can tell just by looking at the points what the projected orientation will be). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1257 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoUtil.java,v 1.29 2002/04/09 17:02:50 ray Exp $
|
||||
// $Id: IsoUtil.java,v 1.30 2002/04/16 17:20:09 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -284,6 +284,42 @@ public class IsoUtil
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two points in screen (cartesian) coordinates, return the
|
||||
* isometrically projected compass direction that point B lies in from
|
||||
* point A.
|
||||
*
|
||||
* @param ax the x-position of point A.
|
||||
* @param ay the y-position of point A.
|
||||
* @param bx the x-position of point B.
|
||||
* @param by the y-position of point B.
|
||||
*
|
||||
* @return the direction specified as one of the <code>Sprite</code>
|
||||
* class's direction constants, or <code>DirectionCodes.NONE</code> if
|
||||
* point B is equivalent to point A.
|
||||
*/
|
||||
public static int getProjectedIsoDirection (int ax, int ay, int bx, int by)
|
||||
{
|
||||
if (bx > ax) {
|
||||
if (by == ay) {
|
||||
return SOUTHEAST;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tile coordinate of the given full coordinate.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user