本节重要公式是三维透视图、坐标旋转和距离计算

基本透视图

scale = f1 / (f1 + zpos);
object.scaleX = boject.scaleY = scale;
pbject.alpha = scale; // optional
object.x = vanishingPointX + xpos * scale;
object.y = vanishingPointY + ypos * scale;

Z排序

//assumes an array of 3D objects with a zpos property
function zSort(a, b) {
    return (b.zpos - a.zpos)
}

objects.sort(zSort);

坐标旋转

x1 = x * cos(angleZ) - y * sin(angleZ)
y1 = y * cos(angleZ) + x * sin(angleZ)

x1 = x * cos(angleY) - z * sin(angleY)
z1 = z * cos(angleY) + x * sin(angleY)

y1 = y * cos(angleX) - z * sin(angleX)
y1 = z * cos(angleX) + y * sin(angleX)

三维距离计算

dist = Math.sqrt(dx * dx + dy * dy + dz * dz);