2
2
from OpenGL .GLU import *
3
3
from PyQt5 .QtWidgets import *
4
4
from PyQt5 .QtCore import *
5
- from PyQt5 .QtGui import *
6
5
from PyQt5 .QtOpenGL import *
7
- import numpy as np
8
- from PIL import Image
9
- import math
10
- from PyQt5 import QtCore , QtWidgets
11
6
import pygame
12
7
13
8
@@ -36,21 +31,8 @@ def __init__(self, parent):
36
31
'w' : [1 ,0 ],
37
32
's' : [- 1 ,0 ],
38
33
}
39
-
40
- self .picture = "ozil.png"
41
34
QGLWidget .__init__ (self , parent )
42
35
self .setMinimumSize (640 , 480 )
43
- main_camera_translation = np .zeros (3 )
44
- main_camera_rotation = np .zeros (3 )
45
-
46
- self .cubeVertices = (
47
- (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 ),
48
- (- 0.5 , - 0.5 , - 0.5 ),
49
- (- 0.5 , - 0.5 , 0.5 ), (- 0.5 , 0.5 , - 0.5 ))
50
- self .cubeEdges = (
51
- (0 , 1 ), (0 , 3 ), (0 , 4 ), (1 , 2 ), (1 , 7 ), (2 , 5 ), (2 , 3 ), (3 , 6 ), (4 , 6 ), (4 , 7 ), (5 , 6 ), (5 , 7 ))
52
- self .cubeQuads = ((0 , 3 , 6 , 4 ), (2 , 5 , 6 , 3 ), (1 , 2 , 5 , 7 ), (1 , 0 , 4 , 7 ), (7 , 4 , 6 , 5 ), (2 , 3 , 0 , 1 ))
53
-
54
36
55
37
def image_load (self ,lox ,loy ,loz ,picture ,rotate ):
56
38
self .read_texture (picture )
@@ -70,22 +52,21 @@ def image_load(self,lox,loy,loz,picture,rotate):
70
52
glPopMatrix ()
71
53
72
54
def keyPressEvent (self , event ):
73
- print ("pressed" ,event .text ())
74
- # gluLookAt(2,1,1,0,0,0,0,1,0)
75
- self .camera = self .action_keymap .get (event .text ())
76
- glRotate (self .camera [0 ],1 ,0 ,0 )
77
- glRotate (self .camera [1 ],0 ,1 ,0 )
78
- self .update ()
55
+ try :
56
+ self .camera = self .action_keymap .get (event .text ())
57
+ if event .text () in self .action_keymap .keys ():
58
+ glRotate (self .camera [0 ],1 ,0 ,0 )
59
+ glRotate (self .camera [1 ],0 ,1 ,0 )
60
+ self .update ()
61
+ except :
62
+ pass
79
63
80
64
def paintGL (self ):
81
65
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
82
66
self .image_load (- 1 ,0 ,0 ,"../reconstruction/mon_r.jpg" ,- 20 )
83
67
self .image_load (1 , 0 , 0 ,"../reconstruction/mon_l.jpg" ,20 )
84
68
glFlush ()
85
69
86
- # def drawAxes(self):
87
-
88
-
89
70
def initializeGL (self ):
90
71
glClearDepth (1.0 )
91
72
glDepthFunc (GL_LESS )
@@ -112,45 +93,20 @@ def wheelEvent(self, event):
112
93
glTranslate (0 ,0 ,- 1 )
113
94
self .update ()
114
95
115
- def mousePressEvent (self , event ):
116
-
117
- print ("pressed" )
118
- btns = event .buttons ()
119
- x = event .localPos ().x ()
120
- y = event .localPos ().y ()
121
-
122
- if btns & Qt .LeftButton :
123
- print ("left" )
124
-
125
- elif btns & (Qt .MidButton ):
126
- print ("middle" )
127
-
128
- elif btns & (Qt .RightButton ):
129
- print ("right" )
130
-
131
- def mouseReleaseEvent (self , event ):
132
- # nothing to be done here.
133
- print ("released" )
134
- pass
135
-
136
96
def read_texture (self ,picture ):
137
97
textureSurface = pygame .image .load (picture )
138
98
textureData = pygame .image .tostring (textureSurface , "RGBA" , 1 )
139
99
width = textureSurface .get_width ()
140
100
height = textureSurface .get_height ()
141
-
142
101
glEnable (GL_TEXTURE_2D )
143
- texid = glGenTextures (1 )
144
-
145
-
102
+ tex_id = glGenTextures (1 )
146
103
glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGB , width , height ,
147
104
0 , GL_RGBA , GL_UNSIGNED_BYTE , textureData )
148
-
149
105
glTexParameterf (GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_REPEAT )
150
106
glTexParameterf (GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_REPEAT )
151
107
glTexParameterf (GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST )
152
108
glTexParameterf (GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST )
153
- return texid
109
+ return tex_id
154
110
155
111
156
112
if __name__ == '__main__' :
0 commit comments