4
4
from PyQt5 .QtCore import *
5
5
from PyQt5 .QtGui import *
6
6
from PyQt5 .QtOpenGL import *
7
- import numpy
7
+ import numpy as np
8
8
from PIL import Image
9
9
import math
10
10
from PyQt5 import QtCore , QtWidgets
@@ -25,9 +25,23 @@ def __init__(self):
25
25
class glWidget (QGLWidget ):
26
26
27
27
def __init__ (self , parent ):
28
+ self .action_keymap = {
29
+ 'a' : lambda : glTranslate (- 1 , 0 , 0 ),
30
+ 'd' : lambda : glTranslate ( 1 , 0 , 0 ),
31
+ 'w' : lambda : glTranslate ( 0 , 1 , 0 ),
32
+ 's' : lambda : glTranslate ( 0 ,- 1 , 0 ),
33
+
34
+ # 'a': lambda: glRotate(-5, 0, 1, 0),
35
+ # 'd': lambda: glRotate(5, 0, 1, 0),
36
+ # 'W': lambda: glRotate(-5, 1, 0, 0),
37
+ # 'S': lambda: glRotate( 5, 1, 0, 0),
38
+ }
28
39
self .picture = "ozil.png"
29
40
QGLWidget .__init__ (self , parent )
30
41
self .setMinimumSize (640 , 480 )
42
+ main_camera_translation = np .zeros (3 )
43
+ main_camera_rotation = np .zeros (3 )
44
+
31
45
self .cubeVertices = (
32
46
(0.5 , 0.5 , 0.5 ), (0.5 , 0.5 , - 0.5 ), (0.5 , - 0.5 , - 0.5 ), (0.5 , - 0.5 , 0.5 ), (- 0.5 , 0.5 , 0.5 ),
33
47
(- 0.5 , - 0.5 , - 0.5 ),
@@ -53,6 +67,10 @@ def solidCube(self):
53
67
54
68
def image_load (self ,lox ,loy ,loz ,picture ):
55
69
self .read_texture (picture )
70
+ glPushMatrix ()
71
+ glRotatef (30 , 1.0 , 0.0 , 1.0 )
72
+ glTranslatef (- 250 , - 250 , 0.0 )
73
+ glPopMatrix ()
56
74
glBegin (GL_QUADS )
57
75
glTexCoord2f (0.0 , 0.0 )
58
76
glVertex3f (- 1.0 + lox , - 1.0 + loy , 1.0 + loz )
@@ -64,12 +82,18 @@ def image_load(self,lox,loy,loz,picture):
64
82
glVertex3f (- 1.0 + lox , 1.0 + loy , 1.0 + loz )
65
83
glEnd ()
66
84
85
+ def keyPressEvent (self , event ):
86
+ action = self .action_keymap .get (str (event .text ()))
87
+ if action :
88
+ action ()
89
+ self .updateGL ()
90
+
67
91
def paintGL (self ):
68
92
69
93
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
70
94
#glLoadIdentity()
71
95
glTranslatef (- 0.0 , 0.0 , - 5.0 )
72
-
96
+ #glRotatef(10, 10, 10, 10)
73
97
# glRotatef(10,10,10,10)
74
98
#glColor3f(1.0, 1.5, 0.0)
75
99
0 commit comments