class TrackballCanvas(MyCanvasBase): def __init__(self,parent,theta=45,phi=60,drawfunc=None,**kwargs): MyCanvasBase.__init__(self,parent,**kwargs) if drawfunc: self.draw = drawfunc self.trackball = Trackball(theta,phi) self.dist = -5 def InitGL(self): self.setupGL() glFlush() def OnMouseMotion(self,evt): MyCanvasBase.OnMouseMotion(self,evt) if evt.LeftIsDown(): w,h= map(float,self.GetSize()) x = (self.lastx*2.0 - w)/float(w) y = (self.lasty*2.0 - w)/float(h) dx = (self.x-self.lastx)*2.0/float(w) dy = -(self.y-self.lasty)*2.0/float(h) if evt.CmdDown(): self.dist += dy else: self.trackball.drag(x,y,dx,dy) def OnDraw(self): # set viewing projection glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60,1,.01,1000) # position viewer glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(0.0, 0.0, self.dist) glMultMatrixf(self.trackball.matrix) # clear color and depth buffers glClear(GL_COLOR_BUFFER_BIT) glClear(GL_DEPTH_BUFFER_BIT) self.draw() glFlush() self.SwapBuffers() def draw(self): raise NotImplementedError() def setupGL(self): pass
def __init__(self,parent,theta=45,phi=60,drawfunc=None,**kwargs): MyCanvasBase.__init__(self,parent,**kwargs) if drawfunc: self.draw = drawfunc self.trackball = Trackball(theta,phi) self.dist = -5