I wanted to simulate a 3d model to perform roll, pitch and yaw. I have the code below but my quad is shrinking over time until it is no longer visible. Here is a gif I made to make it clear. I tried to change perpective and translate but it didn't work.
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_())