Changeset 87
- Timestamp:
- 03/01/08 19:48:24 (10 months ago)
- Files:
-
- trunk/cube/controllers.py (modified) (1 diff)
- trunk/cube/scenegraph.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cube/controllers.py
r72 r87 298 298 299 299 # Add the grapher to the context 300 self.context.children.append(self.grapher) 300 #self.context.children.append(self.grapher) 301 302 303 # Create the 2D User Interface 304 self.uiframe = scenegraph.GLFrame() 305 self.uiframe.pushTransform(scenegraph.Orthographic()) 306 self.uiframe.pushTranslation(-0.0, -0.0, 2.0) 307 308 testcube = scenegraph.GLUTWireCube(1.0) 309 testcube.pushTranslation(0.0, -1.0+0.125, 0.0) 310 testcube.pushScale(2.0, 0.25, 1.0) 311 #testcube.pushTranslation(0.5, 0.5, 0.5) 312 self.uiframe.children.append(testcube) 313 314 crosshair = scenegraph.GLFrame() 315 crosshair.pushColor(0.5, 0.20, 0.20, 0.5) 316 self.uiframe.children.append(crosshair) 317 318 centeredcube = scenegraph.GLUTWireCube(1.0) 319 crosshair.children.append(centeredcube) 320 crosshair.children.append(scenegraph.Line((-0.5, 0.0, 0.0), (0.5, 0.0, 0.0))) 321 crosshair.children.append(scenegraph.Line((0.0, -0.5, 0.0), (0.0, 0.5, 0.0))) 322 323 # Add the UI to the root context 324 self.context.children.append(self.uiframe) 301 325 302 326 def spin_cb(self, section, option, value): trunk/cube/scenegraph.py
r69 r87 129 129 glLoadIdentity() 130 130 131 class Orthographic(GLTransform): 132 """A GLTransform that sets the projection matrix to Orthographic.""" 133 def __init__(self, left=-1, right=1, bottom=-1, top=1, near=-1, far=1): 134 self.left = left 135 self.right = right 136 self.bottom = bottom 137 self.top = top 138 self.near = near 139 self.far = far 140 141 def apply(self): 142 glMatrixMode(GL_PROJECTION) 143 glLoadIdentity() 144 glOrtho(self.left, self.right, self.bottom, self.top, self.near, self.far) 145 glMatrixMode(GL_MODELVIEW) 146 147 class Perspective(GLTransform): 148 def __init__(self, fov=45.0, aspect=(4.0/3.0), near=0.1, far=100.0): 149 self.fov = fov 150 self.aspect = aspect 151 self.near = near 152 self.far = far 153 154 def apply(self): 155 glMatrixMode(GL_PROJECTION) 156 glLoadIdentity() 157 gluPerspective(fov, aspect, near, far) 158 131 159 class GLObject(object): 132 160 """An object in an OpenGL scene. This object can have GLTransforms added … … 170 198 """This method pushes the current GL matrix and applies this object's 171 199 transforms. It is called just before this object is rendered.""" 200 glMatrixMode(GL_PROJECTION) 201 glPushMatrix() 202 203 glMatrixMode(GL_MODELVIEW) 172 204 glPushMatrix() 173 205 for t in self.transforms: … … 177 209 """This method pops the current GL matrix. It is called just after 178 210 this object is rendered.""" 211 glMatrixMode(GL_MODELVIEW) 179 212 glPopMatrix() 213 214 glMatrixMode(GL_PROJECTION) 215 glPopMatrix() 216 180 217 181 218 def render(self): … … 292 329 self.renderY() 293 330 self.renderZ() 331 332 self._postrender() 333 334 class Line(GLObject): 335 def __init__(self, origin=(0, 0, 0), vect=(1, 1, 1)): 336 self.o = origin 337 self.v = vect 338 339 def render(self): 340 glBegin(GL_LINES) 341 glVertex3f(*self.o) 342 glVertex3f(*self.v) 343 glEnd() 344 345 class GLUTSolidCube(GLObject): 346 def __init__(self, side=1.0): 347 GLObject.__init__(self) 348 self.side = side 349 350 def render(self): 351 self._prerender() 352 353 glutSolidCube(self.side) 354 355 self._postrender() 356 357 class GLUTWireCube(GLObject): 358 def __init__(self, side=1.0): 359 GLObject.__init__(self) 360 self.side = side 361 362 def render(self): 363 self._prerender() 364 365 glutWireCube(self.side) 294 366 295 367 self._postrender()
