OSDN Git Service

fix import_mqo.py
[meshio/pymeshio.git] / examples / opengl / __init__.py
1 #!/usr/bin/env python\r
2 # coding: utf-8\r
3 \r
4 from OpenGL.GL import *\r
5 import re\r
6 from .baseview import *\r
7 \r
8 \r
9 DELEGATE_PATTERN=re.compile('^on[A-Z]')\r
10 \r
11 class BaseController(object):\r
12     def __init__(self, view):\r
13         self.isInitialized=False\r
14         self.setView(view)\r
15         self.root=None\r
16 \r
17     def setRoot(self, root):\r
18         self.root=root\r
19         self.delegate(root)\r
20         self.isInitialized=False\r
21 \r
22     def setView(self, view):\r
23         self.view=view\r
24         self.delegate(view)\r
25 \r
26     def delegate(self, to):\r
27         for name in dir(to):  \r
28             if DELEGATE_PATTERN.match(name):\r
29                 method = getattr(to, name)  \r
30                 setattr(self, name, method)\r
31 \r
32     def onUpdate(*args):pass\r
33     def onLeftDown(*args):pass\r
34     def onLeftUp(*args):pass\r
35     def onMiddleDown(*args):pass\r
36     def onMiddleUp(*args):pass\r
37     def onRightDown(*args):pass\r
38     def onRightUp(*args):pass\r
39     def onMotion(*args):pass\r
40     def onResize(*args):pass\r
41     def onWheel(*args):pass\r
42     def onKeyDown(*args):pass\r
43     def onInitialize(*args):pass\r
44 \r
45     def initialize(self):\r
46         self.view.onResize()\r
47         glEnable(GL_DEPTH_TEST)\r
48         # \8f\89\8aú\89»\8e\9e\82Ì\8cÄ\82Ñ\8fo\82µ\r
49         self.onInitialize()\r
50 \r
51     def draw(self):\r
52         if not self.isInitialized:\r
53             self.initialize()\r
54             self.isInitialized=True\r
55         # OpenGL\83o\83b\83t\83@\82Ì\83N\83\8a\83A\r
56         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)\r
57         # \93\8a\89e\8ds\97ñ\82Ì\83N\83\8a\83A\r
58         glMatrixMode(GL_PROJECTION)\r
59         glLoadIdentity()\r
60         self.view.updateProjection()\r
61         # \83\82\83f\83\8b\83r\83\85\81[\8ds\97ñ\82Ì\83N\83\8a\83A\r
62         glMatrixMode(GL_MODELVIEW)\r
63         glLoadIdentity()\r
64         # OpenGL\95`\89æ\r
65         self.view.updateView()\r
66         if self.root:\r
67             self.root.draw()\r
68         glFlush()\r
69 \r