-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCubeWidget.py
89 lines (70 loc) · 2.42 KB
/
CubeWidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from OpenGL.GL import *
from OpenGL.GLU import *
from PyQt5.QtOpenGL import *
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QRect
class CubeWidget(QGLWidget):
@property
def vector_rotate(self):
return self._vector_rotate
@vector_rotate.setter
def vector_rotate(self, value):
self._vector_rotate = value
if not self.isHidden():
self.updateGL()
def __init__(self, parent):
QGLWidget.__init__(self, parent)
self._vector_rotate = [0, 0, 0]
#self.setMinimumSize(100, 100)
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glClearColor(1, 1, 1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslatef(0.0, 0.0, -10.0)
glRotatef(self._vector_rotate[0], 1.0, 0.0, 0.0)
glRotatef(self._vector_rotate[1], 0.0, 1.0, 0.0)
glRotatef(self._vector_rotate[2], 0.0, 0.0, 1.0)
glBegin(GL_QUADS)
glColor3f(0.0, 0.0, 1.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, 1.0)
glColor3f(0.0, 0.0, 1.0)
glVertex3f(1.0, 1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(1.0, -1.0, -1.0)
glColor3f(0.0, 1.0, 0.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(1.0, 1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glColor3f(0.0, 1.0, 0.0)
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(-1.0, -1.0, 1.0)
glColor3f(1.0, 0.0, 0.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(1.0, 1.0, -1.0)
glColor3f(1.0, 0.0, 0.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glEnd()
def setGeometry(self, *__args):
m = min(__args[2], __args[3])
super().setGeometry(__args[0], __args[1], m, m)
def resizeGL(self, width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION);
glLoadIdentity()
glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 30.0)
glMatrixMode(GL_MODELVIEW)
def initializeGL(self):
glEnable(GL_DEPTH_TEST)