《AdvancED ActionScript 3.0 Animation》读书笔记(2) —— 2.5d
【2.5d坐标转换成2d坐标】:
sx = x - z;
sy = y * 1.2247 + (x + z) * .5;
【2d坐标转换成2.5d坐标】:
x = sy + sx / 2
y = 0
z = sy - sx / 2
【转换坐标类】:
public class Point3D
{
public var x:Number;
public var y:Number;
public var z:Number;
public function Point3D(x:Number = 0, y:Number = 0, z:Number = 0)
{
this.x = x;
this.y = y;
this.z = z;
}
}
public class IsoUtils
{
// 1.2247 的精确计算版本
public static const Y_CORRECT:Number = Math.cos(-Math.PI / 6) * Math.SQRT2;
/**
* 把等角空间中的一个3D 坐标点转换成屏幕上的2D 坐标点
* @参数pos 是一个3D 坐标点
*/
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);
}
/**
* 把屏幕上的2D 坐标点转换成等角空间中的一个3D 坐标点,设y=0
* @参数pos 是一个2D 坐标点
*/
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);
}
}