如何在PyOpenGL中旋转2D线?

问题描述 投票:3回答:1

我写了一个代码来画一条线。这是功能:

def drawLines():
    r,g,b = 255,30,20
    #drawing visible axis
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3ub(r,g,b)
    glBegin(GL_LINES)
    #glRotate(10,500,-500,0)
    glVertex2f(0,500)
    glVertex2f(0,-500)

    glEnd()
    glFlush()

现在我正在尝试旋转线。我正在尝试关注this文档,但无法理解。根据文档,旋转功能定义如下:

def glRotate( angle , x , y , z ):

我没有z轴。所以我保持z=0。我在这里想念的是什么?

python opengl coordinate-transformation pyopengl opengl-compat
1个回答
3
投票

请注意,glBegin / glEnd序列和固定功能管道矩阵堆栈的绘制几十年来都被弃用了。阅读Fixed Function Pipeline并查看Vertex SpecificationShader以获得最先进的渲染方式:


传递给x的qazxsw poi,qazxsw poi和qazxsw poi参数是旋转轴。由于几何体是在xy平面中绘制的,因此旋转轴必须是z轴(0,0,1):

y

要绕枢轴旋转,您必须定义一个模型矩阵,该矩阵由倒置的枢轴移动,然后旋转并最终转换回枢轴(z):

glRotate

进一步注意,在glRotatef(10, 0, 0, 1) 序列中不允许像glTranslate这样的操作。在glTranslatef(pivot_x, pivot_y, 0) glRotatef(10, 0, 0, 1) glTranslatef(-pivot_x, -pivot_y, 0) 序列中,只允许操作设置顶点属性,如glRotateglBegin/glEnd。你必须在glBegin/glEnd之前设置矩阵:

EG

glVertex

如果您只想旋转线条而不影响其他对象,则可以通过qazxsw poi保存并恢复矩阵堆栈:

glColor
© www.soinside.com 2019 - 2024. All rights reserved.