---
title: "as3编写3D原理（笔记）"
author: "Fis"
date: "2011-05-13T17:44:50Z"
tags: []
categories: ["编程语言"]
slug: "as3-3d"
draft: false
lastmod: "2011-05-13T17:44:50Z"
id: 1042728
url: "https://fis.iteye.com/blog/1042728"
---

![](http://dl.iteye.com/upload/attachment/480976/ab61c670-7462-353a-8234-e2947c9652e9.png)

1、基本原理：三角形相似原理
d/(d+z) = x1/x
d/(d+z) = y1/y

2、(x1, y1)为二维坐标系，(x, y)为三维坐标系，d/(d+z)为换算比率

3、二维坐标系转flash坐标系
x_flash = stageWidth/2 + x1
y_flash = stageHeight/2 + y1

4、物体宽高比例（透明度类似）
scaleX = scaleY = d/(d+z)*100
alpha = d/(d+z)*100

5、层深计算（as2.0为例）
swapDepth(10000-z) 或 swapDepth(-z)

6、镜头运动
镜头坐标(x, y, z) = 目标坐标(x, y, z) - 镜头坐标(x, y, z)