| Home | Trees | Indices | Help |
|
|---|
|
|
1 from pyforms.gui.Controls.ControlBase import ControlBase
2
3 try:
4 from OpenGL.GL import *
5 from OpenGL.GLU import *
6 from PyQt4.QtOpenGL import QGLWidget
7 except:
8 print ("No OpenGL library available")
13
15 QGLWidget.__init__(self, parent)
16
17 self._zoom = 1.0
18 self._scene = None
19 self._rotation = [0, 0, 0]
20
21 self._mouseLeftDown = False
22 self._mouseRightDown = False
23
24 self._mouseGLPosition = [0,0,0]
25 self._lastMouseGLPosition = [0,0,0]
26
27 self._mousePosition = [0,0] #Current mouse position
28 self._lastMousePosition = [0,0] #Last mouse position
29
30 self._mouseStartDragPoint = None
31
32 self.setMinimumHeight(100)
33 self.setMinimumWidth(100)
34 self.setMouseTracking(True)
35 self.setAcceptDrops(True)
36
37
39 glClearDepth(1.0)
40 glClearColor(0, 0, 0, 1.0)
41 #glDisable(GL_CULL_FACE)
42 #glEnable(GL_DEPTH_TEST)
43 #glDisable(GL_DEPTH_TEST)
44
45
46 #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
47 #glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA)
48 glBlendFunc(GL_SRC_ALPHA,GL_ONE)
49 glEnable( GL_BLEND )
50
52 glViewport(0, 0, width, height)
53 glMatrixMode(GL_PROJECTION)
54 glLoadIdentity()
55 gluPerspective(65.0, float(width)/float(height), 0.01, 800.0)
56
57
59 glClearColor(0.0, 0.0, 0.0, 1.0)
60 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
61 glMatrixMode(GL_MODELVIEW)
62 glLoadIdentity()
63 glBlendFunc(GL_SRC_ALPHA,GL_ONE)
64 glEnable( GL_BLEND )
65
66 glScalef(1,-1,-1)
67
68 glTranslatef( 0, 0, self._zoom)
69 glRotatef( self._rotation[0], 1,0,0 )
70 glRotatef( self._rotation[1], 0,1,0 )
71 glRotatef( self._rotation[2], 0,0,1 )
72
73
74
75 if self._scene!=None: self._scene.DrawGLScene()
76
77
78 if self.mouseDown:
79 #Get mouse position
80 modelview, projection = glGetDoublev( GL_MODELVIEW_MATRIX ), glGetDoublev( GL_PROJECTION_MATRIX )
81 viewport = glGetIntegerv( GL_VIEWPORT )
82 winX, winY = float(self._mousePosition[0]), float(viewport[3] - self._mousePosition[1])
83 winZ = glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT)
84 self._mouseGLPosition = gluUnProject( winX, winY, winZ[0][0], modelview, projection, viewport)
85
87 self._mousePosition[0] = event.x()
88 self._mousePosition[1] = event.y()
89
90 if pressed!=None:
91 if event.button()==2: self._mouseRightDown = pressed
92 if event.button()==1: self._mouseLeftDown = pressed
93
99
101 self.__updateMouse(event)
102
103 if self._mouseRightDown:
104 self._lastMouseGLPosition = self._mouseGLPosition
105 self._mouseRightDown = False
106
107 if self._mouseLeftDown:
108 self.onEndDrag( self._mouseStartDragPoint, self._mouseGLPosition )
109 self._mouseLeftDown = False
110
111
112
114 QGLWidget.mousePressEvent(self, event)
115 self.__updateMouse(event, pressed = True)
116 self.repaint()
117
118 if self._mouseLeftDown: self._mouseStartDragPoint = self._mouseGLPosition
119 if self._mouseRightDown: self._lastMouseGLPosition = self._mouseGLPosition
120
121 self.onPress( event.button(), self._mousePosition, self._mouseGLPosition )
122
124 QGLWidget.mouseMoveEvent(self, event)
125 self.__updateMouse(event)
126 self.repaint()
127
128 self.onMove( (self._mouseGLPosition[0], self._mouseGLPosition[1] ) )
129
130 if self.mouseDown:
131 if self._mouseLeftDown:
132 #p = self._mouseGLPosition[0] - self._x, self._mouseGLPosition[1] + self._y
133 #p = self._mouseGLPosition[0], self._mouseGLPosition[1]
134 self.onDrag(self._lastMousePosition, self._mousePosition)
135
136 self._lastMousePosition = list(self._mousePosition)
137
140
143
144
146 movX, movY = endPoint[0]-startPoint[0], endPoint[1]-startPoint[1]
147 self._rotation[2] -= float(movX)*0.15
148 self._rotation[0] += float(movY)*0.15
149
152
153 ##############################################################################
154 ###### Properties ############################################################
155 ##############################################################################
156
157 @property
159 @scene.setter
161
162 @property
164
165
167
203
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Sep 11 13:06:34 2015 | http://epydoc.sourceforge.net |