python - Pyqt5 OpenGL 模型正在缩小
问题描述
我想模拟一个 3d 模型来执行滚动、俯仰和偏航。我有下面的代码,但我的四边形会随着时间的推移而缩小,直到它不再可见。这是我为清楚起见而制作的gif。我试图改变视角和翻译,但没有奏效。
from random import randint
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.uic import *
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
class mainWindow(QMainWindow):
def __init__(self, *args):
super(mainWindow, self).__init__(*args)
loadUi('UI/gl.ui', self)
def setupUI(self):
self.openGLWidget.initializeGL()
self.init()
self.openGLWidget.resizeGL(651, 551)
self.openGLWidget.paintGL = self.paintGL
timer = QTimer(self)
timer.timeout.connect(self.openGLWidget.update)
timer.start(1000)
def init(self):
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.0)
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glColor3f(1, 0, 0)
random = randint(0, 178)
roll = random # self.data.OrientRoll[self.index]
yaw = 0
pitch = 0
glRotatef(-roll, 0.00, 0.00, 1.00)
glRotatef(pitch, 1.00, 0.00, 0.00)
glRotatef(yaw, 0.00, 1.00, 0.00)
glBegin(GL_QUADS)
glColor3f(0.0, 1.0, 0.0)
glVertex3f(1.0, 0.2, -1.0)
glVertex3f(-1.0, 0.2, -1.0)
glVertex3f(-1.0, 0.2, 1.0)
glVertex3f(1.0, 0.2, 1.0)
glColor3f(1.0, 0.5, 0.0)
glVertex3f(1.0, -0.2, 1.0)
glVertex3f(-1.0, -0.2, 1.0)
glVertex3f(-1.0, -0.2, -1.0)
glVertex3f(1.0, -0.2, -1.0)
glColor3f(1.0, 0.0, 0.0)
glVertex3f(1.0, 0.2, 1.0)
glVertex3f(-1.0, 0.2, 1.0)
glVertex3f(-1.0, -0.2, 1.0)
glVertex3f(1.0, -0.2, 1.0)
glColor3f(1.0, 1.0, 0.0)
glVertex3f(1.0, -0.2, -1.0)
glVertex3f(-1.0, -0.2, -1.0)
glVertex3f(-1.0, 0.2, -1.0)
glVertex3f(1.0, 0.2, -1.0)
glColor3f(0.0, 0.0, 1.0)
glVertex3f(-1.0, 0.2, 1.0)
glVertex3f(-1.0, 0.2, -1.0)
glVertex3f(-1.0, -0.2, -1.0)
glVertex3f(-1.0, -0.2, 1.0)
glColor3f(1.0, 0.0, 1.0)
glVertex3f(1.0, 0.2, -1.0)
glVertex3f(1.0, 0.2, 1.0)
glVertex3f(1.0, -0.2, 1.0)
glVertex3f(1.0, -0.2, -1.0)
glEnd()
gluPerspective(45, 1.0 * (651 / 551), 0.1, 100.0)
glTranslatef(0.0, 0.0, -5)
app = QApplication(sys.argv)
window = mainWindow()
window.setupUI()
window.show()
sys.exit(app.exec_())
解决方案
推荐阅读
- c# - 谷歌登录的 GetExternalLoginInfoAsync 始终为 NULL
- data-visualization - 根据过滤器中的值创建参考线
- ruby - 如何在 Ruby 中获取证书颁发者名称
- gitlab - 配置 GIT 实验室管道
- visual-studio - 下载 VS Studio 2008 [2021]
- php - 无法从我当前的 php 中的另一个 php 获取变量
- python - 如何在 try 和 except 中不忽略 KeyboardInterrupt
- linux - 如何删除 linux 中包含文件和其他目录作为内容的目录
- machine-learning - 知识蒸馏可以用于3个类吗?
- c++ - 为什么 pow 函数在处理 long long int 时会出错?