首页 > 解决方案 > opngl中的“旋转算法”不起作用

问题描述

我正在 opngl 中尝试“旋转算法”,但它不起作用我在运行程序时得到一个空白页。我应该放 POINT* verts 还是 Point verts[6] 我的代码有问题吗?

void rotate(POINT* verts, GLint nverts, POINT fixedv, GLdouble theta) {
     POINT newverts[6]; //POINT fixedv
    GLint k;


    for (k = 0; k < nverts; k++) {
        newverts[k].x = fixedv.x + (verts[k].x - fixedv.x) * cos(theta) - (verts[k].y - fixedv.y) * sin(theta);
        newverts[k].y = fixedv.y + (verts[k].x - fixedv.x) * sin(theta) + (verts[k].y - fixedv.y) * cos(theta);
        newverts[k].x = (verts[k].x) * cos(theta) - (verts[k].y) * sin(theta);
        newverts[k].y = (verts[k].x) * sin(theta) + (verts[k].y) * cos(theta);
    }
    glBegin(GL_TRIANGLE_FAN);
    for (k = 0; k < nverts; k++)
        glVertex2f(newverts[k].x, newverts[k].y);
    glEnd();
    glFlush();
}

显示代码:

void display() {
    glColor3f(r, g, b);
    if (check == 3) {
        double theta = 3.14 * 0.5;

        POINT verts[6],fixedpivot;
        fixedpivot.x = x;
        fixedpivot.y = y;

        verts[0].x = x + 25;
        verts[0].y = y + 50;
        verts[1].x = x;
        verts[1].y = y;
        verts[2].x = x+50;
        verts[2].y = y;
        verts[3].x = x + 25;
        verts[3].y = y + 50;
        verts[4].x = x + 50;
        verts[4].y = y + 100;
        verts[5].x = x;
        verts[5].y = y + 100;
    
        glClear(GL_COLOR_BUFFER_BIT);
        

    
        
        glColor3f(r, g, b);
        rotate(verts, 6, fixedpivot, theta);
        glFlush();

标签: openglopengl-compat

解决方案


推荐阅读