Skip to content

Commit 72a9468

Browse files
committed
np rotation
1 parent 1156f3d commit 72a9468

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

pyqtVisualisation/mainwindow.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from PyQt5.QtCore import *
55
from PyQt5.QtGui import *
66
from PyQt5.QtOpenGL import *
7-
import numpy
7+
import numpy as np
88
from PIL import Image
99
import math
1010
from PyQt5 import QtCore, QtWidgets
@@ -25,9 +25,23 @@ def __init__(self):
2525
class glWidget(QGLWidget):
2626

2727
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+
}
2839
self.picture = "ozil.png"
2940
QGLWidget.__init__(self, parent)
3041
self.setMinimumSize(640, 480)
42+
main_camera_translation = np.zeros(3)
43+
main_camera_rotation = np.zeros(3)
44+
3145
self.cubeVertices = (
3246
(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),
3347
(-0.5, -0.5, -0.5),
@@ -53,6 +67,10 @@ def solidCube(self):
5367

5468
def image_load(self,lox,loy,loz,picture):
5569
self.read_texture(picture)
70+
glPushMatrix()
71+
glRotatef(30, 1.0, 0.0, 1.0)
72+
glTranslatef(-250, -250, 0.0)
73+
glPopMatrix()
5674
glBegin(GL_QUADS)
5775
glTexCoord2f(0.0, 0.0)
5876
glVertex3f(-1.0+lox, -1.0+loy, 1.0+loz)
@@ -64,12 +82,18 @@ def image_load(self,lox,loy,loz,picture):
6482
glVertex3f(-1.0+lox, 1.0+loy, 1.0+loz)
6583
glEnd()
6684

85+
def keyPressEvent(self, event):
86+
action = self.action_keymap.get(str(event.text()))
87+
if action:
88+
action()
89+
self.updateGL()
90+
6791
def paintGL(self):
6892

6993
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
7094
#glLoadIdentity()
7195
glTranslatef(-0.0, 0.0, -5.0)
72-
96+
#glRotatef(10, 10, 10, 10)
7397
# glRotatef(10,10,10,10)
7498
#glColor3f(1.0, 1.5, 0.0)
7599

0 commit comments

Comments
 (0)