3D 环视系统碗状模型绘制

1. 碗状模型数学公式;

step = 2;

R=i*step

x=R * sin(theta),

y=R* cos(theta)

z=pow((R-0.7*R),1.5)

2.  OpenGL 实现代码

// Called to draw scene
void drawBowlVertex(void)
{
    GLfloat X, Y, Z, angle;

    GLfloat fR = 0.0f;

    // Clear the window with current color
    glClear(GL_COLOR_BUFFER_BIT);

    // Save matrix state and do the rotation
    glPushMatrix();

    // Rotate
    glRotatef(xRot, 0.2f, 0.0f, 0.0f);
    glRotatef(yRot, 0.0f, 0.0f, 0.0f);

    glPointSize(2.f);
    glBegin(GL_POINTS);
    float stepx = 4.0f;
   
    int n = 10;
    int thresh = 0.7 * n;
    for (int i = 0; i < n;i++)
    {
        fR = stepx*i;
        if (i < thresh)
        {
            Z = 0.0f;
        }
        else
        {
            Z = -pow(stepx * (i - thresh),1.5);
        }
        for (angle = 0.0f; angle <= 2.0f * PI; angle += 0.1f) // 5圈
        {
            X = fR * sin(angle);
            Y = fR * cos(angle);

            glVertex3f(X, Y, Z);
        }
    }
    
    glEnd();
    // restore transformations
    glPopMatrix();
    // Flush drawing commands
    glFlush();
}

3. 效果如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值