opengl koch雪花有错误?

时间:2014-08-01 15:31:04

标签: c++ opengl

我试图实现koch雪花,但它们是递归中的一个问题,因为它只打印三角形的一边编辑。我还有其他功能,它们首先制作一个三角形,并且所有方面都称为drawnowflakes find mid函数找到新三角形的顶点。

void findmid(int a, int b, int c, int d, int* e, int* f) {
    cout << a << " " << b << endl;
    float length = sqrt(pow((a - c), 2) - pow((b - d), 2));
    float slope = (d - b) / (float)(c - a);
    float t = atan(slope);
    cout << t << endl;
    *e = a + length * cos(t + 1);
    *f = b - length * sin(t + 1);
    cout << *e << " " << *f << endl;
}

int drawsnowflake(int x1, int y1, int x2, int y2) {
    int length = sqrt(pow((x1 - x2), 2) - pow((y1 - y2), 2));
    if (length < 10) {
        return 0;
    }
    int midx1 = (2 * x1 + x2) / 3, midx2 = (2 * x2 + x1) / 3;
    int midy1 = (2 * y1 + y2) / 3, midy2 = (2 * y2 + y1) / 3;
    int e = 1, f = 1;

    findmid(midx1, midy1, midx2, midy2, &e, &f);

    glColor3f(1, 1, 0);
    glBegin(GL_LINES);
    glVertex3f(midx1, midy1, 0);
    glVertex3f(e, f, 0);
    glVertex3f(e, f, 0);
    glVertex3f(midx2, midy2, 0);
    glColor3f(0, 0, 0);
    glVertex3f(midx1, midy1, 0);
    glVertex3f(midx2, midy2, 0);
    glEnd();
    glFlush();

    drawsnowflake(x1, y1, midx1, midy1);
    drawsnowflake(midx1, midy1, e, f);
    drawsnowflake(e, f, midx2, midy2);
    drawsnowflake(midx2, midy2, x2, y2);
}

什么是错误?

0 个答案:

没有答案
相关问题