topical media & game development

talk show tell print

lib-flex-animation-code-03-com-friendsofed-isometric-IsoUtils.ax

lib-flex-animation-code-03-com-friendsofed-isometric-IsoUtils.ax (swf ) [ flash ] flex


  package com.friendsofed.isometric
  {
          import flash.geom.Point;
          
          public class @ax-lib-flex-animation-code-03-com-friendsofed-isometric-IsoUtils
          {
                  // a more accurate version of 1.2247...
                  public static const Y_CORRECT:Number = Math.cos(-Math.PI / 6) * Math.SQRT2;
                  
                  
Converts a 3D point in isometric space to a 2D screen position. @arg pos the 3D point.

  
                  public static function isoToScreen(pos:Point3D):Point
                  {
                          var screenX:Number = pos.x - pos.z;
                          var screenY:Number = pos.y * Y_CORRECT + (pos.x + pos.z) * .5;
                          return new Point(screenX, screenY);
                  }
                  
                  
Converts a 2D screen position to a 3D point in isometric space, assuming y = 0. @arg point the 2D point.

  
                  public static function screenToIso(point:Point):Point3D
                  {
                          var xpos:Number = point.y + point.x * .5;
                          var ypos:Number = 0;
                          var zpos:Number = point.y - point.x * .5;
                          return new Point3D(xpos, ypos, zpos);
                  }
                  
          }
  }


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.