罗大柚OpenGL ES教程系列LessonOne(Part 2):绘制一个五角星

五角星的各顶点坐标如下图所示:

 

五角星一共有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

- (

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值