---
title: "flash3d教学之基础知识01-drawTriangles绘制三角形[转]"
author: "ienown"
date: "2011-04-19T17:53:30Z"
tags: []
categories: ["编程语言"]
slug: "flash3d-01-drawtriangles"
draft: false
lastmod: "2011-04-19T18:08:27Z"
id: 1008296
url: "https://ienown.iteye.com/blog/1008296"
---

**转载 原文为 http://www.pan3d.me/tutorial/?p=133#more 作者 Pan3d.Me**  
![](http://dl.iteye.com/upload/attachment/466694/256f0644-e508-3f2e-986e-17546b71bb93.jpg)  
①. 这是最基础的绘制作三角形的函数， drawTriangles  我们要做的是画出一个三角形，并对应该贴图

//三个坐标;对应该FLASH 舞台  
\_triangles.vertices.push(0, 0);  
\_triangles.vertices.push(0, 200);  
\_triangles.vertices.push(400, 200);  
//三个贴图坐标 ; 说明， 贴图的坐标是按图像的比例而得到的。  
\_triangles.uvtData.push(0, 0);  
\_triangles.uvtData.push(0, 1);  
\_triangles.uvtData.push(1, 1);  
//对应该顺序;  
\_triangles.indices.push(0, 1, 2);  
//能过画图函数将三角形画出来  
\_tempmc.graphics.beginBitmapFill(\_Bmpsource);    //贴图文件，BitmapData  
\_tempmc.graphics.drawTriangles(\_triangles.vertices, \_triangles.indices, \_triangles.uvtData, TriangleCulling.POSITIVE );  
以上是画一个三角形的的基本组成部份。 就现在的3D对象，不论有多复杂，都是基于 三角形来组成的。

②.  接下来我们试着去改变一下里面的坐标，你就可以一个三角形变形，

![](http://dl.iteye.com/upload/attachment/466704/fd813ab2-9436-34d3-805c-0fd9e5f1de70.jpg)  
看图，可以我们将整个图形向右移动了 300像素，另一个点去上移了一半，

代码的变化，

\_tempmc.x=300  // tempmc的坐标变成了 300

\_triangles.vertices.push(0, 0);  
\_triangles.vertices.push(0, 200);  
\_triangles.vertices.push(300, 100);

//它的Y 坐标从原来的 200移到了 100 ,借此我们可以了解到在FLASH 舞台上的Y 坐标向上是减，与我们平时所学到的向上是加正好相反，有后要注意这个细节，就是我们做3D的其它模形时，他的Y坐标是向反的 ，现在只要观查变化就可以了

③. 再接下来我们试着去改变贴图坐标，

![](http://dl.iteye.com/upload/attachment/466706/759605c2-043f-30ee-9086-a0055d0d0c6a.jpg)  
一定还是应该先对比上一张图的变化，简单的就是绘制的面积一样大，但改贴图坐标后的图像缺了一部份代码变化部分。

\_triangles.uvtData.push(0, 0);  
\_triangles.uvtData.push(0, 1);  
\_triangles.uvtData.push(0.5, 0.5);  
可以看出第三个贴图的坐标，从 （1，1） 变到了 （0.5，0.5） 你对应该一个原始图像（在库里），就不难理解了

④. 最后我们来试着去改变  
\_triangles.indices.push(0, 1, 2);  
在这里要理解的是，它与 TriangleCulling 有显示有关联  
在这里，简单是用顺时钟，和逆时钟 来确定三角形是不为可视  
\_triangles.indices.push(0, 1, 2)=\_triangles.indices.push(1, 2, 0)=\_triangles.indices.push(2, 0, 1);  
如果你改变了 TriangleCulling 的属性为 NEGATIVE 那么三角形 的排列就要反着来，  
\_triangles.indices.push(0, 2, 1)=\_triangles.indices.push(2, 1, 0)=\_triangles.indices.push(1, 0, 2);  
——在这一简单的例子里，只是为了弄清楚这个画图的基本参数的变化会出现什么样的图像