---
title: "基础知识06四边形组成一个正方体并转动[转]"
author: "ienown"
date: "2011-04-19T18:34:03Z"
tags: []
categories: ["编程语言"]
slug: "06"
draft: false
lastmod: "2011-04-19T18:36:56Z"
id: 1008352
url: "https://ienown.iteye.com/blog/1008352"
---

**转载 原文为 <http://www.pan3d.me/tutorial> 作者 Pan3d.Me **

![](http://dl.iteye.com/upload/attachment/466736/34caca7d-1fde-32d6-8065-06aa1caa4f7a.jpg)
我们运行程序，可以看到，一个正方体在旋转，原理都是基于三角形来变成的， 可以从图中看出每个三角形的位置

打开程序，你会发现有很多条件 对应该的记录，在这里我并没有优化，我用 4*4=16个独立的点，贴图坐标也用到了16个

只是为了方便大家学习， 在以后一个立方体只需要 8个独立的点，如果4个面都是一样的贴图，那就只需要4个贴图坐标

（现在可以想想，怎么把这些点集合起来让程序不必要写这么多）

就现在的程序跟上一个程序对比，你可以发现，多出来的三角形都是一组一组的。 相对应该容易理解。

_triangles.indices.push(0, 1, 2);
_triangles.indices.push(0, 2, 3);

_triangles.indices.push(4, 5, 6);
_triangles.indices.push(4, 6, 7);

_triangles.indices.push(8, 9, 10);
_triangles.indices.push(8, 10, 11);

_triangles.indices.push(12, 13, 14);
_triangles.indices.push(12, 14, 15);

这就是意味着 有 4 个面， 8个三角形组成，你对比数组编号，然后从映射后的顶点坐标和贴图坐标中得到每个三角形

的贴图参数。

–附->  现在旋转的角度 是 _r   那如果你将  _r = mouseX 试试，会出现什么样的效果