【问题标题】:rotating tire rims of car opengl transformations汽车opengl转换的旋转轮胎轮辋
【发布时间】:2010-10-16 21:15:24
【问题描述】:

这里是绘制汽车零件的绘图功能,在这个功能中检查汽车轮辋并检查标志,并且我需要在移动汽车时旋转轮胎轮辋。当我按向上箭头键时,由于轮辋旋转但从汽车模型中取出,因此某些东西不起作用,但汽车确实移动了。

我还在初始化函数中初始化了 self.fFlag = "false":

def on_draw(self):
    # Clears the screen and draws the car
    # If needed, extra transformations may be set-up here
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)


    for name in self.parts:
        colors = self.colors
        color = colors.get(name, colors["default"])
        glColor3f(*color)

        if (name == 'Front Driver tire rim') & (self.fFlag == "true"):
            bodyFace = self.mini.group(name)
            glPushMatrix()
            glRotatef(45,1,0,0)

            # Drawing the rim
            for face in bodyFace:
                if len(face) == 3:
                    glBegin(GL_TRIANGLES) 
                elif len(face) == 4:
                    glBegin(GL_QUADS) 
                else: 
                    glBegin(GL_POLYGON)
                for i in face:
                    glNormal3f(*self.mini.normal(i))
                    glVertex3f(*self.mini.vertex(i))
                glEnd()



            glPopMatrix()
            self.fFlag == "false"

        else:
            bodyFace = self.mini.group(name)
            for face in bodyFace:
                if len(face) == 3:
                    glBegin(GL_TRIANGLES) 
                elif len(face) == 4:
                    glBegin(GL_QUADS) 
                else: 
                    glBegin(GL_POLYGON)
                for i in face:
                    glNormal3f(*self.mini.normal(i))
                    glVertex3f(*self.mini.vertex(i))
                glEnd()



def on_key_release(self, symbol, modifiers):
    """Process a key pressed event.
    """

    if symbol == key.UP:
        # Move car forward
        # TODO

        glTranslatef(0,-1,0)
        self.fFlag = "true"
        self.on_draw()

        pass

编辑:当我按下向上箭头键时,我试图让汽车轮辋旋转,这会使汽车向前移动。

【问题讨论】:

  • 你能发布一个演示问题的最小程序吗?

标签: python opengl


【解决方案1】:

我强烈建议将其发布到班级论坛。我不认为 TJ 真的很想看到这个,而且很容易找到。

【讨论】:

    【解决方案2】:

    为了围绕自己的中心旋转零件,您需要将其平移到原点,旋转它,然后将其平移回来。

    所以你的

            glRotatef(45,1,0,0) # rotate 45 deg about x axis (thru the world origin)
    

    前后都需要翻译。

    请参阅accepted answer to this question

    【讨论】:

      【解决方案3】:

      您几乎可以肯定是以错误的顺序应用旋转和变换,因此轮辋围绕轮胎中心以外的某个点旋转。

      您可以尝试在 MODELVIEW 矩阵中进行旋转,在 PROJECTION 矩阵中进行平移。

      【讨论】:

      • "您可以尝试在 MODELVIEW 矩阵中进行旋转,在 PROJECTION 矩阵中进行平移。"嗯?为什么?投影矩阵是用于将眼睛空间转换为屏幕空间的,不是吗?
      • 整个场景的平移可以表示为摄像机的变化,不是吗?
      • 好的,你说的是翻译汽车,而不是轮胎?如果他从不向场景中添加任何其他对象,那可能会起作用......但是它仍然比使用 MODELVIEW mx 更复杂,因为他必须将汽车在世界空间中的运动矢量映射到视图空间中的相应矢量......
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      相关资源
      最近更新 更多