- def OnPaint(self, event):
- dc = wx.PaintDC(self)
- self.SetCurrent()
- if not self.init:
- self.InitGL()
- self.init = True
- self.OnDraw()
-
- def OnMouseDown(self, evt):
- self.CaptureMouse()
-
- def OnMouseUp(self, evt):
- self.ReleaseMouse()
-
- def OnMouseMotion(self, evt):
- if evt.Dragging() and evt.LeftIsDown():
- self.x, self.y = self.lastx, self.lasty
- self.x, self.y = evt.GetPosition()
- self.Refresh(False)
-
-
-
-
- class CubeCanvas(MyCanvasBase):
- def InitGL(self):
- # set viewing projection
- glMatrixMode(GL_PROJECTION);
- glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
-
- # position viewer
- glMatrixMode(GL_MODELVIEW);
- glTranslatef(0.0, 0.0, -2.0);
-
- # position object
- glRotatef(self.y, 1.0, 0.0, 0.0);
- glRotatef(self.x, 0.0, 1.0, 0.0);
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
-
-
- def OnDraw(self):
- # clear color and depth buffers
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- # draw six faces of a cube
- glBegin(GL_QUADS)
- glNormal3f( 0.0, 0.0, 1.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f(-0.5, 0.5, 0.5)
- glVertex3f(-0.5,-0.5, 0.5)
- glVertex3f( 0.5,-0.5, 0.5)
-
- glNormal3f( 0.0, 0.0,-1.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glVertex3f( 0.5, 0.5,-0.5)
- glVertex3f( 0.5,-0.5,-0.5)
-
- glNormal3f( 0.0, 1.0, 0.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f( 0.5, 0.5,-0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glVertex3f(-0.5, 0.5, 0.5)
-
- glNormal3f( 0.0,-1.0, 0.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f( 0.5,-0.5,-0.5)
- glVertex3f( 0.5,-0.5, 0.5)
- glVertex3f(-0.5,-0.5, 0.5)
-
- glNormal3f( 1.0, 0.0, 0.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f( 0.5,-0.5, 0.5)
- glVertex3f( 0.5,-0.5,-0.5)
- glVertex3f( 0.5, 0.5,-0.5)
-
- glNormal3f(-1.0, 0.0, 0.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f(-0.5,-0.5, 0.5)
- glVertex3f(-0.5, 0.5, 0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glEnd()
-
- glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0);
- glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0);
-
- self.SwapBuffers()
-
-
-
-
-
- class ConeCanvas(MyCanvasBase):
- def InitGL( self ):
- glMatrixMode(GL_PROJECTION);
- # camera frustrum setup
- glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
- glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
- glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
- glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
- glMaterial(GL_FRONT, GL_SHININESS, 50.0)
- glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
- glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
- glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
- glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
- glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
- glEnable(GL_LIGHTING)
- glEnable(GL_LIGHT0)
- glDepthFunc(GL_LESS)
- glEnable(GL_DEPTH_TEST)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- # position viewer
- glMatrixMode(GL_MODELVIEW);
-
-
- def OnDraw(self):
- # clear color and depth buffers
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- # use a fresh transformation matrix
- glPushMatrix()
- # position object
- glTranslate(0.0, 0.0, -2.0);
- glRotate(30.0, 1.0, 0.0, 0.0);
- glRotate(30.0, 0.0, 1.0, 0.0);
-
- glTranslate(0, -1, 0)
- glRotate(250, 1, 0, 0)
- glutSolidCone(0.5, 1, 30, 5)
- glPopMatrix()
- glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0);
- glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0);
- # push into visible buffer
- self.SwapBuffers()
+
+ def OnMouseUp(self, evt):
+ self.ReleaseMouse()
+
+
+ def OnMouseMotion(self, evt):
+ if evt.Dragging() and evt.LeftIsDown():
+ self.x, self.y = self.lastx, self.lasty
+ self.x, self.y = evt.GetPosition()
+ self.Refresh(False)
+
+
+
+
+class CubeCanvas(MyCanvasBase):
+ def InitGL(self):
+ # set viewing projection
+ glMatrixMode(GL_PROJECTION);
+ glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
+
+ # position viewer
+ glMatrixMode(GL_MODELVIEW);
+ glTranslatef(0.0, 0.0, -2.0);
+
+ # position object
+ glRotatef(self.y, 1.0, 0.0, 0.0);
+ glRotatef(self.x, 0.0, 1.0, 0.0);
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+
+
+ def OnDraw(self):
+ # clear color and depth buffers
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ # draw six faces of a cube
+ glBegin(GL_QUADS)
+ glNormal3f( 0.0, 0.0, 1.0)
+ glVertex3f( 0.5, 0.5, 0.5)
+ glVertex3f(-0.5, 0.5, 0.5)
+ glVertex3f(-0.5,-0.5, 0.5)
+ glVertex3f( 0.5,-0.5, 0.5)
+
+ glNormal3f( 0.0, 0.0,-1.0)
+ glVertex3f(-0.5,-0.5,-0.5)
+ glVertex3f(-0.5, 0.5,-0.5)
+ glVertex3f( 0.5, 0.5,-0.5)
+ glVertex3f( 0.5,-0.5,-0.5)
+
+ glNormal3f( 0.0, 1.0, 0.0)
+ glVertex3f( 0.5, 0.5, 0.5)
+ glVertex3f( 0.5, 0.5,-0.5)
+ glVertex3f(-0.5, 0.5,-0.5)
+ glVertex3f(-0.5, 0.5, 0.5)
+
+ glNormal3f( 0.0,-1.0, 0.0)
+ glVertex3f(-0.5,-0.5,-0.5)
+ glVertex3f( 0.5,-0.5,-0.5)
+ glVertex3f( 0.5,-0.5, 0.5)
+ glVertex3f(-0.5,-0.5, 0.5)
+
+ glNormal3f( 1.0, 0.0, 0.0)
+ glVertex3f( 0.5, 0.5, 0.5)
+ glVertex3f( 0.5,-0.5, 0.5)
+ glVertex3f( 0.5,-0.5,-0.5)
+ glVertex3f( 0.5, 0.5,-0.5)
+
+ glNormal3f(-1.0, 0.0, 0.0)
+ glVertex3f(-0.5,-0.5,-0.5)
+ glVertex3f(-0.5,-0.5, 0.5)
+ glVertex3f(-0.5, 0.5, 0.5)
+ glVertex3f(-0.5, 0.5,-0.5)
+ glEnd()
+
+ glRotatef((self.lasty - self.y)/100., 1.0, 0.0, 0.0);
+ glRotatef((self.lastx - self.x)/100., 0.0, 1.0, 0.0);
+
+ self.SwapBuffers()
+
+
+
+
+
+class ConeCanvas(MyCanvasBase):
+ def InitGL( self ):
+ glMatrixMode(GL_PROJECTION);
+ # camera frustrum setup
+ glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
+ glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
+ glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
+ glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
+ glMaterial(GL_FRONT, GL_SHININESS, 50.0)
+ glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
+ glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
+ glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
+ glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
+ glEnable(GL_LIGHTING)
+ glEnable(GL_LIGHT0)
+ glDepthFunc(GL_LESS)
+ glEnable(GL_DEPTH_TEST)
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+ # position viewer
+ glMatrixMode(GL_MODELVIEW);
+
+
+ def OnDraw(self):
+ # clear color and depth buffers
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ # use a fresh transformation matrix
+ glPushMatrix()
+ # position object
+ glTranslate(0.0, 0.0, -2.0);
+ glRotate(30.0, 1.0, 0.0, 0.0);
+ glRotate(30.0, 0.0, 1.0, 0.0);
+
+ glTranslate(0, -1, 0)
+ glRotate(250, 1, 0, 0)
+ glutSolidCone(0.5, 1, 30, 5)
+ glPopMatrix()
+ glRotatef((self.lasty - self.y)/100., 0.0, 0.0, 1.0);
+ glRotatef(0.0, (self.lastx - self.x)/100., 1.0, 0.0);
+ # push into visible buffer
+ self.SwapBuffers()