Changeset 87

Show
Ignore:
Timestamp:
03/01/08 19:48:24 (10 months ago)
Author:
jkyllo
Message:

scenegraph.py:

  • Added Orthographic and Perspective GLTransforms for splitting up a UI.
  • Added Line, GLUTSolidCube, and GLUTWireCube.

controllers.py:

  • Added some pieces for looking at 2D UI drawing.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cube/controllers.py

    r72 r87  
    298298 
    299299        # 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) 
    301325 
    302326    def spin_cb(self, section, option, value): 
  • trunk/cube/scenegraph.py

    r69 r87  
    129129        glLoadIdentity() 
    130130 
     131class 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 
     147class 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 
    131159class GLObject(object): 
    132160    """An object in an OpenGL scene.  This object can have GLTransforms added 
     
    170198        """This method pushes the current GL matrix and applies this object's 
    171199        transforms.  It is called just before this object is rendered.""" 
     200        glMatrixMode(GL_PROJECTION) 
     201        glPushMatrix() 
     202 
     203        glMatrixMode(GL_MODELVIEW) 
    172204        glPushMatrix() 
    173205        for t in self.transforms: 
     
    177209        """This method pops the current GL matrix.  It is called just after 
    178210        this object is rendered.""" 
     211        glMatrixMode(GL_MODELVIEW) 
    179212        glPopMatrix() 
     213 
     214        glMatrixMode(GL_PROJECTION) 
     215        glPopMatrix() 
     216 
    180217 
    181218    def render(self): 
     
    292329        self.renderY() 
    293330        self.renderZ() 
     331 
     332        self._postrender() 
     333 
     334class 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 
     345class 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 
     357class 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) 
    294366 
    295367        self._postrender()