opengl 绘制绕远点转的飞机

1、绘制飞机方法draw_plane()

void draw_plane()
{
    float scale = 1.0f;

    glLineWidth(6.0f);

    glColor3f(1.0, 0.0, 1.0);
    glPushMatrix();
    glScaled(0.75f * scale, 0.75f * scale, 0.75f * scale);

    glPushMatrix();
    glRotated(90.0f, 0.0f, 1.0f, 0.0f);
    glScaled(1.0f, 1.0f, 1.3f);
    glutSolidSphere(0.25f, 5, 5);           // 机身
    glPopMatrix();

    glColor3f(1.0, 0.0, 0.0);
    glPushMatrix();
    glTranslated(0.0f, -0.24f, 0.0f);
    glRotated(90.0f, 0.0f, 1.0f, 0.0f);
    glScaled(1.0f, 1.0f, 5.0f);
    glTranslated(0.2f, 0.0f, 0.0f);
    glutSolidSphere(0.07f, 3, 3);           // 脚架
    glTranslated(-0.4f, 0.0f, 0.0f);
    glutSolidSphere(0.07f, 3, 3);
    glPopMatrix();

    glColor3f(0.0, 0.0, 1.0);
    glPushMatrix();
    glTranslated(0.0f, 0.2f, 0.0f);
    glRotated(-90.0f, 1.0f, 0.0f, 0.0f);
    glutSolidCone(0.04, 0.16, 4, 1);        // 旋翼轴
    glPopMatrix();

    glPushMatrix();
    glTranslated(0.0f, 0.4f, 0.0f);
    glRotated(90.0f, 1.0f, 0.0f, 0.0f);
    glutSolidCone(0.4, 0.05, 16, 1);        // 旋翼
    glPopMatrix();

    glColor3f(1.0, 1.0, 0.0);
    glPushMatrix();
    glRotated(-90.0f, 0.0f, 1.0f, 0.0f);
    glTranslated(0.0f, 0.05f, 0.29f);
    glRotated(-15.0f, 1.0f, 0.0f, 0.0f);
    glutSolidCone(0.05, 0.3, 4, 1);     // 机尾

    glColor3f(0.0, 0.0, 1.0);
    glTranslated(0.03f, 0.0f, 0.3f);
    glRotated(90.0f, 0.0f, 1.0f, 0.0f);
    glutSolidCone(0.15, 0.0, 8, 1);     // 尾旋翼
    glPopMatrix();

    glPopMatrix();
}

2、更新飞机位置和方向方法update_plane()
全局变量:

float angle = -90;//角度
int i = 0;//修正飞机方向
bool isPause = false;//暂停标志
void update_plane()
{
    glPushMatrix();
    glTranslatef(1.5*cos(angle), 0, 1.5*sin(angle));
    //printf("%f,%d;", -atan((1.5*sin(angle)) / (1.5*cos(angle))) * 180 / 3.141592654,i);
    if (!isPause)
    {
        if (-atan((1.5*sin(angle)) / (1.5*cos(angle))) * 180 / 3.141592654 < -89.95)
            i++;

        if (i % 2 == 0)
            glRotated(-atan((1.5*sin(angle)) / (1.5*cos(angle))) * 180 / 3.141592654 - 90 + 180, 0.0f, 1.0f, 0.0f);
        else
            glRotated(-atan((1.5*sin(angle)) / (1.5*cos(angle))) * 180 / 3.141592654 - 90, 0.0f, 1.0f, 0.0f);
        angle = angle + 0.001;
    } 
    else
    {
        if (i % 2 == 0)
            glRotated(-atan((1.5*sin(angle)) / (1.5*cos(angle))) * 180 / 3.141592654 - 90 + 180, 0.0f, 1.0f, 0.0f);
        else
            glRotated(-atan((1.5*sin(angle)) / (1.5*cos(angle))) * 180 / 3.141592654 - 90, 0.0f, 1.0f, 0.0f);
    }

    draw_plane();
    glPopMatrix();
}

3、另一种方案采用向量法,待定。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值