From 8d413714570eb754c29117fb16d2d42ee623cd72 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 16 Apr 2002 17:20:09 +0000 Subject: [PATCH] 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 --- .../threerings/miso/client/util/IsoUtil.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/miso/client/util/IsoUtil.java b/src/java/com/threerings/miso/client/util/IsoUtil.java index f3307ff9c..c906f3102 100644 --- a/src/java/com/threerings/miso/client/util/IsoUtil.java +++ b/src/java/com/threerings/miso/client/util/IsoUtil.java @@ -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 Sprite + * class's direction constants, or DirectionCodes.NONE 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. */