五角星的各顶点坐标如下图所示:
五角星一共有10个顶点,各顶点的坐标在上图中已经标注,下面给出各顶点坐标计算公式:
#define PI3.1415926
double L1=0.2*cos(36*PI/180);
doubleL2=0.2*sin(36*PI/180);
doubleL3=0.2*cos(72*PI/180);
doubleL4=0.2*sin(72*PI/180);
doubleL5=L2*tan(72*PI/180);
doubleL6=L2/cos(72*PI/180);
doubleL7=L6*sin(54*PI/180);
double L8=L6*cos(54*PI/180)+0.2;
我们通过上面各点的位置关系,得到下面所示的顶点数据,然后我们采用索引的方式来绘制这个五角星,
// Thisdata type is used to store information for each vertex
typedef struct {
GLKVector3 positionCoords;
}Vertex;
//eachvertex coordinates and indexes of the pentacle
static constVertexvertices[] =
{
{-0.307768, -0.423607, 0.0},
{-0.190211, -0.061803, 0.0},
{-0.497980, 0.161803, 0.0},
{-0.117557, 0.161803, 0.0},
{0.0, 0.523607, 0.0},
{0.117557, 0.161803, 0.0},
{0.497980, 0.161803, 0.0},
{0.190211, -0.061803, 0.0},
{0.307768, -0.423607, 0.0},
{0.0, -0.2, 0.0}
};
const GLubyte Indices[]= {
9,0,1,
1,2,3,
3,4,5,
5,6,7,
7,8,9,
9,1,5,
5,7,9,
1,3,5
};
接下来就是写ViewDidLoad方法了:
/
//Called when the view controller's view is loaded
//Perform initialization before the view is asked to draw
- (